Class: SyntaxTree::YARV::OptEq

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

Overview

### Summary

opt_eq is a specialization of the opt_send_without_block instruction that occurs when the == operator is used. Fast paths exist when both operands are integers, floats, symbols or strings. It pops both the receiver and the argument off the stack and pushes on the result.

### Usage

~~~ruby 2 == 2 ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calldata) ⇒ OptEq



2943
2944
2945
# File 'lib/syntax_tree/yarv/instructions.rb', line 2943

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2941
2942
2943
# File 'lib/syntax_tree/yarv/instructions.rb', line 2941

def calldata
  @calldata
end

Instance Method Details

#call(vm) ⇒ Object



2971
2972
2973
# File 'lib/syntax_tree/yarv/instructions.rb', line 2971

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

#canonicalObject



2967
2968
2969
# File 'lib/syntax_tree/yarv/instructions.rb', line 2967

def canonical
  Send.new(calldata, nil)
end

#disasm(fmt) ⇒ Object



2947
2948
2949
# File 'lib/syntax_tree/yarv/instructions.rb', line 2947

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

#lengthObject



2955
2956
2957
# File 'lib/syntax_tree/yarv/instructions.rb', line 2955

def length
  2
end

#popsObject



2959
2960
2961
# File 'lib/syntax_tree/yarv/instructions.rb', line 2959

def pops
  2
end

#pushesObject



2963
2964
2965
# File 'lib/syntax_tree/yarv/instructions.rb', line 2963

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2951
2952
2953
# File 'lib/syntax_tree/yarv/instructions.rb', line 2951

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