Class: SyntaxTree::YARV::OptNilP
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
Instance Method Summary
collapse
Methods inherited from Instruction
#branch_targets, #falls_through?, #leaves?, #side_effects?
Constructor Details
#initialize(calldata) ⇒ OptNilP
Returns a new instance of OptNilP.
3893
3894
3895
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3893
def initialize(calldata)
@calldata = calldata
end
|
Instance Attribute Details
#calldata ⇒ Object
Returns the value of attribute calldata.
3891
3892
3893
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3891
def calldata
@calldata
end
|
Instance Method Details
#==(other) ⇒ Object
3909
3910
3911
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3909
def ==(other)
other.is_a?(OptNilP) && other.calldata == calldata
end
|
#call(vm) ⇒ Object
3929
3930
3931
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3929
def call(vm)
canonical.call(vm)
end
|
#canonical ⇒ Object
3925
3926
3927
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3925
def canonical
Send.new(calldata, nil)
end
|
#deconstruct_keys(_keys) ⇒ Object
3905
3906
3907
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3905
def deconstruct_keys(_keys)
{ calldata: calldata }
end
|
#disasm(fmt) ⇒ Object
3897
3898
3899
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3897
def disasm(fmt)
fmt.instruction("opt_nil_p", [fmt.calldata(calldata)])
end
|
#length ⇒ Object
3913
3914
3915
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3913
def length
2
end
|
#pops ⇒ Object
3917
3918
3919
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3917
def pops
1
end
|
#pushes ⇒ Object
3921
3922
3923
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3921
def pushes
1
end
|
#to_a(_iseq) ⇒ Object
3901
3902
3903
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3901
def to_a(_iseq)
[:opt_nil_p, calldata.to_h]
end
|