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

Commit 633ab9b

Browse files
committed
Start using labels for jumps
1 parent 5dcd672 commit 633ab9b

File tree

6 files changed

+196
-209
lines changed

6 files changed

+196
-209
lines changed

lib/syntax_tree/yarv/bf.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,25 @@ def input_char(iseq)
153153

154154
# unless $tape[$cursor] == 0
155155
def loop_start(iseq)
156-
start_label = iseq.label_at_index
156+
start_label = iseq.label
157+
end_label = iseq.label
157158

159+
iseq.push(start_label)
158160
iseq.getglobal(:$tape)
159161
iseq.getglobal(:$cursor)
160162
iseq.send(YARV.calldata(:[], 1))
161163

162164
iseq.putobject(0)
163165
iseq.send(YARV.calldata(:==, 1))
166+
iseq.branchunless(end_label)
164167

165-
branchunless = iseq.branchunless(-1)
166-
[start_label, branchunless]
168+
[start_label, end_label]
167169
end
168170

169171
# Jump back to the start of the loop.
170-
def loop_end(iseq, start_label, branchunless)
172+
def loop_end(iseq, start_label, end_label)
171173
iseq.jump(start_label)
172-
branchunless.patch!(iseq)
174+
iseq.push(end_label)
173175
end
174176
end
175177
end

0 commit comments

Comments
 (0)