Class: SyntaxTree::YARV::OptDiv

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

Constructor Details

#initialize(calldata) ⇒ OptDiv

Returns a new instance of OptDiv.



2846
2847
2848
# File 'lib/syntax_tree/yarv/instructions.rb', line 2846

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2844
2845
2846
# File 'lib/syntax_tree/yarv/instructions.rb', line 2844

def calldata
  @calldata
end

Instance Method Details

#call(vm) ⇒ Object



2874
2875
2876
# File 'lib/syntax_tree/yarv/instructions.rb', line 2874

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

#canonicalObject



2870
2871
2872
# File 'lib/syntax_tree/yarv/instructions.rb', line 2870

def canonical
  Send.new(calldata, nil)
end

#disasm(fmt) ⇒ Object



2850
2851
2852
# File 'lib/syntax_tree/yarv/instructions.rb', line 2850

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

#lengthObject



2858
2859
2860
# File 'lib/syntax_tree/yarv/instructions.rb', line 2858

def length
  2
end

#popsObject



2862
2863
2864
# File 'lib/syntax_tree/yarv/instructions.rb', line 2862

def pops
  2
end

#pushesObject



2866
2867
2868
# File 'lib/syntax_tree/yarv/instructions.rb', line 2866

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2854
2855
2856
# File 'lib/syntax_tree/yarv/instructions.rb', line 2854

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