Class: SyntaxTree::YARV::OptPlus

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

Overview

### Summary

opt_plus 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, floats, strings, or arrays. 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) ⇒ OptPlus



3787
3788
3789
# File 'lib/syntax_tree/yarv/instructions.rb', line 3787

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3785
3786
3787
# File 'lib/syntax_tree/yarv/instructions.rb', line 3785

def calldata
  @calldata
end

Instance Method Details

#call(vm) ⇒ Object



3815
3816
3817
# File 'lib/syntax_tree/yarv/instructions.rb', line 3815

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

#canonicalObject



3811
3812
3813
# File 'lib/syntax_tree/yarv/instructions.rb', line 3811

def canonical
  Send.new(calldata, nil)
end

#disasm(fmt) ⇒ Object



3791
3792
3793
# File 'lib/syntax_tree/yarv/instructions.rb', line 3791

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

#lengthObject



3799
3800
3801
# File 'lib/syntax_tree/yarv/instructions.rb', line 3799

def length
  2
end

#popsObject



3803
3804
3805
# File 'lib/syntax_tree/yarv/instructions.rb', line 3803

def pops
  2
end

#pushesObject



3807
3808
3809
# File 'lib/syntax_tree/yarv/instructions.rb', line 3807

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3795
3796
3797
# File 'lib/syntax_tree/yarv/instructions.rb', line 3795

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