Class: SyntaxTree::YARV::OptPlus

Inherits:
Instruction 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

Methods inherited from Instruction

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

Constructor Details

#initialize(calldata) ⇒ OptPlus

Returns a new instance of OptPlus.



4050
4051
4052
# File 'lib/syntax_tree/yarv/instructions.rb', line 4050

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



4048
4049
4050
# File 'lib/syntax_tree/yarv/instructions.rb', line 4048

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



4066
4067
4068
# File 'lib/syntax_tree/yarv/instructions.rb', line 4066

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

#call(vm) ⇒ Object



4086
4087
4088
# File 'lib/syntax_tree/yarv/instructions.rb', line 4086

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

#canonicalObject



4082
4083
4084
# File 'lib/syntax_tree/yarv/instructions.rb', line 4082

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



4062
4063
4064
# File 'lib/syntax_tree/yarv/instructions.rb', line 4062

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



4054
4055
4056
# File 'lib/syntax_tree/yarv/instructions.rb', line 4054

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

#lengthObject



4070
4071
4072
# File 'lib/syntax_tree/yarv/instructions.rb', line 4070

def length
  2
end

#popsObject



4074
4075
4076
# File 'lib/syntax_tree/yarv/instructions.rb', line 4074

def pops
  2
end

#pushesObject



4078
4079
4080
# File 'lib/syntax_tree/yarv/instructions.rb', line 4078

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4058
4059
4060
# File 'lib/syntax_tree/yarv/instructions.rb', line 4058

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