mruby-compiler: fix new_undef function to handle symbol lists properly

- Update new_undef function signature to accept node list instead of single symbol
- Fix grammar rule to properly construct undef nodes from symbol lists
- Simplify gen_undef_var function to directly pass symbol list to codegen
- Support multiple symbols in single undef statement (e.g., undef foo, bar)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-08-30 13:22:59 +09:00
parent 528e7932d6
commit 259a388cbe
2 changed files with 6 additions and 10 deletions
+2 -6
View File
@@ -5945,12 +5945,8 @@ gen_undef_var(codegen_scope *s, const node *varnode, int val)
{
struct mrb_ast_undef_node *undef = undef_node(varnode);
// Create stack-allocated traditional node structure
node undef_node_stack;
undef_node_stack.car = undef->syms;
undef_node_stack.cdr = NULL;
codegen_undef(s, &undef_node_stack, val);
// The syms field now contains the list directly
codegen_undef(s, undef->syms, val);
}
static void
+4 -4
View File
@@ -1825,14 +1825,14 @@ new_const(parser_state *p, mrb_sym sym)
/* (:undef a...) */
static node*
new_undef(parser_state *p, mrb_sym sym)
new_undef(parser_state *p, node *syms)
{
size_t total_size = sizeof(struct mrb_ast_undef_node);
enum mrb_ast_size_class class = size_to_class(total_size);
struct mrb_ast_undef_node *undef_node = (struct mrb_ast_undef_node*)
parser_alloc_var(p, total_size, class);
init_var_header(&undef_node->hdr, p, NODE_UNDEF, class);
undef_node->syms = sym_to_node(sym);
undef_node->syms = syms;
return cons_head((node*)NODE_VARIABLE, (node*)undef_node);
}
@@ -3102,7 +3102,7 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym
}
| keyword_undef undef_list
{
$$ = $2;
$$ = new_undef(p, $2);
}
| stmt modifier_if expr_value
{
@@ -3586,7 +3586,7 @@ fsym : fname
undef_list : fsym
{
$$ = new_undef(p, $1);
$$ = cons(sym_to_node($1), 0);
}
| undef_list ',' {p->lstate = EXPR_FNAME;} fsym
{