Class: SyntaxTree::YARV::OptMinus

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

Overview

### Summary

opt_minus is a specialization of the opt_send_without_block instruction that occurs when the - operator is used. There are fast paths for if both operands are integers or if both operands are floats. It pops both the receiver and the argument off the stack and pushes on the result.

### Usage

~~~ruby 3 - 2 ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calldata) ⇒ OptMinus

Returns a new instance of OptMinus.



3815
3816
3817
# File 'lib/syntax_tree/yarv/instructions.rb', line 3815

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3813
3814
3815
# File 'lib/syntax_tree/yarv/instructions.rb', line 3813

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3831
3832
3833
# File 'lib/syntax_tree/yarv/instructions.rb', line 3831

def ==(other)
  other.is_a?(OptMinus) && other.calldata == calldata
end

#call(vm) ⇒ Object



3851
3852
3853
# File 'lib/syntax_tree/yarv/instructions.rb', line 3851

def call(vm)
  canonical.call(vm)
end

#canonicalObject



3847
3848
3849
# File 'lib/syntax_tree/yarv/instructions.rb', line 3847

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3827
3828
3829
# File 'lib/syntax_tree/yarv/instructions.rb', line 3827

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3819
3820
3821
# File 'lib/syntax_tree/yarv/instructions.rb', line 3819

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

#lengthObject



3835
3836
3837
# File 'lib/syntax_tree/yarv/instructions.rb', line 3835

def length
  2
end

#popsObject



3839
3840
3841
# File 'lib/syntax_tree/yarv/instructions.rb', line 3839

def pops
  2
end

#pushesObject



3843
3844
3845
# File 'lib/syntax_tree/yarv/instructions.rb', line 3843

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3823
3824
3825
# File 'lib/syntax_tree/yarv/instructions.rb', line 3823

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