Class: SyntaxTree::YARV::OptAnd

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

Overview

### Summary

‘opt_and` 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) ⇒ OptAnd

Returns a new instance of OptAnd.



2724
2725
2726
# File 'lib/syntax_tree/yarv/instructions.rb', line 2724

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2722
2723
2724
# File 'lib/syntax_tree/yarv/instructions.rb', line 2722

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



2740
2741
2742
# File 'lib/syntax_tree/yarv/instructions.rb', line 2740

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

#call(vm) ⇒ Object



2760
2761
2762
# File 'lib/syntax_tree/yarv/instructions.rb', line 2760

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

#canonicalObject



2756
2757
2758
# File 'lib/syntax_tree/yarv/instructions.rb', line 2756

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



2736
2737
2738
# File 'lib/syntax_tree/yarv/instructions.rb', line 2736

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



2728
2729
2730
# File 'lib/syntax_tree/yarv/instructions.rb', line 2728

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

#lengthObject



2744
2745
2746
# File 'lib/syntax_tree/yarv/instructions.rb', line 2744

def length
  2
end

#popsObject



2748
2749
2750
# File 'lib/syntax_tree/yarv/instructions.rb', line 2748

def pops
  2
end

#pushesObject



2752
2753
2754
# File 'lib/syntax_tree/yarv/instructions.rb', line 2752

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2732
2733
2734
# File 'lib/syntax_tree/yarv/instructions.rb', line 2732

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