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.



3492
3493
3494
3495
# File 'lib/syntax_tree/yarv/instructions.rb', line 3492

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.



3490
3491
3492
# File 'lib/syntax_tree/yarv/instructions.rb', line 3490

def eq_calldata
  @eq_calldata
end

#neq_calldataObject (readonly)

Returns the value of attribute neq_calldata.



3490
3491
3492
# File 'lib/syntax_tree/yarv/instructions.rb', line 3490

def neq_calldata
  @neq_calldata
end

Instance Method Details

#call(vm) ⇒ Object



3524
3525
3526
3527
# File 'lib/syntax_tree/yarv/instructions.rb', line 3524

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

#canonicalObject



3520
3521
3522
# File 'lib/syntax_tree/yarv/instructions.rb', line 3520

def canonical
  self
end

#disasm(fmt) ⇒ Object



3497
3498
3499
3500
3501
3502
# File 'lib/syntax_tree/yarv/instructions.rb', line 3497

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

#lengthObject



3508
3509
3510
# File 'lib/syntax_tree/yarv/instructions.rb', line 3508

def length
  3
end

#popsObject



3512
3513
3514
# File 'lib/syntax_tree/yarv/instructions.rb', line 3512

def pops
  2
end

#pushesObject



3516
3517
3518
# File 'lib/syntax_tree/yarv/instructions.rb', line 3516

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3504
3505
3506
# File 'lib/syntax_tree/yarv/instructions.rb', line 3504

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