Class: SyntaxTree::YARV::OptNilP
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::OptNilP
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
opt_nil_p is an optimization applied when the method nil? is called. It returns true immediately when the receiver is nil and defers to the nil? method in other cases. It pops the receiver off the stack and pushes on the result.
### Usage
~~~ruby “”.nil? ~~~
Instance Attribute Summary collapse
-
#calldata ⇒ Object
readonly
Returns the value of attribute calldata.
Instance Method Summary collapse
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(calldata) ⇒ OptNilP
constructor
A new instance of OptNilP.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(calldata) ⇒ OptNilP
Returns a new instance of OptNilP.
3642 3643 3644 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3642 def initialize(calldata) @calldata = calldata end |
Instance Attribute Details
#calldata ⇒ Object (readonly)
Returns the value of attribute calldata.
3640 3641 3642 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3640 def calldata @calldata end |
Instance Method Details
#call(vm) ⇒ Object
3670 3671 3672 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3670 def call(vm) canonical.call(vm) end |
#canonical ⇒ Object
3666 3667 3668 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3666 def canonical Send.new(calldata, nil) end |
#disasm(fmt) ⇒ Object
3646 3647 3648 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3646 def disasm(fmt) fmt.instruction("opt_nil_p", [fmt.calldata(calldata)]) end |
#length ⇒ Object
3654 3655 3656 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3654 def length 2 end |
#pops ⇒ Object
3658 3659 3660 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3658 def pops 1 end |
#pushes ⇒ Object
3662 3663 3664 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3662 def pushes 1 end |
#to_a(_iseq) ⇒ Object
3650 3651 3652 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3650 def to_a(_iseq) [:opt_nil_p, calldata.to_h] end |