From 0299ccf6c7e4dc25f45f4a622889af70ee970957 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sun, 15 May 2022 19:31:39 +0900 Subject: [PATCH] parse.y: allow inner anonymous block argument. --- mrbgems/mruby-compiler/core/codegen.c | 13 ++++++++++--- mrbgems/mruby-compiler/core/parse.y | 4 ++-- mrbgems/mruby-compiler/core/y.tab.c | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 2357af9d2..c37cfff74 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -1282,7 +1282,12 @@ search_upvar(codegen_scope *s, mrb_sym id, int *idx) lv ++; } - codegen_error(s, "Can't found local variables"); + if (id == MRB_OPSYM_2(s->mrb, and)) { + codegen_error(s, "no anonymous block argument"); + } + else { + codegen_error(s, "Can't found local variables"); + } return -1; /* not reached */ } @@ -3261,9 +3266,11 @@ codegen(codegen_scope *s, node *tree, int val) int idx = lv_idx(s, MRB_OPSYM_2(s->mrb, and)); if (idx == 0) { - codegen_error(s, "no anonymous block argument"); + gen_getupvar(s, cursp(), MRB_OPSYM_2(s->mrb, and)); + } + else { + gen_move(s, cursp(), idx, val); } - gen_move(s, cursp(), idx, val); if (val) push(); } else { diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 032673b9b..3b9c45f5a 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -328,7 +328,7 @@ static void local_add_blk(parser_state *p, mrb_sym blk) { /* allocate register for block */ - local_add_f(p, blk ? blk : intern_op(and)); + local_add_f(p, blk ? blk : 0); } static void @@ -3816,7 +3816,7 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_args_tail } | /* none */ { - local_add_f(p, intern_op(and)); + local_add_f(p, 0); $$ = new_args(p, 0, 0, 0, 0, 0); } ; diff --git a/mrbgems/mruby-compiler/core/y.tab.c b/mrbgems/mruby-compiler/core/y.tab.c index cfbb3032c..808c64137 100644 --- a/mrbgems/mruby-compiler/core/y.tab.c +++ b/mrbgems/mruby-compiler/core/y.tab.c @@ -391,7 +391,7 @@ static void local_add_blk(parser_state *p, mrb_sym blk) { /* allocate register for block */ - local_add_f(p, blk ? blk : intern_op(and)); + local_add_f(p, blk ? blk : 0); } static void @@ -9734,7 +9734,7 @@ yyreduce: case 541: #line 3818 "mrbgems/mruby-compiler/core/parse.y" { - local_add_f(p, intern_op(and)); + local_add_f(p, 0); (yyval.nd) = new_args(p, 0, 0, 0, 0, 0); } #line 9741 "mrbgems/mruby-compiler/core/y.tab.c"