Class: SyntaxTree::YARV::OptOr

Inherits:
Instruction 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

Methods inherited from Instruction

#branch_targets, #falls_through?, #leaves?, #side_effects?

Constructor Details

#initialize(calldata) ⇒ OptOr

Returns a new instance of OptOr.



4005
4006
4007
# File 'lib/syntax_tree/yarv/instructions.rb', line 4005

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



4003
4004
4005
# File 'lib/syntax_tree/yarv/instructions.rb', line 4003

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



4021
4022
4023
# File 'lib/syntax_tree/yarv/instructions.rb', line 4021

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

#call(vm) ⇒ Object



4041
4042
4043
# File 'lib/syntax_tree/yarv/instructions.rb', line 4041

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

#canonicalObject



4037
4038
4039
# File 'lib/syntax_tree/yarv/instructions.rb', line 4037

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



4017
4018
4019
# File 'lib/syntax_tree/yarv/instructions.rb', line 4017

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



4009
4010
4011
# File 'lib/syntax_tree/yarv/instructions.rb', line 4009

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

#lengthObject



4025
4026
4027
# File 'lib/syntax_tree/yarv/instructions.rb', line 4025

def length
  2
end

#popsObject



4029
4030
4031
# File 'lib/syntax_tree/yarv/instructions.rb', line 4029

def pops
  2
end

#pushesObject



4033
4034
4035
# File 'lib/syntax_tree/yarv/instructions.rb', line 4033

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4013
4014
4015
# File 'lib/syntax_tree/yarv/instructions.rb', line 4013

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