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.
3881
3882
3883
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3881
def initialize(calldata)
@calldata = calldata
end
|
Instance Attribute Details
#calldata ⇒ Object
Returns the value of attribute calldata.
3879
3880
3881
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3879
def calldata
@calldata
end
|
Instance Method Details
#==(other) ⇒ Object
3897
3898
3899
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3897
def ==(other)
other.is_a?(OptNilP) && other.calldata == calldata
end
|
#call(vm) ⇒ Object
3917
3918
3919
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3917
def call(vm)
canonical.call(vm)
end
|
#canonical ⇒ Object
3913
3914
3915
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3913
def canonical
Send.new(calldata, nil)
end
|
#deconstruct_keys(_keys) ⇒ Object
3893
3894
3895
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3893
def deconstruct_keys(_keys)
{ calldata: calldata }
end
|
#disasm(fmt) ⇒ Object
3885
3886
3887
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3885
def disasm(fmt)
fmt.instruction("opt_nil_p", [fmt.calldata(calldata)])
end
|
#length ⇒ Object
3901
3902
3903
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3901
def length
2
end
|
#pops ⇒ Object
3905
3906
3907
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3905
def pops
1
end
|
#pushes ⇒ Object
3909
3910
3911
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3909
def pushes
1
end
|
#to_a(_iseq) ⇒ Object
3889
3890
3891
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3889
def to_a(_iseq)
[:opt_nil_p, calldata.to_h]
end
|