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.



3713
3714
3715
# File 'lib/syntax_tree/yarv/instructions.rb', line 3713

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3711
3712
3713
# File 'lib/syntax_tree/yarv/instructions.rb', line 3711

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3729
3730
3731
# File 'lib/syntax_tree/yarv/instructions.rb', line 3729

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

#call(vm) ⇒ Object



3749
3750
3751
# File 'lib/syntax_tree/yarv/instructions.rb', line 3749

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

#canonicalObject



3745
3746
3747
# File 'lib/syntax_tree/yarv/instructions.rb', line 3745

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3725
3726
3727
# File 'lib/syntax_tree/yarv/instructions.rb', line 3725

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3717
3718
3719
# File 'lib/syntax_tree/yarv/instructions.rb', line 3717

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

#lengthObject



3733
3734
3735
# File 'lib/syntax_tree/yarv/instructions.rb', line 3733

def length
  2
end

#popsObject



3737
3738
3739
# File 'lib/syntax_tree/yarv/instructions.rb', line 3737

def pops
  2
end

#pushesObject



3741
3742
3743
# File 'lib/syntax_tree/yarv/instructions.rb', line 3741

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3721
3722
3723
# File 'lib/syntax_tree/yarv/instructions.rb', line 3721

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