Class: SyntaxTree::YARV::BranchUnless

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#labelObject (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

#canonicalObject



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

#lengthObject



305
306
307
# File 'lib/syntax_tree/yarv/instructions.rb', line 305

def length
  2
end

#popsObject



309
310
311
# File 'lib/syntax_tree/yarv/instructions.rb', line 309

def pops
  1
end

#pushesObject



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