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



3872
3873
3874
# File 'lib/syntax_tree/yarv/instructions.rb', line 3872

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3870
3871
3872
# File 'lib/syntax_tree/yarv/instructions.rb', line 3870

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3888
3889
3890
# File 'lib/syntax_tree/yarv/instructions.rb', line 3888

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

#call(vm) ⇒ Object



3908
3909
3910
# File 'lib/syntax_tree/yarv/instructions.rb', line 3908

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

#canonicalObject



3904
3905
3906
# File 'lib/syntax_tree/yarv/instructions.rb', line 3904

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3884
3885
3886
# File 'lib/syntax_tree/yarv/instructions.rb', line 3884

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3876
3877
3878
# File 'lib/syntax_tree/yarv/instructions.rb', line 3876

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

#lengthObject



3892
3893
3894
# File 'lib/syntax_tree/yarv/instructions.rb', line 3892

def length
  2
end

#popsObject



3896
3897
3898
# File 'lib/syntax_tree/yarv/instructions.rb', line 3896

def pops
  2
end

#pushesObject



3900
3901
3902
# File 'lib/syntax_tree/yarv/instructions.rb', line 3900

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3880
3881
3882
# File 'lib/syntax_tree/yarv/instructions.rb', line 3880

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