mirror of
https://github.com/ruby/ruby.git
synced 2025-08-28 15:36:16 +02:00
[YARP] Implement ConstantTargetNode
This commit is contained in:
parent
8f1b688177
commit
91b10c0b77
2 changed files with 20 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue