Class: SyntaxTree::YARV::OptAsetWith

Inherits:
Instruction 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

Methods inherited from Instruction

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

Constructor Details

#initialize(object, calldata) ⇒ OptAsetWith

Returns a new instance of OptAsetWith.



2840
2841
2842
2843
# File 'lib/syntax_tree/yarv/instructions.rb', line 2840

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

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



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

def calldata
  @calldata
end

#objectObject (readonly)

Returns the value of attribute object.



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

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



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

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

#call(vm) ⇒ Object



2877
2878
2879
2880
# File 'lib/syntax_tree/yarv/instructions.rb', line 2877

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

#deconstruct_keys(_keys) ⇒ Object



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

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

#disasm(fmt) ⇒ Object



2845
2846
2847
2848
2849
2850
# File 'lib/syntax_tree/yarv/instructions.rb', line 2845

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

#lengthObject



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

def length
  3
end

#popsObject



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

def pops
  2
end

#pushesObject



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

def pushes
  1
end

#to_a(_iseq) ⇒ Object



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

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