From 8034f71a5e72da3a7a62454193d7a2c914859e64 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 2 Sep 2025 22:53:21 +0900 Subject: [PATCH] mruby-compiler: replace NODE_LITERAL_DELIM with (0 . 0) pattern NODE_LITERAL_DELIM was only used as a marker in literal arrays. Replace it with a (0 . 0) pattern which cannot conflict with empty strings (which would be (0 . ptr) with non-NULL ptr). This allows removing NODE_LITERAL_DELIM from the node type enum. Co-authored-by: Claude --- mrbgems/mruby-compiler/core/codegen.c | 4 ++-- mrbgems/mruby-compiler/core/node.h | 1 - mrbgems/mruby-compiler/core/parse.y | 6 +----- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 5ac30cf25..6c98e1426 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -68,10 +68,10 @@ /* Maximum number of arguments for some opcodes like OP_SUPER or OP_ARGARY. */ #define MAXARG_S (1<<16) -/* Macro to detect NODE_LITERAL_DELIM separators in literal arrays */ +/* Macro to detect (0 . 0) separators in literal arrays */ #define IS_LITERAL_DELIM(node) \ ((node) && (node)->car && \ - node_to_int((node)->car->car) == NODE_LITERAL_DELIM && \ + (node)->car->car == NULL && \ (node)->car->cdr == NULL) typedef mrb_ast_node node; diff --git a/mrbgems/mruby-compiler/core/node.h b/mrbgems/mruby-compiler/core/node.h index 231d4a577..061e7aa6a 100644 --- a/mrbgems/mruby-compiler/core/node.h +++ b/mrbgems/mruby-compiler/core/node.h @@ -88,7 +88,6 @@ enum node_type { NODE_POSTEXE, NODE_DSYM, NODE_HEREDOC, - NODE_LITERAL_DELIM, NODE_WORDS, NODE_SYMBOLS, NODE_VARIABLE, diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index d7fe602a8..2e6da10bd 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -2270,7 +2270,7 @@ new_bv(parser_state *p, mrb_sym id) static node* new_literal_delim(parser_state *p) { - return cons_head((node*)NODE_LITERAL_DELIM, 0); + return cons((node*)0, (node*)0); } /* (:words . a) */ @@ -8781,10 +8781,6 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) dump_recur(mrb, tree, offset+1); break; - case NODE_LITERAL_DELIM: - printf("NODE_LITERAL_DELIM\n"); - break; - case NODE_SELF: printf("NODE_SELF\n"); break;