Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 69bf4bc

Browse files
committed
Handle lambda
1 parent 2f78d14 commit 69bf4bc

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/syntax_tree/visitor/compiler.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,22 @@ def visit_label(node)
15911591
builder.putobject(node.accept(RubyVisitor.new))
15921592
end
15931593

1594+
def visit_lambda(node)
1595+
lambda_iseq =
1596+
with_instruction_sequence(:block, "block in #{current_iseq.name}", current_iseq, node) do
1597+
visit(node.params)
1598+
visit(node.statements)
1599+
builder.leave
1600+
end
1601+
1602+
builder.putspecialobject(VM_SPECIAL_OBJECT_VMCORE)
1603+
builder.send(:lambda, 0, VM_CALL_FCALL, lambda_iseq)
1604+
end
1605+
1606+
def visit_lambda_var(node)
1607+
visit_block_var(node)
1608+
end
1609+
15941610
def visit_method_add_block(node)
15951611
visit_call(
15961612
CommandCall.new(

test/compiler_test.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,12 @@ class CompilerTest < Minitest::Test
385385
"foo {}",
386386
"foo do |bar| end",
387387
"foo { |bar| }",
388-
"foo { |bar; baz| }"
388+
"foo { |bar; baz| }",
389+
"-> do end",
390+
"-> {}",
391+
"-> (bar) do end",
392+
"-> (bar) {}",
393+
"-> (bar; baz) { }"
389394
]
390395

391396
# These are the combinations of instructions that we're going to test.

0 commit comments

Comments
 (0)