Class: SyntaxTree::YARV::OptMult

Inherits:
Object
  • Object
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

Constructor Details

#initialize(calldata) ⇒ OptMult

Returns a new instance of OptMult.



3929
3930
3931
# File 'lib/syntax_tree/yarv/instructions.rb', line 3929

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3927
3928
3929
# File 'lib/syntax_tree/yarv/instructions.rb', line 3927

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3945
3946
3947
# File 'lib/syntax_tree/yarv/instructions.rb', line 3945

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

#call(vm) ⇒ Object



3965
3966
3967
# File 'lib/syntax_tree/yarv/instructions.rb', line 3965

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

#canonicalObject



3961
3962
3963
# File 'lib/syntax_tree/yarv/instructions.rb', line 3961

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3941
3942
3943
# File 'lib/syntax_tree/yarv/instructions.rb', line 3941

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3933
3934
3935
# File 'lib/syntax_tree/yarv/instructions.rb', line 3933

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

#lengthObject



3949
3950
3951
# File 'lib/syntax_tree/yarv/instructions.rb', line 3949

def length
  2
end

#popsObject



3953
3954
3955
# File 'lib/syntax_tree/yarv/instructions.rb', line 3953

def pops
  2
end

#pushesObject



3957
3958
3959
# File 'lib/syntax_tree/yarv/instructions.rb', line 3957

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3937
3938
3939
# File 'lib/syntax_tree/yarv/instructions.rb', line 3937

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