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.



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

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

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2782
2783
2784
# File 'lib/syntax_tree/yarv/instructions.rb', line 2782

def calldata
  @calldata
end

#objectObject (readonly)

Returns the value of attribute object.



2782
2783
2784
# File 'lib/syntax_tree/yarv/instructions.rb', line 2782

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



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

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

#call(vm) ⇒ Object



2821
2822
2823
# File 'lib/syntax_tree/yarv/instructions.rb', line 2821

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

#deconstruct_keys(_keys) ⇒ Object



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

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

#disasm(fmt) ⇒ Object



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

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

#lengthObject



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

def length
  3
end

#popsObject



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

def pops
  1
end

#pushesObject



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

def pushes
  1
end

#to_a(_iseq) ⇒ Object



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

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