Class: Optimize::IR::Instruction

Inherits:
Struct
  • Object
show all
Defined in:
lib/optimize/ir/instruction.rb

Overview

One YARV instruction after decoding. Operands are Ruby values, not object-table indices — the codec resolves indices on decode and re-interns them on encode.

Fields:

opcode   - Symbol, e.g. :putobject, :leave
operands - Array of decoded operand values. For TS_VALUE/TS_ID operands,
           these are object-table indices (not resolved Ruby objects) to
           enable byte-identical round-trip. For TS_ISEQ, the iseq-list
           index. For TS_CALLDATA, no entry is stored. For TS_OFFSET,
           the raw slot-count offset. For TS_LINDEX/TS_NUM/TS_ISE/etc.,
           the raw index/count.
line     - Integer source line number (from insns_info; nil if absent)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



18
19
20
# File 'lib/optimize/ir/instruction.rb', line 18

def line
  @line
end

#opcodeObject

Returns the value of attribute opcode

Returns:

  • (Object)

    the current value of opcode



18
19
20
# File 'lib/optimize/ir/instruction.rb', line 18

def opcode
  @opcode
end

#operandsObject

Returns the value of attribute operands

Returns:

  • (Object)

    the current value of operands



18
19
20
# File 'lib/optimize/ir/instruction.rb', line 18

def operands
  @operands
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/optimize/ir/instruction.rb', line 32

def eql?(other)
  equal?(other)
end

#hashObject

Use object identity for Hash keys and Set membership. IR instructions must be compared by identity (not by value) because the same logical opcode+operands combination can appear at multiple positions in a single iseq. Value-based equality would cause Hash collisions and incorrect slot lookups in inst_to_slot_map / catch_table / line_info.



28
29
30
# File 'lib/optimize/ir/instruction.rb', line 28

def hash
  object_id.hash
end

#to_sObject



19
20
21
# File 'lib/optimize/ir/instruction.rb', line 19

def to_s
  "#{opcode} #{operands.inspect}"
end