Class: SyntaxTree::YARV::OptPlus
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.
4115
4116
4117
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 4115
def initialize(calldata)
@calldata = calldata
end
|
Instance Attribute Details
#calldata ⇒ Object
Returns the value of attribute calldata.
4113
4114
4115
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 4113
def calldata
@calldata
end
|
Instance Method Details
#==(other) ⇒ Object
4131
4132
4133
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 4131
def ==(other)
other.is_a?(OptPlus) && other.calldata == calldata
end
|
#call(vm) ⇒ Object
4151
4152
4153
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 4151
def call(vm)
canonical.call(vm)
end
|
#canonical ⇒ Object
4147
4148
4149
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 4147
def canonical
Send.new(calldata, nil)
end
|
#deconstruct_keys(_keys) ⇒ Object
4127
4128
4129
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 4127
def deconstruct_keys(_keys)
{ calldata: calldata }
end
|
#disasm(fmt) ⇒ Object
4119
4120
4121
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 4119
def disasm(fmt)
fmt.instruction("opt_plus", [fmt.calldata(calldata)])
end
|
#length ⇒ Object
4135
4136
4137
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 4135
def length
2
end
|
#pops ⇒ Object
4139
4140
4141
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 4139
def pops
2
end
|
#pushes ⇒ Object
4143
4144
4145
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 4143
def pushes
1
end
|
#to_a(_iseq) ⇒ Object
4123
4124
4125
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 4123
def to_a(_iseq)
[:opt_plus, calldata.to_h]
end
|