Skip to content

Ruby 3.2 argument forwarding #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions lib/syntax_tree/yarv/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -650,14 +650,36 @@ def visit_call(node)
flag |= CallData::CALL_ARGS_SPLAT
visit(arg_part)
when ArgsForward
flag |= CallData::CALL_ARGS_SPLAT
flag |= CallData::CALL_ARGS_BLOCKARG
flag |= CallData::CALL_TAILCALL if options.tailcall_optimization?

lookup = iseq.local_table.find(:*)
iseq.getlocal(lookup.index, lookup.level)
iseq.splatarray(arg_parts.length != 1)
if RUBY_VERSION < "3.2"
flag |= CallData::CALL_ARGS_SPLAT
lookup = iseq.local_table.find(:*)
iseq.getlocal(lookup.index, lookup.level)
iseq.splatarray(arg_parts.length != 1)
else
flag |= CallData::CALL_ARGS_SPLAT
lookup = iseq.local_table.find(:*)
iseq.getlocal(lookup.index, lookup.level)
iseq.splatarray(true)

flag |= CallData::CALL_KW_SPLAT
iseq.putspecialobject(PutSpecialObject::OBJECT_VMCORE)
iseq.newhash(0)
lookup = iseq.local_table.find(:**)
iseq.getlocal(lookup.index, lookup.level)
iseq.send(
YARV.calldata(
:"core#hash_merge_kwd",
2,
CallData::CALL_ARGS_SIMPLE
)
)
iseq.newarray(1)
iseq.concatarray
end

flag |= CallData::CALL_ARGS_BLOCKARG
lookup = iseq.local_table.find(:&)
iseq.getblockparamproxy(lookup.index, lookup.level)
when BareAssocHash
Expand Down Expand Up @@ -1304,13 +1326,25 @@ def visit_params(node)
end

if node.keyword_rest.is_a?(ArgsForward)
iseq.local_table.plain(:*)
iseq.local_table.plain(:&)
if RUBY_VERSION >= "3.2"
iseq.local_table.plain(:*)
iseq.local_table.plain(:**)
iseq.local_table.plain(:&)

iseq.argument_options[:rest_start] = iseq.argument_size
iseq.argument_options[:block_start] = iseq.argument_size + 2
iseq.argument_options[:kwrest] = iseq.argument_size + 1

iseq.argument_options[:rest_start] = iseq.argument_size
iseq.argument_options[:block_start] = iseq.argument_size + 1
iseq.argument_size += 3
else
iseq.local_table.plain(:*)
iseq.local_table.plain(:&)

iseq.argument_options[:rest_start] = iseq.argument_size
iseq.argument_options[:block_start] = iseq.argument_size + 1

iseq.argument_size += 2
iseq.argument_size += 2
end
elsif node.keyword_rest
visit(node.keyword_rest)
end
Expand Down