Class: SyntaxTree::YARV::BranchUnless
- Inherits:
-
Instruction
- Object
- Instruction
- 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
- #branch_targets ⇒ Object
- #call(vm) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
- #falls_through? ⇒ Boolean
-
#initialize(label) ⇒ BranchUnless
constructor
A new instance of BranchUnless.
- #length ⇒ Object
- #pops ⇒ Object
- #to_a(_iseq) ⇒ Object
Methods inherited from Instruction
#canonical, #leaves?, #pushes, #side_effects?
Constructor Details
#initialize(label) ⇒ BranchUnless
Returns a new instance of BranchUnless.
299 300 301 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 299 def initialize(label) @label = label end |
Instance Attribute Details
#label ⇒ Object (readonly)
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 |