Skip to content
Prev Previous commit
Next Next commit
Start using labels for jumps
  • Loading branch information
kddnewton committed Nov 25, 2022
commit 633ab9bea7f542b098c975296e7e6044faefdb51
12 changes: 7 additions & 5 deletions lib/syntax_tree/yarv/bf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,25 @@ def input_char(iseq)

# unless $tape[$cursor] == 0
def loop_start(iseq)
start_label = iseq.label_at_index
start_label = iseq.label
end_label = iseq.label

iseq.push(start_label)
iseq.getglobal(:$tape)
iseq.getglobal(:$cursor)
iseq.send(YARV.calldata(:[], 1))

iseq.putobject(0)
iseq.send(YARV.calldata(:==, 1))
iseq.branchunless(end_label)

branchunless = iseq.branchunless(-1)
[start_label, branchunless]
[start_label, end_label]
end

# Jump back to the start of the loop.
def loop_end(iseq, start_label, branchunless)
def loop_end(iseq, start_label, end_label)
iseq.jump(start_label)
branchunless.patch!(iseq)
iseq.push(end_label)
end
end
end
Expand Down
Loading