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

Commit b422b42

Browse files
committed
Give a reference on the labels to their container nodes
1 parent f3ed30d commit b422b42

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lib/syntax_tree/yarv/instruction_sequence.rb

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,18 @@ def change_by(value)
9595
class Label
9696
attr_reader :name
9797

98+
# When we're serializing the instruction sequence, we need to be able to
99+
# look up the label from the branch instructions and then access the
100+
# subsequent node. So we'll store the reference here.
101+
attr_reader :node
102+
98103
def initialize(name = nil)
99104
@name = name
100105
end
101106

102-
def patch!(name)
107+
def patch!(name, node)
103108
@name = name
109+
@node = node
104110
end
105111
end
106112

@@ -220,19 +226,17 @@ def to_a
220226
specialize_instructions! if options.specialized_instruction?
221227

222228
# Next, set it up so that all of the labels get their correct name.
223-
insns
224-
.each
225-
.inject(0) do |length, insn|
226-
case insn
227-
when Integer, Symbol
228-
length
229-
when Label
230-
insn.patch!(:"label_#{length}")
231-
length
232-
else
233-
length + insn.length
234-
end
229+
length = 0
230+
insns.each_node do |node, value|
231+
case value
232+
when Integer, Symbol
233+
# skip
234+
when Label
235+
value.patch!(:"label_#{length}", node)
236+
else
237+
length += value.length
235238
end
239+
end
236240

237241
# Next, dump all of the instructions into a flat list.
238242
dumped =

0 commit comments

Comments
 (0)