Class: SyntaxTree::YARV::OptMod

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

Overview

### Summary

opt_mod 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 if both operands are floats. It pops both the receiver and the argument off the stack and pushes on the result.

### Usage

~~~ruby 4 % 2 ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calldata) ⇒ OptMod

Returns a new instance of OptMod.



3392
3393
3394
# File 'lib/syntax_tree/yarv/instructions.rb', line 3392

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3390
3391
3392
# File 'lib/syntax_tree/yarv/instructions.rb', line 3390

def calldata
  @calldata
end

Instance Method Details

#call(vm) ⇒ Object



3420
3421
3422
# File 'lib/syntax_tree/yarv/instructions.rb', line 3420

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

#canonicalObject



3416
3417
3418
# File 'lib/syntax_tree/yarv/instructions.rb', line 3416

def canonical
  Send.new(calldata, nil)
end

#disasm(fmt) ⇒ Object



3396
3397
3398
# File 'lib/syntax_tree/yarv/instructions.rb', line 3396

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

#lengthObject



3404
3405
3406
# File 'lib/syntax_tree/yarv/instructions.rb', line 3404

def length
  2
end

#popsObject



3408
3409
3410
# File 'lib/syntax_tree/yarv/instructions.rb', line 3408

def pops
  2
end

#pushesObject



3412
3413
3414
# File 'lib/syntax_tree/yarv/instructions.rb', line 3412

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3400
3401
3402
# File 'lib/syntax_tree/yarv/instructions.rb', line 3400

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