Skip to content

Commit 10d88ec

Browse files
authored
[PRISM] Compile AliasGlobalVariableNode (#8675)
1 parent 8f33d80 commit 10d88ec

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

prism_compile.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ parse_string_symbol(pm_string_t *string)
161161
return parse_symbol(start, start + pm_string_length(string));
162162
}
163163

164+
static inline ID
165+
parse_location_symbol(pm_location_t *location)
166+
{
167+
return parse_symbol(location->start, location->end);
168+
}
169+
164170
static int
165171
pm_optimizable_range_item_p(pm_node_t *node)
166172
{
@@ -848,6 +854,19 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
848854
NODE dummy_line_node = generate_dummy_line_node(lineno, lineno);
849855

850856
switch (PM_NODE_TYPE(node)) {
857+
case PM_ALIAS_GLOBAL_VARIABLE_NODE: {
858+
pm_alias_global_variable_node_t *alias_node = (pm_alias_global_variable_node_t *) node;
859+
860+
ADD_INSN1(ret, &dummy_line_node, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
861+
862+
ADD_INSN1(ret, &dummy_line_node, putobject, ID2SYM(parse_location_symbol(&alias_node->new_name->location)));
863+
ADD_INSN1(ret, &dummy_line_node, putobject, ID2SYM(parse_location_symbol(&alias_node->old_name->location)));
864+
865+
ADD_SEND(ret, &dummy_line_node, id_core_set_variable_alias, INT2FIX(2));
866+
867+
PM_POP_IF_POPPED;
868+
return;
869+
}
851870
case PM_ALIAS_METHOD_NODE: {
852871
pm_alias_method_node_t *alias_node = (pm_alias_method_node_t *) node;
853872

test/ruby/test_compile_prism.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@ def test_ParenthesesNode
401401
# Methods / parameters #
402402
############################################################################
403403

404+
def test_AliasGlobalVariableNode
405+
test_prism_eval("alias $prism_foo $prism_bar")
406+
end
407+
408+
def test_AliasMethodNode
409+
test_prism_eval("alias :prism_a :to_s")
410+
end
411+
404412
def test_UndefNode
405413
test_prism_eval("def prism_undef_node_1; end; undef prism_undef_node_1")
406414
test_prism_eval(<<-HERE

0 commit comments

Comments
 (0)