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
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ 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.
325 326 327 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 325 def initialize(label) @label = label end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
323 324 325 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 323 def label @label end |
Instance Method Details
#==(other) ⇒ Object
341 342 343 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 341 def ==(other) other.is_a?(BranchUnless) && other.label == label end |
#call(vm) ⇒ Object
361 362 363 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 361 def call(vm) vm.jump(label) unless vm.pop end |
#canonical ⇒ Object
357 358 359 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 357 def canonical self end |
#deconstruct_keys(_keys) ⇒ Object
337 338 339 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 337 def deconstruct_keys(_keys) { label: label } end |
#disasm(fmt) ⇒ Object
329 330 331 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 329 def disasm(fmt) fmt.instruction("branchunless", [fmt.label(label)]) end |
#length ⇒ Object
345 346 347 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 345 def length 2 end |
#pops ⇒ Object
349 350 351 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 349 def pops 1 end |
#pushes ⇒ Object
353 354 355 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 353 def pushes 0 end |
#to_a(_iseq) ⇒ Object
333 334 335 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 333 def to_a(_iseq) [:branchunless, label.name] end |