Class: SyntaxTree::YARV::BranchNil
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::BranchNil
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
branchnil has one argument: the jump index. It pops one value off the stack: the jump condition.
If the value popped off the stack is nil, branchnil jumps to the jump index and continues executing there.
### Usage
~~~ruby x = nil if x&.to_s
puts "hi"
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) ⇒ BranchNil
constructor
A new instance of BranchNil.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(label) ⇒ BranchNil
Returns a new instance of BranchNil.
241 242 243 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 241 def initialize(label) @label = label end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
239 240 241 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 239 def label @label end |
Instance Method Details
#call(vm) ⇒ Object
269 270 271 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 269 def call(vm) vm.jump(label) if vm.pop.nil? end |
#canonical ⇒ Object
265 266 267 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 265 def canonical self end |
#disasm(fmt) ⇒ Object
245 246 247 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 245 def disasm(fmt) fmt.instruction("branchnil", [fmt.label(label)]) end |
#length ⇒ Object
253 254 255 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 253 def length 2 end |
#pops ⇒ Object
257 258 259 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 257 def pops 1 end |
#pushes ⇒ Object
261 262 263 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 261 def pushes 0 end |
#to_a(_iseq) ⇒ Object
249 250 251 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 249 def to_a(_iseq) [:branchnil, label.name] end |