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.



2613
2614
2615
# File 'lib/syntax_tree/yarv/instructions.rb', line 2613

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2611
2612
2613
# File 'lib/syntax_tree/yarv/instructions.rb', line 2611

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



2629
2630
2631
# File 'lib/syntax_tree/yarv/instructions.rb', line 2629

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

#call(vm) ⇒ Object



2649
2650
2651
# File 'lib/syntax_tree/yarv/instructions.rb', line 2649

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

#canonicalObject



2645
2646
2647
# File 'lib/syntax_tree/yarv/instructions.rb', line 2645

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



2625
2626
2627
# File 'lib/syntax_tree/yarv/instructions.rb', line 2625

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



2617
2618
2619
# File 'lib/syntax_tree/yarv/instructions.rb', line 2617

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

#lengthObject



2633
2634
2635
# File 'lib/syntax_tree/yarv/instructions.rb', line 2633

def length
  2
end

#popsObject



2637
2638
2639
# File 'lib/syntax_tree/yarv/instructions.rb', line 2637

def pops
  2
end

#pushesObject



2641
2642
2643
# File 'lib/syntax_tree/yarv/instructions.rb', line 2641

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2621
2622
2623
# File 'lib/syntax_tree/yarv/instructions.rb', line 2621

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