class SyntaxTree::YARV::BranchNil
### Summary
‘branchnil` has one argument: the jump index. It pops one value off the stack: the jump condition.
If the value popped off the stack is nil, ‘branchnil` jumps to the jump index and continues executing there.
### Usage
~~~ruby x = nil if x&.to_s
puts "hi"
end ~~~
Attributes
label[R]
Public Class Methods
new(label)
click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 239 def initialize(label) @label = label end
Public Instance Methods
==(other)
click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 255 def ==(other) other.is_a?(BranchNil) && other.label == label end
branch_targets()
click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 271 def branch_targets [label] end
call(vm)
click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 267 def call(vm) vm.jump(label) if vm.pop.nil? end
deconstruct_keys(_keys)
click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 251 def deconstruct_keys(_keys) { label: label } end
disasm(fmt)
click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 243 def disasm(fmt) fmt.instruction("branchnil", [fmt.label(label)]) end
falls_through?()
click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 275 def falls_through? true end
length()
click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 259 def length 2 end
pops()
click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 263 def pops 1 end
to_a(_iseq)
click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 247 def to_a(_iseq) [:branchnil, label.name] end