Class: SyntaxTree::YARV::OptMinus

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

Methods inherited from Instruction

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

Constructor Details

#initialize(calldata) ⇒ OptMinus

Returns a new instance of OptMinus.



3603
3604
3605
# File 'lib/syntax_tree/yarv/instructions.rb', line 3603

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3601
3602
3603
# File 'lib/syntax_tree/yarv/instructions.rb', line 3601

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3619
3620
3621
# File 'lib/syntax_tree/yarv/instructions.rb', line 3619

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

#call(vm) ⇒ Object



3639
3640
3641
# File 'lib/syntax_tree/yarv/instructions.rb', line 3639

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

#canonicalObject



3635
3636
3637
# File 'lib/syntax_tree/yarv/instructions.rb', line 3635

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3615
3616
3617
# File 'lib/syntax_tree/yarv/instructions.rb', line 3615

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3607
3608
3609
# File 'lib/syntax_tree/yarv/instructions.rb', line 3607

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

#lengthObject



3623
3624
3625
# File 'lib/syntax_tree/yarv/instructions.rb', line 3623

def length
  2
end

#popsObject



3627
3628
3629
# File 'lib/syntax_tree/yarv/instructions.rb', line 3627

def pops
  2
end

#pushesObject



3631
3632
3633
# File 'lib/syntax_tree/yarv/instructions.rb', line 3631

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3611
3612
3613
# File 'lib/syntax_tree/yarv/instructions.rb', line 3611

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