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.
3829 3830 3831 3832 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3829 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.
3827 3828 3829 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3827 def eq_calldata @eq_calldata end |
#neq_calldata ⇒ Object (readonly)
Returns the value of attribute neq_calldata.
3827 3828 3829 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3827 def neq_calldata @neq_calldata end |
Instance Method Details
#==(other) ⇒ Object
3849 3850 3851 3852 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3849 def ==(other) other.is_a?(OptNEq) && other.eq_calldata == eq_calldata && other.neq_calldata == neq_calldata end |
#call(vm) ⇒ Object
3866 3867 3868 3869 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3866 def call(vm) receiver, argument = vm.pop(2) vm.push(receiver != argument) end |
#deconstruct_keys(_keys) ⇒ Object
3845 3846 3847 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3845 def deconstruct_keys(_keys) { eq_calldata: eq_calldata, neq_calldata: neq_calldata } end |
#disasm(fmt) ⇒ Object
3834 3835 3836 3837 3838 3839 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3834 def disasm(fmt) fmt.instruction( "opt_neq", [fmt.calldata(eq_calldata), fmt.calldata(neq_calldata)] ) end |
#length ⇒ Object
3854 3855 3856 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3854 def length 3 end |
#pops ⇒ Object
3858 3859 3860 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3858 def pops 2 end |
#pushes ⇒ Object
3862 3863 3864 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3862 def pushes 1 end |
#to_a(_iseq) ⇒ Object
3841 3842 3843 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3841 def to_a(_iseq) [:opt_neq, eq_calldata.to_h, neq_calldata.to_h] end |