Class: SyntaxTree::YARV::OptArefWith

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

Overview

### Summary

‘opt_aref_with` is a specialization of the `opt_aref` instruction that occurs when the `[]` operator is used with a string argument known at compile time. There are fast paths if the receiver is a hash. It pops the receiver off the stack and pushes on the result.

### Usage

~~~ruby ‘test’ => true ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(object, calldata) ⇒ OptArefWith

Returns a new instance of OptArefWith.



2837
2838
2839
2840
# File 'lib/syntax_tree/yarv/instructions.rb', line 2837

def initialize(object, calldata)
  @object = object
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2835
2836
2837
# File 'lib/syntax_tree/yarv/instructions.rb', line 2835

def calldata
  @calldata
end

#objectObject (readonly)

Returns the value of attribute object.



2835
2836
2837
# File 'lib/syntax_tree/yarv/instructions.rb', line 2835

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



2857
2858
2859
2860
# File 'lib/syntax_tree/yarv/instructions.rb', line 2857

def ==(other)
  other.is_a?(OptArefWith) && other.object == object &&
    other.calldata == calldata
end

#call(vm) ⇒ Object



2874
2875
2876
# File 'lib/syntax_tree/yarv/instructions.rb', line 2874

def call(vm)
  vm.push(vm.pop[object])
end

#deconstruct_keys(_keys) ⇒ Object



2853
2854
2855
# File 'lib/syntax_tree/yarv/instructions.rb', line 2853

def deconstruct_keys(_keys)
  { object: object, calldata: calldata }
end

#disasm(fmt) ⇒ Object



2842
2843
2844
2845
2846
2847
# File 'lib/syntax_tree/yarv/instructions.rb', line 2842

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

#lengthObject



2862
2863
2864
# File 'lib/syntax_tree/yarv/instructions.rb', line 2862

def length
  3
end

#popsObject



2866
2867
2868
# File 'lib/syntax_tree/yarv/instructions.rb', line 2866

def pops
  1
end

#pushesObject



2870
2871
2872
# File 'lib/syntax_tree/yarv/instructions.rb', line 2870

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2849
2850
2851
# File 'lib/syntax_tree/yarv/instructions.rb', line 2849

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