mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-compiler: convert new_asgn to always use variable-sized nodes
Remove conditional logic from new_asgn() and inline new_asgn_var() helper function for cleaner implementation. Assignment expressions maintain proper value semantics while using more efficient memory allocation. Changes: - Remove var_nodes_enabled conditional in new_asgn() - Inline new_asgn_var() logic directly into new_asgn() - Remove new_asgn_var() function and declaration - Remove NODE_ASGN case from main codegen() switch - Update gen_asgn_var() to use direct struct field access - Remove traditional codegen_asgn() function Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -3878,12 +3878,6 @@ codegen_regx(codegen_scope *s, node *tree, int val)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
codegen_asgn(codegen_scope *s, node *tree, int val)
|
||||
{
|
||||
gen_assignment(s, tree->car, tree->cdr, 0, val);
|
||||
}
|
||||
|
||||
static void
|
||||
codegen_def(codegen_scope *s, node *tree, int val)
|
||||
{
|
||||
@@ -4714,10 +4708,9 @@ static void
|
||||
gen_asgn_var(codegen_scope *s, node *varnode, int val)
|
||||
{
|
||||
struct mrb_ast_asgn_node *asgn_n = asgn_node(varnode);
|
||||
node *lhs = ASGN_NODE_LHS(asgn_n);
|
||||
node *rhs = ASGN_NODE_RHS(asgn_n);
|
||||
node *lhs = asgn_n->lhs;
|
||||
node *rhs = asgn_n->rhs;
|
||||
|
||||
/* Use existing assignment generation logic */
|
||||
gen_assignment(s, lhs, rhs, 0, val);
|
||||
}
|
||||
|
||||
@@ -5822,7 +5815,6 @@ gen_undef_var(codegen_scope *s, const node *varnode, int val)
|
||||
gen_load_nil(s, val);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gen_sdef_var(codegen_scope *s, const node *varnode, int val)
|
||||
{
|
||||
@@ -6221,10 +6213,6 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
codegen_scall(s, tree, val);
|
||||
break;
|
||||
|
||||
case NODE_ASGN:
|
||||
codegen_asgn(s, tree, val);
|
||||
break;
|
||||
|
||||
case NODE_MASGN:
|
||||
codegen_masgn(s, tree, val);
|
||||
break;
|
||||
@@ -6237,7 +6225,6 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
codegen_lvar(s, node_to_sym(tree), val);
|
||||
break;
|
||||
|
||||
|
||||
case NODE_DEF:
|
||||
codegen_def(s, tree, val);
|
||||
break;
|
||||
|
||||
@@ -500,7 +500,6 @@ new_stmts(parser_state *p, node *body)
|
||||
return cons_head((node*)NODE_VARIABLE, (node*)n);
|
||||
}
|
||||
|
||||
|
||||
/* (:begin body) - Always use variable-sized nodes */
|
||||
static node*
|
||||
new_begin(parser_state *p, node *body)
|
||||
@@ -608,7 +607,6 @@ new_alias(parser_state *p, mrb_sym a, mrb_sym b)
|
||||
|
||||
/* Forward declarations for variable-sized AST node creation functions */
|
||||
static node* new_def_var(parser_state *p, mrb_sym name, node *args, node *body);
|
||||
static node* new_asgn_var(parser_state *p, node *lhs, node *rhs);
|
||||
static node* new_masgn_var(parser_state *p, node *lhs, node *rhs);
|
||||
static node* new_op_asgn_var(parser_state *p, node *lhs, mrb_sym op, node *rhs);
|
||||
|
||||
@@ -874,25 +872,6 @@ new_def_var(parser_state *p, mrb_sym name, node *args, node *body)
|
||||
return cons_head((node*)NODE_VARIABLE, (node*)n);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* Variable-sized assignment node creation */
|
||||
static node*
|
||||
new_asgn_var(parser_state *p, node *lhs, node *rhs)
|
||||
{
|
||||
size_t total_size = sizeof(struct mrb_ast_asgn_node);
|
||||
enum mrb_ast_size_class class = size_to_class(total_size);
|
||||
|
||||
struct mrb_ast_asgn_node *n = (struct mrb_ast_asgn_node*)parser_alloc_var(p, total_size, class);
|
||||
|
||||
init_var_header(&n->header, p, NODE_ASGN, class);
|
||||
n->lhs = lhs;
|
||||
n->rhs = rhs;
|
||||
|
||||
return cons_head((node*)NODE_VARIABLE, (node*)n);
|
||||
}
|
||||
|
||||
/* Variable-sized multiple assignment node creation */
|
||||
static node*
|
||||
new_masgn_var(parser_state *p, node *lhs, node *rhs)
|
||||
@@ -1310,7 +1289,6 @@ new_lvar(parser_state *p, mrb_sym sym)
|
||||
return cons_head((node*)NODE_LVAR, sym_to_node(sym));
|
||||
}
|
||||
|
||||
|
||||
/* (:nvar . a) */
|
||||
static node*
|
||||
new_nvar(parser_state *p, int num)
|
||||
@@ -1686,10 +1664,17 @@ static node*
|
||||
new_asgn(parser_state *p, node *a, node *b)
|
||||
{
|
||||
void_expr_error(p, b);
|
||||
if (p->var_nodes_enabled) {
|
||||
return new_asgn_var(p, a, b);
|
||||
}
|
||||
return cons_head((node*)NODE_ASGN, cons(a, b));
|
||||
|
||||
size_t total_size = sizeof(struct mrb_ast_asgn_node);
|
||||
enum mrb_ast_size_class class = size_to_class(total_size);
|
||||
|
||||
struct mrb_ast_asgn_node *n = (struct mrb_ast_asgn_node*)parser_alloc_var(p, total_size, class);
|
||||
|
||||
init_var_header(&n->header, p, NODE_ASGN, class);
|
||||
n->lhs = a;
|
||||
n->rhs = b;
|
||||
|
||||
return cons_head((node*)NODE_VARIABLE, (node*)n);
|
||||
}
|
||||
|
||||
/* (:masgn mlhs=(pre rest post) mrhs) */
|
||||
|
||||
+1071
-1086
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user