Class: SyntaxTree::YARV::OptMult

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

Overview

### Summary

‘opt_mult` 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 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) ⇒ OptMult

Returns a new instance of OptMult.



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

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3715
3716
3717
# File 'lib/syntax_tree/yarv/instructions.rb', line 3715

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



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

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

#call(vm) ⇒ Object



3753
3754
3755
# File 'lib/syntax_tree/yarv/instructions.rb', line 3753

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

#canonicalObject



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

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



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

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



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

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

#lengthObject



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

def length
  2
end

#popsObject



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

def pops
  2
end

#pushesObject



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

def pushes
  1
end

#to_a(_iseq) ⇒ Object



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

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