Class: SyntaxTree::YARV::OptNEq
- Inherits:
-
Instruction
- Object
- Instruction
- 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
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #deconstruct_keys(_keys) ⇒ 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
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #side_effects?
Constructor Details
#initialize(eq_calldata, neq_calldata) ⇒ OptNEq
Returns a new instance of OptNEq.
3776 3777 3778 3779 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3776 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.
3774 3775 3776 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3774 def eq_calldata @eq_calldata end |
#neq_calldata ⇒ Object (readonly)
Returns the value of attribute neq_calldata.
3774 3775 3776 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3774 def neq_calldata @neq_calldata end |
Instance Method Details
#==(other) ⇒ Object
3796 3797 3798 3799 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3796 def ==(other) other.is_a?(OptNEq) && other.eq_calldata == eq_calldata && other.neq_calldata == neq_calldata end |
#call(vm) ⇒ Object
3813 3814 3815 3816 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3813 def call(vm) receiver, argument = vm.pop(2) vm.push(receiver != argument) end |
#deconstruct_keys(_keys) ⇒ Object
3792 3793 3794 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3792 def deconstruct_keys(_keys) { eq_calldata: eq_calldata, neq_calldata: neq_calldata } end |
#disasm(fmt) ⇒ Object
3781 3782 3783 3784 3785 3786 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3781 def disasm(fmt) fmt.instruction( "opt_neq", [fmt.calldata(eq_calldata), fmt.calldata(neq_calldata)] ) end |
#length ⇒ Object
3801 3802 3803 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3801 def length 3 end |
#pops ⇒ Object
3805 3806 3807 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3805 def pops 2 end |
#pushes ⇒ Object
3809 3810 3811 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3809 def pushes 1 end |
#to_a(_iseq) ⇒ Object
3788 3789 3790 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3788 def to_a(_iseq) [:opt_neq, eq_calldata.to_h, neq_calldata.to_h] end |