Class: SyntaxTree::YARV::OptDiv

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

Overview

### Summary

‘opt_div` 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 2 / 3 ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(calldata) ⇒ OptDiv

Returns a new instance of OptDiv.



3034
3035
3036
# File 'lib/syntax_tree/yarv/instructions.rb', line 3034

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3032
3033
3034
# File 'lib/syntax_tree/yarv/instructions.rb', line 3032

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3050
3051
3052
# File 'lib/syntax_tree/yarv/instructions.rb', line 3050

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

#call(vm) ⇒ Object



3070
3071
3072
# File 'lib/syntax_tree/yarv/instructions.rb', line 3070

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

#canonicalObject



3066
3067
3068
# File 'lib/syntax_tree/yarv/instructions.rb', line 3066

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3046
3047
3048
# File 'lib/syntax_tree/yarv/instructions.rb', line 3046

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3038
3039
3040
# File 'lib/syntax_tree/yarv/instructions.rb', line 3038

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

#lengthObject



3054
3055
3056
# File 'lib/syntax_tree/yarv/instructions.rb', line 3054

def length
  2
end

#popsObject



3058
3059
3060
# File 'lib/syntax_tree/yarv/instructions.rb', line 3058

def pops
  2
end

#pushesObject



3062
3063
3064
# File 'lib/syntax_tree/yarv/instructions.rb', line 3062

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3042
3043
3044
# File 'lib/syntax_tree/yarv/instructions.rb', line 3042

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