Class: SyntaxTree::YARV::OptArefWith

Inherits:
Object
  • Object
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

Constructor Details

#initialize(object, calldata) ⇒ OptArefWith



2624
2625
2626
2627
# File 'lib/syntax_tree/yarv/instructions.rb', line 2624

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

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2622
2623
2624
# File 'lib/syntax_tree/yarv/instructions.rb', line 2622

def calldata
  @calldata
end

#objectObject (readonly)

Returns the value of attribute object.



2622
2623
2624
# File 'lib/syntax_tree/yarv/instructions.rb', line 2622

def object
  @object
end

Instance Method Details

#call(vm) ⇒ Object



2656
2657
2658
# File 'lib/syntax_tree/yarv/instructions.rb', line 2656

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

#canonicalObject



2652
2653
2654
# File 'lib/syntax_tree/yarv/instructions.rb', line 2652

def canonical
  self
end

#disasm(fmt) ⇒ Object



2629
2630
2631
2632
2633
2634
# File 'lib/syntax_tree/yarv/instructions.rb', line 2629

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

#lengthObject



2640
2641
2642
# File 'lib/syntax_tree/yarv/instructions.rb', line 2640

def length
  3
end

#popsObject



2644
2645
2646
# File 'lib/syntax_tree/yarv/instructions.rb', line 2644

def pops
  1
end

#pushesObject



2648
2649
2650
# File 'lib/syntax_tree/yarv/instructions.rb', line 2648

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2636
2637
2638
# File 'lib/syntax_tree/yarv/instructions.rb', line 2636

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