Class: SyntaxTree::YARV::OptAref

Inherits:
Instruction show all
Defined in:
lib/syntax_tree/yarv/instructions.rb

Overview

### Summary

‘opt_aref` is a specialization of the `opt_send_without_block` instruction that occurs when the `[]` operator is used. There are fast paths if the receiver is an integer, array, or hash.

### Usage

~~~ruby 7 ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

#branch_targets, #falls_through?, #leaves?, #side_effects?

Constructor Details

#initialize(calldata) ⇒ OptAref

Returns a new instance of OptAref.



2780
2781
2782
# File 'lib/syntax_tree/yarv/instructions.rb', line 2780

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2778
2779
2780
# File 'lib/syntax_tree/yarv/instructions.rb', line 2778

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



2796
2797
2798
# File 'lib/syntax_tree/yarv/instructions.rb', line 2796

def ==(other)
  other.is_a?(OptAref) && other.calldata == calldata
end

#call(vm) ⇒ Object



2816
2817
2818
# File 'lib/syntax_tree/yarv/instructions.rb', line 2816

def call(vm)
  canonical.call(vm)
end

#canonicalObject



2812
2813
2814
# File 'lib/syntax_tree/yarv/instructions.rb', line 2812

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



2792
2793
2794
# File 'lib/syntax_tree/yarv/instructions.rb', line 2792

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



2784
2785
2786
# File 'lib/syntax_tree/yarv/instructions.rb', line 2784

def disasm(fmt)
  fmt.instruction("opt_aref", [fmt.calldata(calldata)])
end

#lengthObject



2800
2801
2802
# File 'lib/syntax_tree/yarv/instructions.rb', line 2800

def length
  2
end

#popsObject



2804
2805
2806
# File 'lib/syntax_tree/yarv/instructions.rb', line 2804

def pops
  2
end

#pushesObject



2808
2809
2810
# File 'lib/syntax_tree/yarv/instructions.rb', line 2808

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2788
2789
2790
# File 'lib/syntax_tree/yarv/instructions.rb', line 2788

def to_a(_iseq)
  [:opt_aref, calldata.to_h]
end