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



2980
2981
2982
2983
# File 'lib/syntax_tree/yarv/instructions.rb', line 2980

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

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2978
2979
2980
# File 'lib/syntax_tree/yarv/instructions.rb', line 2978

def calldata
  @calldata
end

#objectObject (readonly)

Returns the value of attribute object.



2978
2979
2980
# File 'lib/syntax_tree/yarv/instructions.rb', line 2978

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



3000
3001
3002
3003
# File 'lib/syntax_tree/yarv/instructions.rb', line 3000

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

#call(vm) ⇒ Object



3021
3022
3023
# File 'lib/syntax_tree/yarv/instructions.rb', line 3021

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

#canonicalObject



3017
3018
3019
# File 'lib/syntax_tree/yarv/instructions.rb', line 3017

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



2996
2997
2998
# File 'lib/syntax_tree/yarv/instructions.rb', line 2996

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

#disasm(fmt) ⇒ Object



2985
2986
2987
2988
2989
2990
# File 'lib/syntax_tree/yarv/instructions.rb', line 2985

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

#lengthObject



3005
3006
3007
# File 'lib/syntax_tree/yarv/instructions.rb', line 3005

def length
  3
end

#popsObject



3009
3010
3011
# File 'lib/syntax_tree/yarv/instructions.rb', line 3009

def pops
  1
end

#pushesObject



3013
3014
3015
# File 'lib/syntax_tree/yarv/instructions.rb', line 3013

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2992
2993
2994
# File 'lib/syntax_tree/yarv/instructions.rb', line 2992

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