diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-02-14 17:06:43 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-02-14 17:06:43 +0900 |
| commit | 7586d474b585642c1222e618d1bc1caf3e2de27f (patch) | |
| tree | 08fba25fd758e58b3d5715a65fcce94d42515276 | |
| parent | 007ed07e77be90ec2b5f7e5043dd611540e9f80d (diff) | |
| parent | 876e7de7ecbaafe9386a0d562e13ee315d32036d (diff) | |
| download | mruby-7586d474b585642c1222e618d1bc1caf3e2de27f.tar.gz mruby-7586d474b585642c1222e618d1bc1caf3e2de27f.zip | |
Merge pull request #1707 from Fleurer/issue1706
keep stack with nlocals instead of nregs; fix #1706
| -rw-r--r-- | mrbgems/mruby-bin-mirb/bintest/mirb.rb | 23 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-mirb/tools/mirb/mirb.c | 8 |
2 files changed, 26 insertions, 5 deletions
diff --git a/mrbgems/mruby-bin-mirb/bintest/mirb.rb b/mrbgems/mruby-bin-mirb/bintest/mirb.rb index ed53321bd..ea13eb0d2 100644 --- a/mrbgems/mruby-bin-mirb/bintest/mirb.rb +++ b/mrbgems/mruby-bin-mirb/bintest/mirb.rb @@ -10,3 +10,26 @@ assert('regression for #1563') do o, s = Open3.capture2('bin/mirb', :stdin_data => "a=1;b=2;c=3\nb\nc") assert_true o.include?('=> 3') end + +assert('regression for #1706') do + o, s = Open3.capture2('bin/mirb', :stdin_data => %{ + if false + a = 1 + b = 1 + end + puts "a: \#{a.inspect}" + puts "b: \#{b.inspect}" + }) + assert_true o.include?('a: nil') + assert_true o.include?('b: nil') + + o, s = Open3.capture2('bin/mirb', :stdin_data => %{ + a = 1 + b = 2 + if false + c = 3 + end + puts "c: \#{c.inspect}" + }) + assert_true o.include?('c: nil') +end diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c index 183003307..a9d6850a5 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c @@ -251,8 +251,7 @@ main(int argc, char **argv) int n; mrb_bool code_block_open = FALSE; int ai; - mrb_bool first_command = TRUE; - unsigned int nregs; + unsigned int stack_keep = 0; /* new interpreter instance */ mrb = mrb_open(); @@ -365,12 +364,12 @@ main(int argc, char **argv) mrb_codedump_all(mrb, proc); } /* pass a proc for evaulation */ - nregs = first_command ? 0: proc->body.irep->nregs; /* evaluate the bytecode */ result = mrb_context_run(mrb, proc, mrb_top_self(mrb), - nregs); + stack_keep); + stack_keep = proc->body.irep->nlocals; /* did an exception occur? */ if (mrb->exc) { p(mrb, mrb_obj_value(mrb->exc), 0); @@ -390,7 +389,6 @@ main(int argc, char **argv) } mrb_parser_free(parser); cxt->lineno++; - first_command = FALSE; } mrbc_context_free(mrb, cxt); mrb_close(mrb); |
