Skip to content

Commit

Permalink
[PRISM] Compile CallTargetNode
Browse files Browse the repository at this point in the history
  • Loading branch information
eightbitraptor authored and kddnewton committed Dec 15, 2023
1 parent 5b6a4d8 commit 161787f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
20 changes: 19 additions & 1 deletion prism_compile.c
Expand Up @@ -1226,6 +1226,12 @@ pm_compile_multi_write_lhs(rb_iseq_t *iseq, NODE dummy_line_node, const uint8_t
}
break;
}
case PM_CALL_TARGET_NODE: {
pm_call_target_node_t *cast = (pm_call_target_node_t *)node;
PM_COMPILE_NOT_POPPED((pm_node_t *)cast->receiver);
pushed++;
break;
}
case PM_MULTI_TARGET_NODE: {
pm_multi_target_node_t *cast = (pm_multi_target_node_t *) node;
for (size_t index = 0; index < cast->lefts.size; index++) {
Expand Down Expand Up @@ -4940,7 +4946,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
pm_multi_write_node_t *multi_write_node = (pm_multi_write_node_t *)node;
pm_node_list_t *lefts = &multi_write_node->lefts;
pm_node_list_t *rights = &multi_write_node->rights;
size_t argc = 0;
size_t argc = 1;

// pre-process the left hand side of multi-assignments.
uint8_t pushed = 0;
Expand Down Expand Up @@ -4997,6 +5003,18 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
PM_POP;
PM_POP;
remainder -= argc;

} else if (PM_NODE_TYPE_P(considered_node, PM_CALL_TARGET_NODE)) {
pm_call_target_node_t *cast = (pm_call_target_node_t *)considered_node;

VALUE vals = INT2FIX(remainder + (lefts->size - index));
ADD_INSN1(ret, &dummy_line_node, topn, vals);
ADD_INSN(ret, &dummy_line_node, swap);

ID method_id = pm_constant_id_lookup(scope_node, cast->name);
ADD_SEND(ret, &dummy_line_node, method_id, INT2FIX(argc));
PM_POP;
remainder -= argc;
} else {
PM_COMPILE(lefts->nodes[index]);
}
Expand Down
24 changes: 24 additions & 0 deletions test/ruby/test_compile_prism.rb
Expand Up @@ -534,6 +534,30 @@ def test_MultiWriteNode
assert_prism_eval("_, {}[:foo], _ = 1")
assert_prism_eval("_,{}[:foo], _, {}[:bar] = 1")

assert_prism_eval(<<~CODE)
class Foo
def bar=(x); end
def baz=(c); end
end
foo = Foo.new
foo.bar, foo.baz = 1
CODE
assert_prism_eval(<<~CODE)
class Foo
def bar=(x); end
def baz=(c); end
end
foo = Foo.new
_, foo.bar, foo.baz = 1
CODE
assert_prism_eval(<<~CODE)
class Foo
def bar=(x); end
def baz=(c); end
end
foo = Foo.new
_, foo.bar, _, foo.baz = 1
CODE
end

############################################################################
Expand Down

0 comments on commit 161787f

Please sign in to comment.