Class: SyntaxTree::YARV::BranchUnless
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::BranchUnless
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
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
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(label) ⇒ BranchUnless
constructor
A new instance of BranchUnless.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(label) ⇒ BranchUnless
Returns a new instance of BranchUnless.
293 294 295 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 293 def initialize(label) @label = label end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
291 292 293 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 291 def label @label end |
Instance Method Details
#call(vm) ⇒ Object
321 322 323 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 321 def call(vm) vm.jump(label) unless vm.pop end |
#canonical ⇒ Object
317 318 319 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 317 def canonical self end |
#disasm(fmt) ⇒ Object
297 298 299 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 297 def disasm(fmt) fmt.instruction("branchunless", [fmt.label(label)]) end |
#length ⇒ Object
305 306 307 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 305 def length 2 end |
#pops ⇒ Object
309 310 311 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 309 def pops 1 end |
#pushes ⇒ Object
313 314 315 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 313 def pushes 0 end |
#to_a(_iseq) ⇒ Object
301 302 303 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 301 def to_a(_iseq) [:branchunless, label.name] end |