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
Handle until
  • Loading branch information
kddnewton committed Nov 18, 2022
commit c59c58550b19186a7d8e61fd3b6bee3796760263
18 changes: 18 additions & 0 deletions lib/syntax_tree/visitor/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,24 @@ def visit_undef(node)
end
end

def visit_until(node)
jumps = []

jumps << builder.jump(-1)
builder.putnil
builder.pop
jumps << builder.jump(-1)

label = builder.label
visit(node.statements)
builder.pop
jumps.each { |jump| jump[1] = builder.label }

visit(node.predicate)
builder.branchunless(label)
builder.putnil if last_statement?
end

def visit_var_field(node)
case node.value
when CVar, IVar
Expand Down
3 changes: 3 additions & 0 deletions test/compiler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ class CompilerTest < Minitest::Test
"if foo then bar elsif baz then qux end",
"foo if bar",
"foo while bar",
"while foo do bar end",
"foo until bar",
"until foo do bar end",
"for i in [1, 2, 3] do i end",
"foo ? bar : baz",
# Constructed values
Expand Down