mruby-compiler: rename NODE_BEGIN to NODE_STMTS for clarity

Rename NODE_BEGIN to NODE_STMTS to better reflect its purpose as a
container for statement sequences, not specifically begin-end blocks.
This prepares for adding a dedicated node type for explicit begin-end
constructs.

- Rename NODE_BEGIN enum to NODE_STMTS in node.h
- Update all references in parse.y and codegen.c
- Rename new_begin function to new_stmts

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-07-05 19:23:12 +09:00
parent 540bbc71e6
commit f6c166cbb0
3 changed files with 24 additions and 24 deletions
+7 -7
View File
@@ -3139,7 +3139,7 @@ gen_literal_array(codegen_scope *s, node *tree, mrb_bool sym, int val)
if ((tree->cdr == NULL) && (nint(tree->car->cdr->cdr) == 0))
break;
/* fall through */
case NODE_BEGIN:
case NODE_STMTS:
codegen(s, tree->car, VAL);
j++;
break;
@@ -3192,7 +3192,7 @@ gen_literal_array(codegen_scope *s, node *tree, mrb_bool sym, int val)
else {
while (tree) {
switch (nint(tree->car->car)) {
case NODE_BEGIN: case NODE_BLOCK:
case NODE_STMTS: case NODE_BLOCK:
codegen(s, tree->car, NOVAL);
}
tree = tree->cdr;
@@ -3344,7 +3344,7 @@ codegen(codegen_scope *s, node *tree, int val)
s->lineno = tree->lineno;
tree = tree->cdr;
switch (nt) {
case NODE_BEGIN:
case NODE_STMTS:
if (val && !tree) {
genop_1(s, OP_LOADNIL, cursp());
push();
@@ -3450,7 +3450,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_ENSURE:
if (!tree->cdr || !tree->cdr->cdr ||
(nint(tree->cdr->cdr->car) == NODE_BEGIN &&
(nint(tree->cdr->cdr->car) == NODE_STMTS &&
tree->cdr->cdr->cdr)) {
int catch_entry, begin, end, target;
int idx;
@@ -4755,7 +4755,7 @@ codegen(codegen_scope *s, node *tree, int val)
idx = new_sym(s, nsym(tree->car->cdr));
genop_2(s, OP_CLASS, cursp(), idx);
body = tree->cdr->cdr->car;
if (nint(body->cdr->car) == NODE_BEGIN && body->cdr->cdr == NULL) {
if (nint(body->cdr->car) == NODE_STMTS && body->cdr->cdr == NULL) {
genop_1(s, OP_LOADNIL, cursp());
}
else {
@@ -4786,7 +4786,7 @@ codegen(codegen_scope *s, node *tree, int val)
pop();
idx = new_sym(s, nsym(tree->car->cdr));
genop_2(s, OP_MODULE, cursp(), idx);
if (nint(tree->cdr->car->cdr->car) == NODE_BEGIN &&
if (nint(tree->cdr->car->cdr->car) == NODE_STMTS &&
tree->cdr->car->cdr->cdr == NULL) {
genop_1(s, OP_LOADNIL, cursp());
}
@@ -4807,7 +4807,7 @@ codegen(codegen_scope *s, node *tree, int val)
codegen(s, tree->car, VAL);
pop();
genop_1(s, OP_SCLASS, cursp());
if (nint(tree->cdr->car->cdr->car) == NODE_BEGIN &&
if (nint(tree->cdr->car->cdr->car) == NODE_STMTS &&
tree->cdr->car->cdr->cdr == NULL) {
genop_1(s, OP_LOADNIL, cursp());
}
+1 -1
View File
@@ -22,7 +22,7 @@ enum node_type {
NODE_NEXT,
NODE_REDO,
NODE_RETRY,
NODE_BEGIN,
NODE_STMTS,
NODE_RESCUE,
NODE_ENSURE,
NODE_AND,
+16 -16
View File
@@ -382,12 +382,12 @@ new_scope(parser_state *p, node *body)
/* (:begin prog...) */
static node*
new_begin(parser_state *p, node *body)
new_stmts(parser_state *p, node *body)
{
if (body) {
return list2((node*)NODE_BEGIN, body);
return list2((node*)NODE_STMTS, body);
}
return cons((node*)NODE_BEGIN, 0);
return cons((node*)NODE_STMTS, 0);
}
#define newline_node(n) (n)
@@ -1681,11 +1681,11 @@ top_compstmt : top_stmts opt_terms
top_stmts : none
{
$$ = new_begin(p, 0);
$$ = new_stmts(p, 0);
}
| top_stmt
{
$$ = new_begin(p, $1);
$$ = new_stmts(p, $1);
NODE_LINENO($$, $1);
}
| top_stmts terms top_stmt
@@ -1694,7 +1694,7 @@ top_stmts : none
}
| error top_stmt
{
$$ = new_begin(p, 0);
$$ = new_stmts(p, 0);
}
;
@@ -1748,11 +1748,11 @@ compstmt : stmts opt_terms
stmts : none
{
$$ = new_begin(p, 0);
$$ = new_stmts(p, 0);
}
| stmt
{
$$ = new_begin(p, $1);
$$ = new_stmts(p, $1);
NODE_LINENO($$, $1);
}
| stmts terms stmt
@@ -1761,7 +1761,7 @@ stmts : none
}
| error stmt
{
$$ = new_begin(p, $2);
$$ = new_stmts(p, $2);
}
;
@@ -1892,7 +1892,7 @@ command_asgn : lhs '=' command_rhs
| backref tOP_ASGN command_rhs
{
backref_error(p, $1);
$$ = new_begin(p, 0);
$$ = new_stmts(p, 0);
}
;
@@ -2326,17 +2326,17 @@ arg : lhs '=' arg_rhs
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
{
yyerror(&@1, p, "constant re-assignment");
$$ = new_begin(p, 0);
$$ = new_stmts(p, 0);
}
| tCOLON3 tCONSTANT tOP_ASGN arg_rhs
{
yyerror(&@1, p, "constant re-assignment");
$$ = new_begin(p, 0);
$$ = new_stmts(p, 0);
}
| backref tOP_ASGN arg_rhs
{
backref_error(p, $1);
$$ = new_begin(p, 0);
$$ = new_stmts(p, 0);
}
| arg tDOT2 arg
{
@@ -4309,7 +4309,7 @@ void_expr_error(parser_state *p, node *n)
void_expr_error(p, n->cdr->cdr);
}
break;
case NODE_BEGIN:
case NODE_STMTS:
if (n->cdr) {
while (n->cdr) {
n = n->cdr;
@@ -7129,8 +7129,8 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
nodetype = intn(tree->car);
tree = tree->cdr;
switch (nodetype) {
case NODE_BEGIN:
printf("NODE_BEGIN:\n");
case NODE_STMTS:
printf("NODE_STMTS:\n");
dump_recur(mrb, tree, offset+1);
break;