Class: SyntaxTree::YARV::BranchUnless
Overview
### Summary
branchunless has one argument: the jump index. It pops one value off the stack: the jump condition.
If the value popped off the stack is false or nil, branchunless jumps to the jump index and continues executing there.
### Usage
~~~ruby if 2 + 3
puts "foo"
end ~~~
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Instruction
#canonical, #leaves?, #pushes, #side_effects?
Constructor Details
299
300
301
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 299
def initialize(label)
@label = label
end
|
Instance Attribute Details
#label ⇒ Object
Returns the value of attribute label.
297
298
299
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 297
def label
@label
end
|
Instance Method Details
#==(other) ⇒ Object
315
316
317
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 315
def ==(other)
other.is_a?(BranchUnless) && other.label == label
end
|
#branch_targets ⇒ Object
331
332
333
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 331
def branch_targets
[label]
end
|
#call(vm) ⇒ Object
327
328
329
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 327
def call(vm)
vm.jump(label) unless vm.pop
end
|
#deconstruct_keys(_keys) ⇒ Object
311
312
313
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 311
def deconstruct_keys(_keys)
{ label: label }
end
|
#disasm(fmt) ⇒ Object
303
304
305
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 303
def disasm(fmt)
fmt.instruction("branchunless", [fmt.label(label)])
end
|
#falls_through? ⇒ Boolean
335
336
337
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 335
def falls_through?
true
end
|
#length ⇒ Object
319
320
321
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 319
def length
2
end
|
#pops ⇒ Object
323
324
325
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 323
def pops
1
end
|
#to_a(_iseq) ⇒ Object
307
308
309
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 307
def to_a(_iseq)
[:branchunless, label.name]
end
|