Class: SyntaxTree::YARV::Jump

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/yarv/instructions.rb

Overview

### Summary

jump unconditionally jumps to the label given as its only argument.

### Usage

~~~ruby x = 0 if x == 0

puts "0"

else

puts "2"

end ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label) ⇒ Jump

Returns a new instance of Jump.



2096
2097
2098
# File 'lib/syntax_tree/yarv/instructions.rb', line 2096

def initialize(label)
  @label = label
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



2094
2095
2096
# File 'lib/syntax_tree/yarv/instructions.rb', line 2094

def label
  @label
end

Instance Method Details

#call(vm) ⇒ Object



2124
2125
2126
# File 'lib/syntax_tree/yarv/instructions.rb', line 2124

def call(vm)
  vm.jump(label)
end

#canonicalObject



2120
2121
2122
# File 'lib/syntax_tree/yarv/instructions.rb', line 2120

def canonical
  self
end

#disasm(fmt) ⇒ Object



2100
2101
2102
# File 'lib/syntax_tree/yarv/instructions.rb', line 2100

def disasm(fmt)
  fmt.instruction("jump", [fmt.label(label)])
end

#lengthObject



2108
2109
2110
# File 'lib/syntax_tree/yarv/instructions.rb', line 2108

def length
  2
end

#popsObject



2112
2113
2114
# File 'lib/syntax_tree/yarv/instructions.rb', line 2112

def pops
  0
end

#pushesObject



2116
2117
2118
# File 'lib/syntax_tree/yarv/instructions.rb', line 2116

def pushes
  0
end

#to_a(_iseq) ⇒ Object



2104
2105
2106
# File 'lib/syntax_tree/yarv/instructions.rb', line 2104

def to_a(_iseq)
  [:jump, label.name]
end