Class: SyntaxTree::YARV::OptOr

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

Overview

### Summary

opt_or is a specialization of the opt_send_without_block instruction that occurs when the ‘|` operator is used. There is a fast path for if both operands are integers. 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) ⇒ OptOr

Returns a new instance of OptOr.



3738
3739
3740
# File 'lib/syntax_tree/yarv/instructions.rb', line 3738

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3736
3737
3738
# File 'lib/syntax_tree/yarv/instructions.rb', line 3736

def calldata
  @calldata
end

Instance Method Details

#call(vm) ⇒ Object



3766
3767
3768
# File 'lib/syntax_tree/yarv/instructions.rb', line 3766

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

#canonicalObject



3762
3763
3764
# File 'lib/syntax_tree/yarv/instructions.rb', line 3762

def canonical
  Send.new(calldata, nil)
end

#disasm(fmt) ⇒ Object



3742
3743
3744
# File 'lib/syntax_tree/yarv/instructions.rb', line 3742

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

#lengthObject



3750
3751
3752
# File 'lib/syntax_tree/yarv/instructions.rb', line 3750

def length
  2
end

#popsObject



3754
3755
3756
# File 'lib/syntax_tree/yarv/instructions.rb', line 3754

def pops
  2
end

#pushesObject



3758
3759
3760
# File 'lib/syntax_tree/yarv/instructions.rb', line 3758

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3746
3747
3748
# File 'lib/syntax_tree/yarv/instructions.rb', line 3746

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