Class: SyntaxTree::YARV::OptNEq
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::OptNEq
- 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
-
#eq_calldata ⇒ Object
readonly
Returns the value of attribute eq_calldata.
-
#neq_calldata ⇒ Object
readonly
Returns the value of attribute neq_calldata.
Instance Method Summary collapse
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(eq_calldata, neq_calldata) ⇒ OptNEq
constructor
A new instance of OptNEq.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
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_calldata ⇒ Object (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_calldata ⇒ Object (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 |
#canonical ⇒ Object
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 |
#length ⇒ Object
3508 3509 3510 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3508 def length 3 end |
#pops ⇒ Object
3512 3513 3514 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3512 def pops 2 end |
#pushes ⇒ Object
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 |