Class: SyntaxTree::YARV::OptNEq

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

Overview

### Summary

opt_neq is an optimization that tests whether two values at the top of the stack are not equal by testing their equality and calling the ‘!` on the result. This allows opt_neq to use the fast paths optimized in opt_eq 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(eq_calldata, neq_calldata) ⇒ OptNEq

Returns a new instance of OptNEq.



3988
3989
3990
3991
# File 'lib/syntax_tree/yarv/instructions.rb', line 3988

def initialize(eq_calldata, neq_calldata)
  @eq_calldata = eq_calldata
  @neq_calldata = neq_calldata
end

Instance Attribute Details

#eq_calldataObject (readonly)

Returns the value of attribute eq_calldata.



3986
3987
3988
# File 'lib/syntax_tree/yarv/instructions.rb', line 3986

def eq_calldata
  @eq_calldata
end

#neq_calldataObject (readonly)

Returns the value of attribute neq_calldata.



3986
3987
3988
# File 'lib/syntax_tree/yarv/instructions.rb', line 3986

def neq_calldata
  @neq_calldata
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  other.is_a?(OptNEq) && other.eq_calldata == eq_calldata &&
    other.neq_calldata == neq_calldata
end

#call(vm) ⇒ Object



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

def call(vm)
  receiver, argument = vm.pop(2)
  vm.push(receiver != argument)
end

#canonicalObject



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

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



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

def deconstruct_keys(_keys)
  { eq_calldata: eq_calldata, neq_calldata: neq_calldata }
end

#disasm(fmt) ⇒ Object



3993
3994
3995
3996
3997
3998
# File 'lib/syntax_tree/yarv/instructions.rb', line 3993

def disasm(fmt)
  fmt.instruction(
    "opt_neq",
    [fmt.calldata(eq_calldata), fmt.calldata(neq_calldata)]
  )
end

#lengthObject



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

def length
  3
end

#popsObject



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

def pops
  2
end

#pushesObject



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

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4000
4001
4002
# File 'lib/syntax_tree/yarv/instructions.rb', line 4000

def to_a(_iseq)
  [:opt_neq, eq_calldata.to_h, neq_calldata.to_h]
end