mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-compiler: convert new_const to always use variable-sized nodes
Remove conditional logic from new_const() and inline new_const_var() helper function for cleaner implementation. Update codegen to handle NODE_CONST in both variable-sized access and assignment contexts. Changes: - Remove var_nodes_enabled conditional in new_const() - Inline new_const_var() logic directly into new_const() - Remove new_const_var() function and declaration - Remove NODE_CONST case from main codegen() switch - Add NODE_CONST support in gen_assignment() for variable-sized nodes - Inline codegen_const() logic into gen_const_var() - Remove traditional codegen_const() function Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2925,7 +2925,6 @@ gen_assignment(codegen_scope *s, node *tree, node *rhs, int sp, int val)
|
||||
switch (type) {
|
||||
case NODE_ARG:
|
||||
case NODE_LVAR:
|
||||
case NODE_CONST:
|
||||
case NODE_NIL:
|
||||
case NODE_MASGN:
|
||||
if (rhs) {
|
||||
@@ -2968,6 +2967,9 @@ gen_assignment(codegen_scope *s, node *tree, node *rhs, int sp, int val)
|
||||
case NODE_CVAR:
|
||||
gen_xvar_assignment(s, tree, rhs, sp, val, OP_SETCV);
|
||||
break;
|
||||
case NODE_CONST:
|
||||
gen_xvar_assignment(s, tree, rhs, sp, val, OP_SETCONST);
|
||||
break;
|
||||
default:
|
||||
codegen_error(s, "unsupported variable-sized lhs");
|
||||
break;
|
||||
@@ -2997,9 +2999,6 @@ gen_assignment(codegen_scope *s, node *tree, node *rhs, int sp, int val)
|
||||
gen_setupvar(s, sp, node_to_sym(tree));
|
||||
}
|
||||
break;
|
||||
case NODE_CONST:
|
||||
gen_setxv(s, OP_SETCONST, sp, node_to_sym(tree), val);
|
||||
break;
|
||||
|
||||
case NODE_CALL:
|
||||
case NODE_SCALL:
|
||||
@@ -3624,15 +3623,6 @@ codegen_lvar(codegen_scope *s, mrb_sym sym, int val)
|
||||
push();
|
||||
}
|
||||
|
||||
static void
|
||||
codegen_const(codegen_scope *s, mrb_sym sym, int val)
|
||||
{
|
||||
int i = new_sym(s, sym);
|
||||
|
||||
genop_2(s, OP_GETCONST, cursp(), i);
|
||||
if (val) push();
|
||||
}
|
||||
|
||||
static void
|
||||
gen_hash_var(codegen_scope *s, node *varnode, int val)
|
||||
{
|
||||
@@ -5094,11 +5084,12 @@ gen_false_var(codegen_scope *s, node *varnode, int val)
|
||||
static void
|
||||
gen_const_var(codegen_scope *s, node *varnode, int val)
|
||||
{
|
||||
struct mrb_ast_const_node *const_n = const_node(varnode->car);
|
||||
mrb_sym symbol = CONST_NODE_SYMBOL(const_n);
|
||||
struct mrb_ast_const_node *const_n = const_node(varnode);
|
||||
mrb_sym symbol = const_n->symbol;
|
||||
|
||||
/* Use traditional const codegen logic */
|
||||
codegen_const(s, symbol, val);
|
||||
int i = new_sym(s, symbol);
|
||||
genop_2(s, OP_GETCONST, cursp(), i);
|
||||
if (val) push();
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -6245,9 +6236,6 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
codegen_lvar(s, node_to_sym(tree), val);
|
||||
break;
|
||||
|
||||
case NODE_CONST:
|
||||
codegen_const(s, node_to_sym(tree), val);
|
||||
break;
|
||||
|
||||
case NODE_DEF:
|
||||
codegen_def(s, tree, val);
|
||||
|
||||
@@ -47,7 +47,6 @@ static const char* tok(parser_state *p);
|
||||
static int toklen(parser_state *p);
|
||||
|
||||
/* Forward declarations for variable-sized simple node functions */
|
||||
static node* new_const_var(parser_state *p, mrb_sym symbol);
|
||||
|
||||
/* Forward declarations for variable-sized advanced node functions */
|
||||
|
||||
@@ -928,19 +927,6 @@ new_op_asgn_var(parser_state *p, node *lhs, mrb_sym op, node *rhs)
|
||||
}
|
||||
|
||||
/* Variable-sized simple node creation functions */
|
||||
static node*
|
||||
new_const_var(parser_state *p, mrb_sym symbol)
|
||||
{
|
||||
size_t total_size = sizeof(struct mrb_ast_const_node);
|
||||
enum mrb_ast_size_class class = size_to_class(total_size);
|
||||
|
||||
struct mrb_ast_const_node *n = (struct mrb_ast_const_node*)parser_alloc_var(p, total_size, class);
|
||||
|
||||
init_var_header(&n->hdr, p, NODE_CONST, class);
|
||||
n->symbol = symbol;
|
||||
|
||||
return cons_head((node*)NODE_VARIABLE, (node*)n);
|
||||
}
|
||||
|
||||
/* (:fcall self mid args) */
|
||||
static node*
|
||||
@@ -1361,10 +1347,15 @@ new_nvar(parser_state *p, int num)
|
||||
static node*
|
||||
new_const(parser_state *p, mrb_sym sym)
|
||||
{
|
||||
if (p->var_nodes_enabled) {
|
||||
return new_const_var(p, sym);
|
||||
}
|
||||
return cons_head((node*)NODE_CONST, sym_to_node(sym));
|
||||
size_t total_size = sizeof(struct mrb_ast_const_node);
|
||||
enum mrb_ast_size_class class = size_to_class(total_size);
|
||||
|
||||
struct mrb_ast_const_node *n = (struct mrb_ast_const_node*)parser_alloc_var(p, total_size, class);
|
||||
|
||||
init_var_header(&n->hdr, p, NODE_CONST, class);
|
||||
n->symbol = sym;
|
||||
|
||||
return cons_head((node*)NODE_VARIABLE, (node*)n);
|
||||
}
|
||||
|
||||
/* (:undef a...) */
|
||||
|
||||
+1119
-1128
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user