mruby-compiler: improve for-loop variable dump with labeled sections

Enhanced NODE_FOR dump to properly handle the cons-list structure of
FOR_NODE_VAR with clear section labels. The structure contains:
- car: cons-list of pre-splat variables
- cdr->car: splat varnode (not a cons-list)
- cdr->cdr->car: cons-list of post-splat variables

Added "splat var:" and "post var:" labels to distinguish sections
and simplified the dump logic for better readability.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-09-30 13:37:22 +09:00
parent 791f631191
commit 29e70c10ba
2 changed files with 1091 additions and 1055 deletions
+33 -15
View File
@@ -566,6 +566,7 @@ new_until_mod(parser_state *p, node *a, node *b)
return until_node;
}
/* (:for var obj body) */
static node*
new_for(parser_state *p, node *v, node *o, node *b)
@@ -8115,23 +8116,40 @@ dump_node(mrb_state *mrb, node *tree, int offset)
case NODE_FOR:
printf("NODE_FOR:\n");
{
if (FOR_NODE_VAR(tree)) {
dump_prefix(offset+1, lineno);
printf("var:\n");
dump_node(mrb, FOR_NODE_VAR(tree), offset+2);
}
if (FOR_NODE_ITERABLE(tree)) {
dump_prefix(offset+1, lineno);
printf("iterable:\n");
dump_node(mrb, FOR_NODE_ITERABLE(tree), offset+2);
}
if (FOR_NODE_BODY(tree)) {
dump_prefix(offset+1, lineno);
printf("body:\n");
dump_node(mrb, FOR_NODE_BODY(tree), offset+2);
if (FOR_NODE_VAR(tree)) {
dump_prefix(offset+1, lineno);
printf("var:\n");
/* FOR_NODE_VAR structure:
* var_list->car: cons-list of pre-splat variables
* var_list->cdr->car: splat varnode (not a cons-list)
* var_list->cdr->cdr->car: cons-list of post-splat variables */
node *var_list = FOR_NODE_VAR(tree);
if (var_list) {
dump_recur(mrb, var_list->car, offset+2);
if (var_list && var_list->cdr) {
/* Second element is a varnode, not a cons-list */
dump_prefix(offset+1, lineno);
printf("splat var:\n");
dump_node(mrb, var_list->cdr->car, offset+2);
if (var_list->cdr->cdr) {
/* Third element is a cons-list of post-splat variables */
dump_prefix(offset+1, lineno);
printf("post var:\n");
dump_recur(mrb, var_list->cdr->cdr->car, offset+2);
}
}
}
}
if (FOR_NODE_ITERABLE(tree)) {
dump_prefix(offset+1, lineno);
printf("iterable:\n");
dump_node(mrb, FOR_NODE_ITERABLE(tree), offset+2);
}
if (FOR_NODE_BODY(tree)) {
dump_prefix(offset+1, lineno);
printf("body:\n");
dump_node(mrb, FOR_NODE_BODY(tree), offset+2);
}
break;
case NODE_DOT2:
File diff suppressed because it is too large Load Diff