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.



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

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



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

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



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

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

#call(vm) ⇒ Object



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

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

#canonicalObject



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

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



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

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



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

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

#lengthObject



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

def length
  2
end

#popsObject



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

def pops
  2
end

#pushesObject



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

def pushes
  1
end

#to_a(_iseq) ⇒ Object



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

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