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.



4108
4109
4110
# File 'lib/syntax_tree/yarv/instructions.rb', line 4108

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



4106
4107
4108
# File 'lib/syntax_tree/yarv/instructions.rb', line 4106

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



4124
4125
4126
# File 'lib/syntax_tree/yarv/instructions.rb', line 4124

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

#call(vm) ⇒ Object



4144
4145
4146
# File 'lib/syntax_tree/yarv/instructions.rb', line 4144

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

#canonicalObject



4140
4141
4142
# File 'lib/syntax_tree/yarv/instructions.rb', line 4140

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



4120
4121
4122
# File 'lib/syntax_tree/yarv/instructions.rb', line 4120

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



4112
4113
4114
# File 'lib/syntax_tree/yarv/instructions.rb', line 4112

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

#lengthObject



4128
4129
4130
# File 'lib/syntax_tree/yarv/instructions.rb', line 4128

def length
  2
end

#popsObject



4132
4133
4134
# File 'lib/syntax_tree/yarv/instructions.rb', line 4132

def pops
  2
end

#pushesObject



4136
4137
4138
# File 'lib/syntax_tree/yarv/instructions.rb', line 4136

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4116
4117
4118
# File 'lib/syntax_tree/yarv/instructions.rb', line 4116

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