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



4332
4333
4334
# File 'lib/syntax_tree/yarv/instructions.rb', line 4332

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



4330
4331
4332
# File 'lib/syntax_tree/yarv/instructions.rb', line 4330

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



4348
4349
4350
# File 'lib/syntax_tree/yarv/instructions.rb', line 4348

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

#call(vm) ⇒ Object



4368
4369
4370
# File 'lib/syntax_tree/yarv/instructions.rb', line 4368

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

#canonicalObject



4364
4365
4366
# File 'lib/syntax_tree/yarv/instructions.rb', line 4364

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



4344
4345
4346
# File 'lib/syntax_tree/yarv/instructions.rb', line 4344

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



4336
4337
4338
# File 'lib/syntax_tree/yarv/instructions.rb', line 4336

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

#lengthObject



4352
4353
4354
# File 'lib/syntax_tree/yarv/instructions.rb', line 4352

def length
  2
end

#popsObject



4356
4357
4358
# File 'lib/syntax_tree/yarv/instructions.rb', line 4356

def pops
  2
end

#pushesObject



4360
4361
4362
# File 'lib/syntax_tree/yarv/instructions.rb', line 4360

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4340
4341
4342
# File 'lib/syntax_tree/yarv/instructions.rb', line 4340

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