Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
newarraykwsplat
  • Loading branch information
kddnewton committed Nov 22, 2022
commit 1262b52c781d35df4c911d87ed47be2322812b0d
9 changes: 9 additions & 0 deletions lib/syntax_tree/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ def visit_args(node)
def visit_array(node)
if (compiled = RubyVisitor.compile(node))
iseq.duparray(compiled)
elsif node.contents && node.contents.parts.length == 1 &&
node.contents.parts.first.is_a?(BareAssocHash) &&
node.contents.parts.first.assocs.length == 1 &&
node.contents.parts.first.assocs.first.is_a?(AssocSplat)
iseq.putspecialobject(YARV::VM_SPECIAL_OBJECT_VMCORE)
iseq.newhash(0)
visit(node.contents.parts.first)
iseq.send(:"core#hash_merge_kwd", 2)
iseq.newarraykwsplat(1)
else
length = 0

Expand Down
5 changes: 5 additions & 0 deletions lib/syntax_tree/yarv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,11 @@ def newarray(length)
push([:newarray, length])
end

def newarraykwsplat(length)
stack.change_by(-length + 1)
push([:newarraykwsplat, length])
end

def newhash(length)
stack.change_by(-length + 1)
push([:newhash, length])
Expand Down
1 change: 1 addition & 0 deletions test/compiler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class CompilerTest < Minitest::Test
"[1, 2, 3].min",
"[foo, bar, baz].min",
"[foo, bar, baz].min(1)",
"[**{ x: true }][0][:x]",
# Core method calls
"alias foo bar",
"alias :foo :bar",
Expand Down