diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-02-26 18:10:02 -0800 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-02-26 18:10:02 -0800 |
| commit | ced8fea305806cb955677d87a574098afc4e2143 (patch) | |
| tree | 5d0b79aef366bdc022e31fd385695cfbcf1abc84 | |
| parent | 2a932441379f242a08e6f3783f2cd2f6204e8193 (diff) | |
| parent | f413e6881c2e325d10c041d03da695ad00b91830 (diff) | |
| download | mruby-ced8fea305806cb955677d87a574098afc4e2143.tar.gz mruby-ced8fea305806cb955677d87a574098afc4e2143.zip | |
Merge pull request #898 from masamitsu-murase/modify_return_value
Modify handling of NODE_RETURN and NODE_NEXT.
| -rw-r--r-- | src/codegen.c | 14 | ||||
| -rw-r--r-- | test/t/exception.rb | 10 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/codegen.c b/src/codegen.c index ce9967f89..59fde4cb8 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1570,15 +1570,20 @@ codegen(codegen_scope *s, node *tree, int val) break; case NODE_RETURN: - codegen(s, tree, VAL); - pop(); + if (tree) { + codegen(s, tree, VAL); + pop(); + } + else { + genop(s, MKOP_A(OP_LOADNIL, cursp())); + } if (s->loop) { genop(s, MKOP_AB(OP_RETURN, cursp(), OP_R_RETURN)); } else { genop_peep(s, MKOP_AB(OP_RETURN, cursp(), OP_R_NORMAL), NOVAL); } - push(); + if (val) push(); break; case NODE_YIELD: @@ -1630,6 +1635,9 @@ codegen(codegen_scope *s, node *tree, int val) codegen(s, tree, VAL); pop(); } + else { + genop(s, MKOP_A(OP_LOADNIL, cursp())); + } genop_peep(s, MKOP_AB(OP_RETURN, cursp(), OP_R_NORMAL), NOVAL); } if (val) push(); diff --git a/test/t/exception.rb b/test/t/exception.rb index 663c8f337..7ecc51fa8 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -321,19 +321,19 @@ end # very deeply recursive function that stil returns albeit very deeply so $test_infinite_recursion = 0 -TEST_INFINITE_RECURSION_MAX = 100000 +TEST_INFINITE_RECURSION_MAX = 1000000 def test_infinite_recursion $test_infinite_recursion += 1 if $test_infinite_recursion > TEST_INFINITE_RECURSION_MAX - return $test_infinite_recursion + return $test_infinite_recursion end - test_infinite_recursion + test_infinite_recursion end assert('Infinite recursion should result in an exception being raised') do - a = begin + a = begin test_infinite_recursion - rescue + rescue :ok end # OK if an exception was caught, otherwise a number will be stored in a |
