Skip to content

Commit 18468ac

Browse files
authored
Merge pull request #221 from ruby-syntax-tree/fix-arg-forwarding-32
Ruby 3.2 argument forwarding
2 parents d9df121 + ad671c4 commit 18468ac

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

lib/syntax_tree/yarv/compiler.rb

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -650,14 +650,36 @@ def visit_call(node)
650650
flag |= CallData::CALL_ARGS_SPLAT
651651
visit(arg_part)
652652
when ArgsForward
653-
flag |= CallData::CALL_ARGS_SPLAT
654-
flag |= CallData::CALL_ARGS_BLOCKARG
655653
flag |= CallData::CALL_TAILCALL if options.tailcall_optimization?
656654

657-
lookup = iseq.local_table.find(:*)
658-
iseq.getlocal(lookup.index, lookup.level)
659-
iseq.splatarray(arg_parts.length != 1)
655+
if RUBY_VERSION < "3.2"
656+
flag |= CallData::CALL_ARGS_SPLAT
657+
lookup = iseq.local_table.find(:*)
658+
iseq.getlocal(lookup.index, lookup.level)
659+
iseq.splatarray(arg_parts.length != 1)
660+
else
661+
flag |= CallData::CALL_ARGS_SPLAT
662+
lookup = iseq.local_table.find(:*)
663+
iseq.getlocal(lookup.index, lookup.level)
664+
iseq.splatarray(true)
665+
666+
flag |= CallData::CALL_KW_SPLAT
667+
iseq.putspecialobject(PutSpecialObject::OBJECT_VMCORE)
668+
iseq.newhash(0)
669+
lookup = iseq.local_table.find(:**)
670+
iseq.getlocal(lookup.index, lookup.level)
671+
iseq.send(
672+
YARV.calldata(
673+
:"core#hash_merge_kwd",
674+
2,
675+
CallData::CALL_ARGS_SIMPLE
676+
)
677+
)
678+
iseq.newarray(1)
679+
iseq.concatarray
680+
end
660681

682+
flag |= CallData::CALL_ARGS_BLOCKARG
661683
lookup = iseq.local_table.find(:&)
662684
iseq.getblockparamproxy(lookup.index, lookup.level)
663685
when BareAssocHash
@@ -1304,13 +1326,25 @@ def visit_params(node)
13041326
end
13051327

13061328
if node.keyword_rest.is_a?(ArgsForward)
1307-
iseq.local_table.plain(:*)
1308-
iseq.local_table.plain(:&)
1329+
if RUBY_VERSION >= "3.2"
1330+
iseq.local_table.plain(:*)
1331+
iseq.local_table.plain(:**)
1332+
iseq.local_table.plain(:&)
1333+
1334+
iseq.argument_options[:rest_start] = iseq.argument_size
1335+
iseq.argument_options[:block_start] = iseq.argument_size + 2
1336+
iseq.argument_options[:kwrest] = iseq.argument_size + 1
13091337

1310-
iseq.argument_options[:rest_start] = iseq.argument_size
1311-
iseq.argument_options[:block_start] = iseq.argument_size + 1
1338+
iseq.argument_size += 3
1339+
else
1340+
iseq.local_table.plain(:*)
1341+
iseq.local_table.plain(:&)
1342+
1343+
iseq.argument_options[:rest_start] = iseq.argument_size
1344+
iseq.argument_options[:block_start] = iseq.argument_size + 1
13121345

1313-
iseq.argument_size += 2
1346+
iseq.argument_size += 2
1347+
end
13141348
elsif node.keyword_rest
13151349
visit(node.keyword_rest)
13161350
end

0 commit comments

Comments
 (0)