parse.y: allow inner anonymous block argument.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-05-15 19:31:39 +09:00
parent 0a52f171aa
commit 0299ccf6c7
3 changed files with 14 additions and 7 deletions
+10 -3
View File
@@ -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 {
+2 -2
View File
@@ -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);
}
;
+2 -2
View File
@@ -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"