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
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ 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.
4163 4164 4165 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4163 def initialize(calldata) @calldata = calldata end |
Instance Attribute Details
#calldata ⇒ Object (readonly)
Returns the value of attribute calldata.
4161 4162 4163 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4161 def calldata @calldata end |
Instance Method Details
#==(other) ⇒ Object
4179 4180 4181 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4179 def ==(other) other.is_a?(OptNilP) && other.calldata == calldata end |
#call(vm) ⇒ Object
4199 4200 4201 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4199 def call(vm) canonical.call(vm) end |
#canonical ⇒ Object
4195 4196 4197 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4195 def canonical Send.new(calldata, nil) end |
#deconstruct_keys(_keys) ⇒ Object
4175 4176 4177 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4175 def deconstruct_keys(_keys) { calldata: calldata } end |
#disasm(fmt) ⇒ Object
4167 4168 4169 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4167 def disasm(fmt) fmt.instruction("opt_nil_p", [fmt.calldata(calldata)]) end |
#length ⇒ Object
4183 4184 4185 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4183 def length 2 end |
#pops ⇒ Object
4187 4188 4189 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4187 def pops 1 end |
#pushes ⇒ Object
4191 4192 4193 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4191 def pushes 1 end |
#to_a(_iseq) ⇒ Object
4171 4172 4173 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4171 def to_a(_iseq) [:opt_nil_p, calldata.to_h] end |