Skip to content

Commit c59c585

Browse files
committed
Handle until
1 parent 0b2d012 commit c59c585

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/syntax_tree/visitor/compiler.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,24 @@ def visit_undef(node)
19971997
end
19981998
end
19991999

2000+
def visit_until(node)
2001+
jumps = []
2002+
2003+
jumps << builder.jump(-1)
2004+
builder.putnil
2005+
builder.pop
2006+
jumps << builder.jump(-1)
2007+
2008+
label = builder.label
2009+
visit(node.statements)
2010+
builder.pop
2011+
jumps.each { |jump| jump[1] = builder.label }
2012+
2013+
visit(node.predicate)
2014+
builder.branchunless(label)
2015+
builder.putnil if last_statement?
2016+
end
2017+
20002018
def visit_var_field(node)
20012019
case node.value
20022020
when CVar, IVar

test/compiler_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ class CompilerTest < Minitest::Test
260260
"if foo then bar elsif baz then qux end",
261261
"foo if bar",
262262
"foo while bar",
263+
"while foo do bar end",
264+
"foo until bar",
265+
"until foo do bar end",
263266
"for i in [1, 2, 3] do i end",
264267
"foo ? bar : baz",
265268
# Constructed values

0 commit comments

Comments
 (0)