Class: SyntaxTree::YARV::OptMod

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

Overview

### Summary

‘opt_mod` 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 4 % 2 ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(calldata) ⇒ OptMod

Returns a new instance of OptMod.



3660
3661
3662
# File 'lib/syntax_tree/yarv/instructions.rb', line 3660

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3658
3659
3660
# File 'lib/syntax_tree/yarv/instructions.rb', line 3658

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3676
3677
3678
# File 'lib/syntax_tree/yarv/instructions.rb', line 3676

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

#call(vm) ⇒ Object



3696
3697
3698
# File 'lib/syntax_tree/yarv/instructions.rb', line 3696

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

#canonicalObject



3692
3693
3694
# File 'lib/syntax_tree/yarv/instructions.rb', line 3692

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3672
3673
3674
# File 'lib/syntax_tree/yarv/instructions.rb', line 3672

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3664
3665
3666
# File 'lib/syntax_tree/yarv/instructions.rb', line 3664

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

#lengthObject



3680
3681
3682
# File 'lib/syntax_tree/yarv/instructions.rb', line 3680

def length
  2
end

#popsObject



3684
3685
3686
# File 'lib/syntax_tree/yarv/instructions.rb', line 3684

def pops
  2
end

#pushesObject



3688
3689
3690
# File 'lib/syntax_tree/yarv/instructions.rb', line 3688

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3668
3669
3670
# File 'lib/syntax_tree/yarv/instructions.rb', line 3668

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