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.



3087
3088
3089
# File 'lib/syntax_tree/yarv/instructions.rb', line 3087

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3085
3086
3087
# File 'lib/syntax_tree/yarv/instructions.rb', line 3085

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3103
3104
3105
# File 'lib/syntax_tree/yarv/instructions.rb', line 3103

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

#call(vm) ⇒ Object



3123
3124
3125
# File 'lib/syntax_tree/yarv/instructions.rb', line 3123

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

#canonicalObject



3119
3120
3121
# File 'lib/syntax_tree/yarv/instructions.rb', line 3119

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3099
3100
3101
# File 'lib/syntax_tree/yarv/instructions.rb', line 3099

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3091
3092
3093
# File 'lib/syntax_tree/yarv/instructions.rb', line 3091

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

#lengthObject



3107
3108
3109
# File 'lib/syntax_tree/yarv/instructions.rb', line 3107

def length
  2
end

#popsObject



3111
3112
3113
# File 'lib/syntax_tree/yarv/instructions.rb', line 3111

def pops
  2
end

#pushesObject



3115
3116
3117
# File 'lib/syntax_tree/yarv/instructions.rb', line 3115

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3095
3096
3097
# File 'lib/syntax_tree/yarv/instructions.rb', line 3095

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