Class: SyntaxTree::YARV::OptAsetWith

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

Overview

### Summary

opt_aset_with is an instruction for setting the hash value by the known string key in the ‘recv = set` format. It pops the receiver and the value off the stack and pushes on the result.

### Usage

~~~ruby = value ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, calldata) ⇒ OptAsetWith

Returns a new instance of OptAsetWith.



2725
2726
2727
2728
# File 'lib/syntax_tree/yarv/instructions.rb', line 2725

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

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2723
2724
2725
# File 'lib/syntax_tree/yarv/instructions.rb', line 2723

def calldata
  @calldata
end

#objectObject (readonly)

Returns the value of attribute object.



2723
2724
2725
# File 'lib/syntax_tree/yarv/instructions.rb', line 2723

def object
  @object
end

Instance Method Details

#call(vm) ⇒ Object



2757
2758
2759
2760
# File 'lib/syntax_tree/yarv/instructions.rb', line 2757

def call(vm)
  hash, value = vm.pop(2)
  vm.push(hash[object] = value)
end

#canonicalObject



2753
2754
2755
# File 'lib/syntax_tree/yarv/instructions.rb', line 2753

def canonical
  self
end

#disasm(fmt) ⇒ Object



2730
2731
2732
2733
2734
2735
# File 'lib/syntax_tree/yarv/instructions.rb', line 2730

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

#lengthObject



2741
2742
2743
# File 'lib/syntax_tree/yarv/instructions.rb', line 2741

def length
  3
end

#popsObject



2745
2746
2747
# File 'lib/syntax_tree/yarv/instructions.rb', line 2745

def pops
  2
end

#pushesObject



2749
2750
2751
# File 'lib/syntax_tree/yarv/instructions.rb', line 2749

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2737
2738
2739
# File 'lib/syntax_tree/yarv/instructions.rb', line 2737

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