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.



2671
2672
2673
# File 'lib/syntax_tree/yarv/instructions.rb', line 2671

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2669
2670
2671
# File 'lib/syntax_tree/yarv/instructions.rb', line 2669

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



2687
2688
2689
# File 'lib/syntax_tree/yarv/instructions.rb', line 2687

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

#call(vm) ⇒ Object



2707
2708
2709
# File 'lib/syntax_tree/yarv/instructions.rb', line 2707

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

#canonicalObject



2703
2704
2705
# File 'lib/syntax_tree/yarv/instructions.rb', line 2703

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



2683
2684
2685
# File 'lib/syntax_tree/yarv/instructions.rb', line 2683

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



2675
2676
2677
# File 'lib/syntax_tree/yarv/instructions.rb', line 2675

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

#lengthObject



2691
2692
2693
# File 'lib/syntax_tree/yarv/instructions.rb', line 2691

def length
  2
end

#popsObject



2695
2696
2697
# File 'lib/syntax_tree/yarv/instructions.rb', line 2695

def pops
  2
end

#pushesObject



2699
2700
2701
# File 'lib/syntax_tree/yarv/instructions.rb', line 2699

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2679
2680
2681
# File 'lib/syntax_tree/yarv/instructions.rb', line 2679

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