Class: SyntaxTree::YARV::BranchIf
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::BranchIf
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
branchif has one argument: the jump index. It pops one value off the stack: the jump condition.
If the value popped off the stack is true, branchif jumps to the jump index and continues executing there.
### Usage
~~~ruby x = true x ||= “foo” puts x ~~~
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) ⇒ BranchIf
constructor
A new instance of BranchIf.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(label) ⇒ BranchIf
Returns a new instance of BranchIf.
188 189 190 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 188 def initialize(label) @label = label end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
186 187 188 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 186 def label @label end |
Instance Method Details
#call(vm) ⇒ Object
216 217 218 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 216 def call(vm) vm.jump(label) if vm.pop end |
#canonical ⇒ Object
212 213 214 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 212 def canonical self end |
#disasm(fmt) ⇒ Object
192 193 194 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 192 def disasm(fmt) fmt.instruction("branchif", [fmt.label(label)]) end |
#length ⇒ Object
200 201 202 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 200 def length 2 end |
#pops ⇒ Object
204 205 206 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 204 def pops 1 end |
#pushes ⇒ Object
208 209 210 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 208 def pushes 0 end |
#to_a(_iseq) ⇒ Object
196 197 198 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 196 def to_a(_iseq) [:branchif, label.name] end |