File tree Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -95,12 +95,18 @@ def change_by(value)
95
95
class Label
96
96
attr_reader :name
97
97
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
+
98
103
def initialize ( name = nil )
99
104
@name = name
100
105
end
101
106
102
- def patch! ( name )
107
+ def patch! ( name , node )
103
108
@name = name
109
+ @node = node
104
110
end
105
111
end
106
112
@@ -220,19 +226,17 @@ def to_a
220
226
specialize_instructions! if options . specialized_instruction?
221
227
222
228
# 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
235
238
end
239
+ end
236
240
237
241
# Next, dump all of the instructions into a flat list.
238
242
dumped =
You can’t perform that action at this time.
0 commit comments