From 49c929a237fe482b2286aab47a263f8b51225cad Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Wed, 27 Feb 2013 02:37:26 +0900 Subject: Return nil if argument of NODE_RETURN and NODE_NEXT is not specified. --- src/codegen.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/codegen.c b/src/codegen.c index 53324f321..a595a27c8 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1571,15 +1571,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: @@ -1631,6 +1636,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(); -- cgit v1.2.3 From f413e6881c2e325d10c041d03da695ad00b91830 Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Wed, 27 Feb 2013 02:47:08 +0900 Subject: Increase TEST_INFINITE_RECURSION_MAX value from 100000 to 1000000 because modification of handling of `NODE_RETURN` reduces stack size. --- test/t/exception.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 -- cgit v1.2.3