mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-compiler: remove obsolete NODE_STR and NODE_XSTR node types
Remove NODE_STR and NODE_XSTR enum values and all associated code as these traditional node types are no longer used with the new cons list string representation. The compiler now exclusively uses the cons list format ((len . str) (-1 . node)...) for all string types. - remove NODE_STR and NODE_XSTR from node_type enum in node.h - remove NODE_STR and NODE_XSTR cases from codegen.c switch statements - remove NODE_STR and NODE_XSTR cases from parse.y codedump functions - remove unused codegen_str(), codegen_xstr(), and gen_xstr_var() functions - update codegen_dregx() to use cons list string handling instead of checking for obsolete NODE_STR - preserve str_dump() function wrapped in #if 0 for future codedump updates - update comment in node.h to reflect current node types NODE_DSTR remains available for dynamic string interpolation. All string functionality continues to work via the cons list representation and variable-sized node implementations. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -3355,7 +3355,6 @@ true_always(node *tree)
|
||||
switch (node_to_int(tree->car)) {
|
||||
case NODE_TRUE:
|
||||
case NODE_INT:
|
||||
case NODE_STR:
|
||||
case NODE_SYM:
|
||||
return TRUE;
|
||||
default:
|
||||
@@ -4299,27 +4298,6 @@ codegen_int(codegen_scope *s, node *tree, int val)
|
||||
push();
|
||||
}
|
||||
|
||||
static void
|
||||
codegen_xstr(codegen_scope *s, node *tree, int val)
|
||||
{
|
||||
char *p = (char*)tree->car;
|
||||
mrb_int len = node_to_int(tree->cdr);
|
||||
int off = new_lit_str(s, p, len);
|
||||
int sym;
|
||||
|
||||
/* Always execute backtick command for side effects, even in NOVAL mode */
|
||||
push();
|
||||
genop_2(s, OP_STRING, cursp(), off);
|
||||
push(); push();
|
||||
pop_n(3);
|
||||
sym = new_sym(s, MRB_OPSYM_2(s->mrb, tick)); /* ` */
|
||||
genop_3(s, OP_SSEND, cursp(), sym, 1);
|
||||
|
||||
if (val) {
|
||||
push(); /* Keep result on stack if needed */
|
||||
}
|
||||
/* If val=0, the result is discarded but the method was still called */
|
||||
}
|
||||
|
||||
static void
|
||||
codegen_dxstr(codegen_scope *s, node *tree, int val)
|
||||
@@ -4357,18 +4335,6 @@ codegen_heredoc_dstr(codegen_scope *s, node *tree, int val)
|
||||
codegen_cons_list_string(s, tree, val);
|
||||
}
|
||||
|
||||
static void
|
||||
codegen_str(codegen_scope *s, node *tree, int val)
|
||||
{
|
||||
if (val) {
|
||||
char *p = (char*)tree->car;
|
||||
mrb_int len = node_to_int(tree->cdr);
|
||||
int off = new_lit_str(s, p, len);
|
||||
|
||||
genop_2(s, OP_STRING, cursp(), off);
|
||||
push();
|
||||
}
|
||||
}
|
||||
|
||||
/* Common function to generate bytecode for cons list string representation
|
||||
* Handles list of elements where each element is either:
|
||||
@@ -5759,17 +5725,6 @@ gen_until_mod_var(codegen_scope *s, node *varnode, int val)
|
||||
codegen_while_until(s, (node*)&temp_tree, val, NODE_UNTIL_MOD);
|
||||
}
|
||||
|
||||
static void
|
||||
gen_xstr_var(codegen_scope *s, node *varnode, int val)
|
||||
{
|
||||
struct mrb_ast_xstr_node *n = (struct mrb_ast_xstr_node*)varnode;
|
||||
// Stack allocation for compatibility with existing codegen
|
||||
mrb_int len;
|
||||
const char *str = mrb_sym2name_len(s->mrb, n->name, &len);
|
||||
struct mrb_ast_node temp_car = { .car = (node*)str, .cdr = int_to_node((int)len) };
|
||||
struct mrb_ast_node temp_tree = { .car = (node*)&temp_car, .cdr = NULL };
|
||||
codegen_xstr(s, (node*)&temp_tree, val);
|
||||
}
|
||||
|
||||
static void
|
||||
gen_dxstr_var(codegen_scope *s, node *varnode, int val)
|
||||
@@ -6192,14 +6147,6 @@ codegen_variable_node(codegen_scope *s, node *varnode, int val)
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
case NODE_STR:
|
||||
if (val) {
|
||||
int off = new_lit_str(s, STR_NODE_PTR(varnode), STR_NODE_LEN(varnode));
|
||||
genop_2(s, OP_STRING, cursp(), off);
|
||||
push();
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
case NODE_SYM:
|
||||
codegen_sym(s, SYM_NODE_VALUE(varnode), val);
|
||||
return TRUE;
|
||||
@@ -6376,10 +6323,6 @@ codegen_variable_node(codegen_scope *s, node *varnode, int val)
|
||||
gen_until_mod_var(s, varnode, val);
|
||||
return TRUE;
|
||||
|
||||
case NODE_XSTR:
|
||||
gen_xstr_var(s, varnode, val);
|
||||
return TRUE;
|
||||
|
||||
case NODE_DXSTR:
|
||||
gen_dxstr_var(s, varnode, val);
|
||||
return TRUE;
|
||||
@@ -6730,10 +6673,6 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
codegen_negate(s, tree, val);
|
||||
break;
|
||||
|
||||
case NODE_STR:
|
||||
codegen_str(s, tree, val);
|
||||
break;
|
||||
|
||||
case NODE_HEREDOC:
|
||||
codegen_heredoc(s, tree, val);
|
||||
break;
|
||||
@@ -6754,10 +6693,6 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
codegen_dxstr(s, tree, val);
|
||||
break;
|
||||
|
||||
case NODE_XSTR:
|
||||
codegen_xstr(s, tree, val);
|
||||
break;
|
||||
|
||||
case NODE_REGX:
|
||||
codegen_regx(s, tree, val);
|
||||
break;
|
||||
|
||||
@@ -57,9 +57,7 @@ enum node_type {
|
||||
NODE_NEGATE,
|
||||
NODE_LAMBDA,
|
||||
NODE_SYM,
|
||||
NODE_STR,
|
||||
NODE_DSTR,
|
||||
NODE_XSTR,
|
||||
NODE_DXSTR,
|
||||
NODE_REGX,
|
||||
NODE_DREGX,
|
||||
@@ -154,7 +152,7 @@ struct mrb_ast_head_node {
|
||||
struct mrb_ast_var_header {
|
||||
uint16_t lineno; /* Line number information */
|
||||
uint16_t filename_index; /* File index information */
|
||||
uint8_t node_type; /* NODE_INT, NODE_STR, NODE_SYM, etc. */
|
||||
uint8_t node_type; /* NODE_INT, NODE_SYM, NODE_DSTR, etc. */
|
||||
uint8_t size_class; /* Size class for allocation/deallocation */
|
||||
uint16_t flags; /* Type-specific flags and metadata */
|
||||
/* Total: 8 bytes header for all variable nodes */
|
||||
|
||||
@@ -2542,9 +2542,7 @@ prohibit_literals(parser_state *p, node *n)
|
||||
else {
|
||||
switch (node_to_type(n->car)) {
|
||||
case NODE_INT:
|
||||
case NODE_STR:
|
||||
case NODE_DSTR:
|
||||
case NODE_XSTR:
|
||||
case NODE_DXSTR:
|
||||
case NODE_DREGX:
|
||||
case NODE_MATCH:
|
||||
@@ -8190,6 +8188,7 @@ dump_args(mrb_state *mrb, node *n, int offset)
|
||||
* performed at the caller, the string pointer returned as the return
|
||||
* value may become invalid.
|
||||
*/
|
||||
#if 0
|
||||
static const char*
|
||||
str_dump(mrb_state *mrb, const char *str, int len)
|
||||
{
|
||||
@@ -8208,6 +8207,8 @@ str_dump(mrb_state *mrb, const char *str, int len)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
|
||||
{
|
||||
@@ -8723,19 +8724,11 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
|
||||
mrb_parser_dump(mrb, tree, offset+1);
|
||||
break;
|
||||
|
||||
case NODE_STR:
|
||||
printf("NODE_STR %s len %d\n", str_dump(mrb, (char*)tree->car, node_to_int(tree->cdr)), node_to_int(tree->cdr));
|
||||
break;
|
||||
|
||||
case NODE_DSTR:
|
||||
printf("NODE_DSTR:\n");
|
||||
dump_recur(mrb, tree, offset+1);
|
||||
break;
|
||||
|
||||
case NODE_XSTR:
|
||||
printf("NODE_XSTR %s len %d\n", str_dump(mrb, (char*)tree->car, node_to_int(tree->cdr)), node_to_int(tree->cdr));
|
||||
break;
|
||||
|
||||
case NODE_DXSTR:
|
||||
printf("NODE_DXSTR:\n");
|
||||
dump_recur(mrb, tree, offset+1);
|
||||
|
||||
+1028
-1035
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user