Merge pull request #6347 from leviongit/fixes/yield-kw-codegen

codegen.c,parse.y: remove flattening of `yield` arguments; fix #6346
This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-09-12 06:39:27 +09:00
committed by GitHub
2 changed files with 19 additions and 17 deletions
+16 -7
View File
@@ -3109,7 +3109,7 @@ codegen(codegen_scope *s, node *tree, int val)
{
codegen_scope *s2 = s;
int lv = 0, ainfo = -1;
int n = 0, sendv = 0;
int n = 0, nk = 0, sendv = 0;
while (!s2->mscope) {
lv++;
@@ -3122,17 +3122,26 @@ codegen(codegen_scope *s, node *tree, int val)
if (ainfo < 0) codegen_error(s, "invalid yield (SyntaxError)");
push();
if (tree) {
n = gen_values(s, tree, VAL, 14);
if (n < 0) {
n = sendv = 1;
push();
if (tree->car) {
n = gen_values(s, tree->car, VAL, 14);
if (n < 0) {
n = sendv = 1;
push();
}
}
if (tree->cdr->car) {
nk = gen_hash(s, tree->cdr->car->cdr, VAL, 14);
if (nk < 0) {
nk = 15;
}
}
}
push();pop(); /* space for a block */
pop_n(n+1);
pop_n(n + (nk == 15 ? 1 : nk * 2) + 1);
genop_2S(s, OP_BLKPUSH, cursp(), (ainfo<<4)|(lv & 0xf));
if (sendv) n = CALL_MAXARGS;
genop_3(s, OP_SEND, cursp(), new_sym(s, MRB_SYM_2(s->mrb, call)), n);
genop_3(s, OP_SEND, cursp(), new_sym(s, MRB_SYM_2(s->mrb, call)), n|(nk<<4));
if (val) push();
}
break;
+3 -10
View File
@@ -552,18 +552,11 @@ new_zsuper(parser_state *p)
static node*
new_yield(parser_state *p, node *c)
{
if (c) {
if (c->cdr) {
if (c->cdr->cdr) {
if (c && c->cdr && c->cdr->cdr) {
yyerror(NULL, p, "both block arg and actual block given");
}
if (c->cdr->car) {
return cons((node*)NODE_YIELD, push(c->car, c->cdr->car));
}
}
return cons((node*)NODE_YIELD, c->car);
}
return cons((node*)NODE_YIELD, 0);
return cons((node*)NODE_YIELD, c);
}
/* (:return . c) */