mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-compiler: simplify argument handling by removing redundant NODE_ARG
NODE_ARG and NODE_LVAR were handled identically in codegen.c, making the distinction unnecessary. This change: - Replaces all new_arg() calls with new_xvar(p, sym, NODE_LVAR) - Removes the new_arg() function entirely - Removes the unused NODE_ARG enum value - Updates codegen.c to handle only NODE_LVAR case The simplification reduces parser complexity while maintaining identical functionality for argument processing. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2860,7 +2860,6 @@ gen_assignment(codegen_scope *s, node *tree, node *rhs, int sp, int val)
|
||||
gen_masgn_var(s, tree->cdr, rhs, sp, val);
|
||||
return;
|
||||
case NODE_LVAR:
|
||||
case NODE_ARG:
|
||||
{
|
||||
mrb_sym sym = VAR_NODE_SYMBOL(tree->cdr);
|
||||
if (rhs) {
|
||||
|
||||
@@ -60,7 +60,6 @@ enum node_type {
|
||||
NODE_XSTR,
|
||||
NODE_REGX,
|
||||
NODE_DREGX,
|
||||
NODE_ARG,
|
||||
NODE_ARGS_TAIL,
|
||||
NODE_KW_ARG,
|
||||
NODE_KW_REST_ARGS,
|
||||
|
||||
@@ -1311,13 +1311,6 @@ new_sdef(parser_state *p, node *o, mrb_sym name)
|
||||
return cons_head((node*)NODE_VARIABLE, (node*)sdef_node);
|
||||
}
|
||||
|
||||
/* (:arg . sym) */
|
||||
static node*
|
||||
new_arg(parser_state *p, mrb_sym sym)
|
||||
{
|
||||
return new_xvar(p, sym, NODE_ARG);
|
||||
}
|
||||
|
||||
static void
|
||||
local_add_margs(parser_state *p, node *n)
|
||||
{
|
||||
@@ -1500,7 +1493,7 @@ setup_numparams(parser_state *p, node *a)
|
||||
buf[1] = i+'0';
|
||||
buf[2] = '\0';
|
||||
sym = intern_cstr(buf);
|
||||
args = cons(new_arg(p, sym), args);
|
||||
args = cons(new_xvar(p, sym, NODE_LVAR), args);
|
||||
p->locals->car = cons(sym_to_node(sym), p->locals->car);
|
||||
}
|
||||
a = new_args(p, args, 0, 0, 0, 0);
|
||||
@@ -3771,11 +3764,11 @@ f_margs : f_arg
|
||||
}
|
||||
| f_arg ',' tSTAR f_norm_arg
|
||||
{
|
||||
$$ = list3($1, new_arg(p, $4), 0);
|
||||
$$ = list3($1, new_xvar(p, $4, NODE_LVAR), 0);
|
||||
}
|
||||
| f_arg ',' tSTAR f_norm_arg ',' f_arg
|
||||
{
|
||||
$$ = list3($1, new_arg(p, $4), $6);
|
||||
$$ = list3($1, new_xvar(p, $4, NODE_LVAR), $6);
|
||||
}
|
||||
| f_arg ',' tSTAR
|
||||
{
|
||||
@@ -3788,11 +3781,11 @@ f_margs : f_arg
|
||||
}
|
||||
| tSTAR f_norm_arg
|
||||
{
|
||||
$$ = list3(0, new_arg(p, $2), 0);
|
||||
$$ = list3(0, new_xvar(p, $2, NODE_LVAR), 0);
|
||||
}
|
||||
| tSTAR f_norm_arg ',' f_arg
|
||||
{
|
||||
$$ = list3(0, new_arg(p, $2), $4);
|
||||
$$ = list3(0, new_xvar(p, $2, NODE_LVAR), $4);
|
||||
}
|
||||
| tSTAR
|
||||
{
|
||||
@@ -4686,7 +4679,7 @@ f_norm_arg : f_bad_arg
|
||||
|
||||
f_arg_item : f_norm_arg
|
||||
{
|
||||
$$ = new_arg(p, $1);
|
||||
$$ = new_xvar(p, $1, NODE_LVAR);
|
||||
}
|
||||
| tLPAREN
|
||||
{
|
||||
@@ -8383,10 +8376,6 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
|
||||
printf("NODE_NTH_REF: $%d\n", node_to_int(tree));
|
||||
break;
|
||||
|
||||
case NODE_ARG:
|
||||
printf("NODE_ARG %s\n", mrb_sym_name(mrb, node_to_sym(tree)));
|
||||
break;
|
||||
|
||||
case NODE_BLOCK_ARG:
|
||||
printf("NODE_BLOCK_ARG:\n");
|
||||
mrb_parser_dump(mrb, tree, offset+1);
|
||||
|
||||
+1041
-1052
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user