summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-04-04 11:15:10 -0400
committerKevin Newton <kddnewton@gmail.com>2024-04-04 14:14:55 -0400
commit3cc61dc9ba8804bf00e8c68a5162fabf4e2457e0 (patch)
tree7a09555a30571c67182e4409f0178bf426ca3bf4
parent116a332c3a4a26fb217f3c1b5fbf045aecbc55fc (diff)
[PRISM] Remove dummy_line_node usage from class variable nodes
-rw-r--r--prism_compile.c129
1 files changed, 58 insertions, 71 deletions
diff --git a/prism_compile.c b/prism_compile.c
index e11df40419..88759fc9f5 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -214,7 +214,7 @@ parse_rational(const pm_rational_node_t *node)
* then convert into an imaginary with rb_complex_raw.
*/
static VALUE
-parse_imaginary(pm_imaginary_node_t *node)
+parse_imaginary(const pm_imaginary_node_t *node)
{
VALUE imaginary_part;
switch (PM_NODE_TYPE(node->numeric)) {
@@ -5231,110 +5231,97 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
return;
}
case PM_CLASS_VARIABLE_AND_WRITE_NODE: {
- pm_class_variable_and_write_node_t *class_variable_and_write_node = (pm_class_variable_and_write_node_t*) node;
-
- LABEL *end_label = NEW_LABEL(lineno);
-
- ID class_variable_name_id = pm_constant_id_lookup(scope_node, class_variable_and_write_node->name);
- VALUE class_variable_name_val = ID2SYM(class_variable_name_id);
-
- ADD_INSN2(ret, &dummy_line_node, getclassvariable,
- class_variable_name_val,
- get_cvar_ic_value(iseq, class_variable_name_id));
-
- PM_DUP_UNLESS_POPPED;
+ // @@foo &&= bar
+ // ^^^^^^^^^^^^^
+ const pm_class_variable_and_write_node_t *cast = (const pm_class_variable_and_write_node_t *) node;
+ LABEL *end_label = NEW_LABEL(location.line);
- ADD_INSNL(ret, &dummy_line_node, branchunless, end_label);
+ ID name_id = pm_constant_id_lookup(scope_node, cast->name);
+ VALUE name = ID2SYM(name_id);
- PM_POP_UNLESS_POPPED;
+ PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
+ if (!popped) PUSH_INSN(ret, location, dup);
- PM_COMPILE_NOT_POPPED(class_variable_and_write_node->value);
+ PUSH_INSNL(ret, location, branchunless, end_label);
+ if (!popped) PUSH_INSN(ret, location, pop);
- PM_DUP_UNLESS_POPPED;
+ PM_COMPILE_NOT_POPPED(cast->value);
+ if (!popped) PUSH_INSN(ret, location, dup);
- ADD_INSN2(ret, &dummy_line_node, setclassvariable,
- class_variable_name_val,
- get_cvar_ic_value(iseq, class_variable_name_id));
- ADD_LABEL(ret, end_label);
+ PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
+ PUSH_LABEL(ret, end_label);
return;
}
case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
- pm_class_variable_operator_write_node_t *class_variable_operator_write_node = (pm_class_variable_operator_write_node_t*) node;
-
- ID class_variable_name_id = pm_constant_id_lookup(scope_node, class_variable_operator_write_node->name);
- VALUE class_variable_name_val = ID2SYM(class_variable_name_id);
+ // @@foo += bar
+ // ^^^^^^^^^^^^
+ const pm_class_variable_operator_write_node_t *cast = (const pm_class_variable_operator_write_node_t *) node;
- ADD_INSN2(ret, &dummy_line_node, getclassvariable,
- class_variable_name_val,
- get_cvar_ic_value(iseq, class_variable_name_id));
+ ID name_id = pm_constant_id_lookup(scope_node, cast->name);
+ VALUE name = ID2SYM(name_id);
- PM_COMPILE_NOT_POPPED(class_variable_operator_write_node->value);
- ID method_id = pm_constant_id_lookup(scope_node, class_variable_operator_write_node->operator);
+ PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
+ PM_COMPILE_NOT_POPPED(cast->value);
+ ID method_id = pm_constant_id_lookup(scope_node, cast->operator);
int flags = VM_CALL_ARGS_SIMPLE;
- ADD_SEND_WITH_FLAG(ret, &dummy_line_node, method_id, INT2NUM(1), INT2FIX(flags));
-
- PM_DUP_UNLESS_POPPED;
+ PUSH_SEND_WITH_FLAG(ret, location, method_id, INT2NUM(1), INT2FIX(flags));
- ADD_INSN2(ret, &dummy_line_node, setclassvariable,
- class_variable_name_val,
- get_cvar_ic_value(iseq, class_variable_name_id));
+ if (!popped) PUSH_INSN(ret, location, dup);
+ PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
return;
}
case PM_CLASS_VARIABLE_OR_WRITE_NODE: {
- pm_class_variable_or_write_node_t *class_variable_or_write_node = (pm_class_variable_or_write_node_t*) node;
-
- LABEL *end_label = NEW_LABEL(lineno);
- LABEL *start_label = NEW_LABEL(lineno);
-
- ADD_INSN(ret, &dummy_line_node, putnil);
- ADD_INSN3(ret, &dummy_line_node, defined, INT2FIX(DEFINED_CVAR),
- ID2SYM(pm_constant_id_lookup(scope_node, class_variable_or_write_node->name)), Qtrue);
-
- ADD_INSNL(ret, &dummy_line_node, branchunless, start_label);
-
- ID class_variable_name_id = pm_constant_id_lookup(scope_node, class_variable_or_write_node->name);
- VALUE class_variable_name_val = ID2SYM(class_variable_name_id);
-
- ADD_INSN2(ret, &dummy_line_node, getclassvariable,
- class_variable_name_val,
- get_cvar_ic_value(iseq, class_variable_name_id));
+ // @@foo ||= bar
+ // ^^^^^^^^^^^^^
+ const pm_class_variable_or_write_node_t *cast = (const pm_class_variable_or_write_node_t *) node;
+ LABEL *end_label = NEW_LABEL(location.line);
+ LABEL *start_label = NEW_LABEL(location.line);
- PM_DUP_UNLESS_POPPED;
+ ID name_id = pm_constant_id_lookup(scope_node, cast->name);
+ VALUE name = ID2SYM(name_id);
- ADD_INSNL(ret, &dummy_line_node, branchif, end_label);
+ PUSH_INSN(ret, location, putnil);
+ PUSH_INSN3(ret, location, defined, INT2FIX(DEFINED_CVAR), name, Qtrue);
+ PUSH_INSNL(ret, location, branchunless, start_label);
- PM_POP_UNLESS_POPPED;
- ADD_LABEL(ret, start_label);
+ PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
+ if (!popped) PUSH_INSN(ret, location, dup);
- PM_COMPILE_NOT_POPPED(class_variable_or_write_node->value);
+ PUSH_INSNL(ret, location, branchif, end_label);
+ if (!popped) PUSH_INSN(ret, location, pop);
- PM_DUP_UNLESS_POPPED;
+ PUSH_LABEL(ret, start_label);
+ PM_COMPILE_NOT_POPPED(cast->value);
+ if (!popped) PUSH_INSN(ret, location, dup);
- ADD_INSN2(ret, &dummy_line_node, setclassvariable,
- class_variable_name_val,
- get_cvar_ic_value(iseq, class_variable_name_id));
- ADD_LABEL(ret, end_label);
+ PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
+ PUSH_LABEL(ret, end_label);
return;
}
case PM_CLASS_VARIABLE_READ_NODE: {
+ // @@foo
+ // ^^^^^
if (!popped) {
- pm_class_variable_read_node_t *class_variable_read_node = (pm_class_variable_read_node_t *) node;
- ID cvar_name = pm_constant_id_lookup(scope_node, class_variable_read_node->name);
- ADD_INSN2(ret, &dummy_line_node, getclassvariable, ID2SYM(cvar_name), get_cvar_ic_value(iseq, cvar_name));
+ const pm_class_variable_read_node_t *cast = (const pm_class_variable_read_node_t *) node;
+ ID name = pm_constant_id_lookup(scope_node, cast->name);
+ PUSH_INSN2(ret, location, getclassvariable, ID2SYM(name), get_cvar_ic_value(iseq, name));
}
return;
}
case PM_CLASS_VARIABLE_WRITE_NODE: {
- pm_class_variable_write_node_t *write_node = (pm_class_variable_write_node_t *) node;
- PM_COMPILE_NOT_POPPED(write_node->value);
- PM_DUP_UNLESS_POPPED;
+ // @@foo = 1
+ // ^^^^^^^^^
+ const pm_class_variable_write_node_t *cast = (const pm_class_variable_write_node_t *) node;
+ PM_COMPILE_NOT_POPPED(cast->value);
+ if (!popped) PUSH_INSN(ret, location, dup);
+
+ ID name = pm_constant_id_lookup(scope_node, cast->name);
+ PUSH_INSN2(ret, location, setclassvariable, ID2SYM(name), get_cvar_ic_value(iseq, name));
- ID cvar_name = pm_constant_id_lookup(scope_node, write_node->name);
- ADD_INSN2(ret, &dummy_line_node, setclassvariable, ID2SYM(cvar_name), get_cvar_ic_value(iseq, cvar_name));
return;
}
case PM_CONSTANT_PATH_NODE: {