[YARP] Implement ConstantTargetNode

This commit is contained in:
Matt Valentine-House 2023-09-18 21:50:33 +01:00
parent 8f1b688177
commit 91b10c0b77
2 changed files with 20 additions and 0 deletions

View file

@ -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

View file

@ -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);