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

Commit f3ed30d

Browse files
committed
Have the instruction list point to values not necessarily instructions
1 parent 80de9c9 commit f3ed30d

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

lib/syntax_tree/yarv/instruction_sequence.rb

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ class InstructionSequence
1212
# and other transformations like instruction specialization.
1313
class InstructionList
1414
class Node
15-
attr_accessor :instruction, :next_node
15+
attr_accessor :value, :next_node
1616

17-
def initialize(instruction, next_node = nil)
18-
@instruction = instruction
17+
def initialize(value, next_node = nil)
18+
@value = value
1919
@next_node = next_node
2020
end
2121
end
@@ -29,15 +29,15 @@ def initialize
2929

3030
def each
3131
return to_enum(__method__) unless block_given?
32-
each_node { |node| yield node.instruction }
32+
each_node { |node| yield node.value }
3333
end
3434

3535
def each_node
3636
return to_enum(__method__) unless block_given?
3737
node = head_node
3838

3939
while node
40-
yield node
40+
yield node, node.value
4141
node = node.next_node
4242
end
4343
end
@@ -274,62 +274,56 @@ def to_a
274274
end
275275

276276
def specialize_instructions!
277-
insns.each_node do |node|
278-
case node.instruction
277+
insns.each_node do |node, value|
278+
case value
279279
when NewArray
280280
next unless node.next_node
281281

282282
next_node = node.next_node
283-
next unless next_node.instruction.is_a?(Send)
284-
next if next_node.instruction.block_iseq
283+
next unless next_node.value.is_a?(Send)
284+
next if next_node.value.block_iseq
285285

286-
calldata = next_node.instruction.calldata
286+
calldata = next_node.value.calldata
287287
next unless calldata.flags == CallData::CALL_ARGS_SIMPLE
288288
next unless calldata.argc == 0
289289

290290
case calldata.method
291291
when :max
292-
node.instruction = OptNewArrayMax.new(node.instruction.number)
292+
node.value = OptNewArrayMax.new(value.number)
293293
node.next_node = next_node.next_node
294294
when :min
295-
node.instruction = OptNewArrayMin.new(node.instruction.number)
295+
node.value = OptNewArrayMin.new(value.number)
296296
node.next_node = next_node.next_node
297297
end
298298
when PutObject, PutString
299299
next unless node.next_node
300-
if node.instruction.is_a?(PutObject) &&
301-
!node.instruction.object.is_a?(String)
302-
next
303-
end
300+
next if value.is_a?(PutObject) && !value.object.is_a?(String)
304301

305302
next_node = node.next_node
306-
next unless next_node.instruction.is_a?(Send)
307-
next if next_node.instruction.block_iseq
303+
next unless next_node.value.is_a?(Send)
304+
next if next_node.value.block_iseq
308305

309-
calldata = next_node.instruction.calldata
306+
calldata = next_node.value.calldata
310307
next unless calldata.flags == CallData::CALL_ARGS_SIMPLE
311308
next unless calldata.argc == 0
312309

313310
case calldata.method
314311
when :freeze
315-
node.instruction =
316-
OptStrFreeze.new(node.instruction.object, calldata)
312+
node.value = OptStrFreeze.new(value.object, calldata)
317313
node.next_node = next_node.next_node
318314
when :-@
319-
node.instruction =
320-
OptStrUMinus.new(node.instruction.object, calldata)
315+
node.value = OptStrUMinus.new(value.object, calldata)
321316
node.next_node = next_node.next_node
322317
end
323318
when Send
324-
calldata = node.instruction.calldata
319+
calldata = value.calldata
325320

326-
if !node.instruction.block_iseq &&
327-
!calldata.flag?(CallData::CALL_ARGS_BLOCKARG)
321+
if !value.block_iseq && !calldata.flag?(CallData::CALL_ARGS_BLOCKARG)
328322
# Specialize the send instruction. If it doesn't have a block
329323
# attached, then we will replace it with an opt_send_without_block
330324
# and do further specializations based on the called method and
331325
# the number of arguments.
332-
node.instruction =
326+
node.value =
333327
case [calldata.method, calldata.argc]
334328
when [:length, 0]
335329
OptLength.new(calldata)

0 commit comments

Comments
 (0)