Class: SyntaxTree::YARV::OptMult

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

Overview

### Summary

opt_mult 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 or floats. It pops both the receiver and the argument off the stack and pushes on the result.

### Usage

~~~ruby 3 * 2 ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calldata) ⇒ OptMult

Returns a new instance of OptMult.



3441
3442
3443
# File 'lib/syntax_tree/yarv/instructions.rb', line 3441

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3439
3440
3441
# File 'lib/syntax_tree/yarv/instructions.rb', line 3439

def calldata
  @calldata
end

Instance Method Details

#call(vm) ⇒ Object



3469
3470
3471
# File 'lib/syntax_tree/yarv/instructions.rb', line 3469

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

#canonicalObject



3465
3466
3467
# File 'lib/syntax_tree/yarv/instructions.rb', line 3465

def canonical
  Send.new(calldata, nil)
end

#disasm(fmt) ⇒ Object



3445
3446
3447
# File 'lib/syntax_tree/yarv/instructions.rb', line 3445

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

#lengthObject



3453
3454
3455
# File 'lib/syntax_tree/yarv/instructions.rb', line 3453

def length
  2
end

#popsObject



3457
3458
3459
# File 'lib/syntax_tree/yarv/instructions.rb', line 3457

def pops
  2
end

#pushesObject



3461
3462
3463
# File 'lib/syntax_tree/yarv/instructions.rb', line 3461

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3449
3450
3451
# File 'lib/syntax_tree/yarv/instructions.rb', line 3449

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