mruby-compiler: convert new_dot2 and new_dot3 to always use variable-sized nodes

Remove var_nodes_enabled conditions from new_dot2 and new_dot3 functions
and inline variable-sized node creation logic directly. Clean up obsolete
codegen paths by removing case NODE_DOT2 and NODE_DOT3 from traditional
codegen() and removing unused codegen_dot2 and codegen_dot3 functions.
Update gen_dot2_var and gen_dot3_var to use proper DOT2/DOT3_NODE macros
and generate OP_RANGE_INC/EXC instructions directly.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-09-03 15:09:11 +09:00
parent d239fcde48
commit 81311671c5
3 changed files with 1229 additions and 1297 deletions
+16 -48
View File
@@ -4023,28 +4023,6 @@ codegen_call_fcall(codegen_scope *s, node *tree, int val)
gen_call(s, tree, val, 0);
}
static void
codegen_dot2(codegen_scope *s, node *tree, int val)
{
codegen(s, tree->car, val);
codegen(s, tree->cdr, val);
if (!val) return;
pop(); pop();
genop_1(s, OP_RANGE_INC, cursp());
push();
}
static void
codegen_dot3(codegen_scope *s, node *tree, int val)
{
codegen(s, tree->car, val);
codegen(s, tree->cdr, val);
if (!val) return;
pop(); pop();
genop_1(s, OP_RANGE_EXC, cursp());
push();
}
static void
codegen_scall(codegen_scope *s, node *tree, int val)
{
@@ -5494,31 +5472,29 @@ gen_regx_var(codegen_scope *s, node *varnode, int val)
static void
gen_dot2_var(codegen_scope *s, node *varnode, int val)
{
struct mrb_ast_dot2_node *dot2_n = dot2_node(varnode->car);
node *left = DOT2_NODE_LEFT(dot2_n);
node *right = DOT2_NODE_RIGHT(dot2_n);
node *left = DOT2_NODE_LEFT(varnode);
node *right = DOT2_NODE_RIGHT(varnode);
/* Create simple cons structure like traditional node */
node range_node;
range_node.car = left;
range_node.cdr = right;
codegen_dot2(s, &range_node, val);
codegen(s, left, val);
codegen(s, right, val);
if (!val) return;
pop(); pop();
genop_1(s, OP_RANGE_INC, cursp());
push();
}
static void
gen_dot3_var(codegen_scope *s, node *varnode, int val)
{
struct mrb_ast_dot3_node *dot3_n = dot3_node(varnode->car);
node *left = DOT3_NODE_LEFT(dot3_n);
node *right = DOT3_NODE_RIGHT(dot3_n);
node *left = DOT3_NODE_LEFT(varnode);
node *right = DOT3_NODE_RIGHT(varnode);
/* Create simple cons structure like traditional node */
node range_node;
range_node.car = left;
range_node.cdr = right;
codegen_dot3(s, &range_node, val);
codegen(s, left, val);
codegen(s, right, val);
if (!val) return;
pop(); pop();
genop_1(s, OP_RANGE_EXC, cursp());
push();
}
static void
@@ -6481,14 +6457,6 @@ codegen(codegen_scope *s, node *tree, int val)
codegen_scall(s, tree, val);
break;
case NODE_DOT2:
codegen_dot2(s, tree, val);
break;
case NODE_DOT3:
codegen_dot3(s, tree, val);
break;
case NODE_COLON2:
codegen_colon2(s, tree, val);
break;
+20 -38
View File
@@ -613,8 +613,6 @@ static node* new_or_var(parser_state *p, node *left, node *right);
static node* new_return_var(parser_state *p, node *args);
static node* new_yield_var(parser_state *p, node *args);
static node* new_super_var(parser_state *p, node *args);
static node* new_dot2_var(parser_state *p, node *left, node *right);
static node* new_dot3_var(parser_state *p, node *left, node *right);
static node* new_float_var(parser_state *p, const char *value);
/* (:if cond then else) */
@@ -1198,35 +1196,7 @@ new_super_var(parser_state *p, node *args)
}
/* Variable-sized literal node creation functions */
static node*
new_dot2_var(parser_state *p, node *left, node *right)
{
size_t total_size = sizeof(struct mrb_ast_dot2_node);
enum mrb_ast_size_class class = size_to_class(total_size);
struct mrb_ast_dot2_node *n = (struct mrb_ast_dot2_node*)parser_alloc_var(p, total_size, class);
init_var_header(&n->hdr, p, NODE_DOT2, class);
n->left = left;
n->right = right;
return cons_head((node*)NODE_VARIABLE, (node*)n);
}
static node*
new_dot3_var(parser_state *p, node *left, node *right)
{
size_t total_size = sizeof(struct mrb_ast_dot3_node);
enum mrb_ast_size_class class = size_to_class(total_size);
struct mrb_ast_dot3_node *n = (struct mrb_ast_dot3_node*)parser_alloc_var(p, total_size, class);
init_var_header(&n->hdr, p, NODE_DOT3, class);
n->left = left;
n->right = right;
return cons_head((node*)NODE_VARIABLE, (node*)n);
}
static node*
new_float_var(parser_state *p, const char *value)
@@ -1456,20 +1426,32 @@ new_retry(parser_state *p)
static node*
new_dot2(parser_state *p, node *a, node *b)
{
if (p->var_nodes_enabled) {
return new_dot2_var(p, a, b);
}
return cons_head((node*)NODE_DOT2, cons(a, b));
size_t total_size = sizeof(struct mrb_ast_dot2_node);
enum mrb_ast_size_class class = size_to_class(total_size);
struct mrb_ast_dot2_node *n = (struct mrb_ast_dot2_node*)parser_alloc_var(p, total_size, class);
init_var_header(&n->hdr, p, NODE_DOT2, class);
n->left = a;
n->right = b;
return cons_head((node*)NODE_VARIABLE, (node*)n);
}
/* (:dot3 a b) */
static node*
new_dot3(parser_state *p, node *a, node *b)
{
if (p->var_nodes_enabled) {
return new_dot3_var(p, a, b);
}
return cons_head((node*)NODE_DOT3, cons(a, b));
size_t total_size = sizeof(struct mrb_ast_dot3_node);
enum mrb_ast_size_class class = size_to_class(total_size);
struct mrb_ast_dot3_node *n = (struct mrb_ast_dot3_node*)parser_alloc_var(p, total_size, class);
init_var_header(&n->hdr, p, NODE_DOT3, class);
n->left = a;
n->right = b;
return cons_head((node*)NODE_VARIABLE, (node*)n);
}
/* (:colon2 b c) */
File diff suppressed because it is too large Load Diff