summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Valentine-House <matt@eightbitraptor.com>2023-09-18 21:50:33 +0100
committerMatt Valentine-House <matt@eightbitraptor.com>2023-09-19 14:53:39 +0100
commit91b10c0b77c5408cbbbc2fc6d678ee92b2d4b28a (patch)
treebaaea6db0d5977bf8a09ab47179ed9b63dc9a011
parent8f1b688177dba412821cbc01ef2cabdce385f7ba (diff)
[YARP] Implement ConstantTargetNode
-rw-r--r--test/yarp/compiler_test.rb14
-rw-r--r--yarp/yarp_compiler.c6
2 files changed, 20 insertions, 0 deletions
diff --git a/test/yarp/compiler_test.rb b/test/yarp/compiler_test.rb
index b8a636d984..c6b7fed1eb 100644
--- a/test/yarp/compiler_test.rb
+++ b/test/yarp/compiler_test.rb
@@ -103,6 +103,20 @@ module YARP
test_yarp_eval("class YARP::CompilerTest; @@yct = 0; @@yct += 1; end")
end
+ def test_ConstantTargetNode
+ # We don't call test_yarp_eval directly in this case becuase we
+ # don't want to assign the constant mutliple times if we run
+ # with `--repeat-count`
+ # Instead, we eval manually here, and remove the constant to
+ constant_names = ["YCT", "YCT2"]
+ source = "#{constant_names.join(",")} = 1"
+ yarp_eval = RubyVM::InstructionSequence.compile_yarp(source).eval
+ assert_equal yarp_eval, 1
+ constant_names.map { |name|
+ Object.send(:remove_const, name)
+ }
+ end
+
def test_ConstantWriteNode
# We don't call test_yarp_eval directly in this case becuase we
# don't want to assign the constant mutliple times if we run
diff --git a/yarp/yarp_compiler.c b/yarp/yarp_compiler.c
index 400583130a..2a8ebe5403 100644
--- a/yarp/yarp_compiler.c
+++ b/yarp/yarp_compiler.c
@@ -994,6 +994,12 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret,
return;
}
+ case YP_CONSTANT_TARGET_NODE: {
+ yp_constant_target_node_t *constant_write_node = (yp_constant_target_node_t *) node;
+ ADD_INSN1(ret, &dummy_line_node, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
+ ADD_INSN1(ret, &dummy_line_node, setconstant, ID2SYM(yp_constant_id_lookup(compile_context, constant_write_node->name)));
+ return;
+ }
case YP_CONSTANT_WRITE_NODE: {
yp_constant_write_node_t *constant_write_node = (yp_constant_write_node_t *) node;
YP_COMPILE_NOT_POPPED(constant_write_node->value);