Class: SyntaxTree::YARV::Jump

Inherits:
Instruction 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

Methods inherited from Instruction

#canonical, #falls_through?, #leaves?, #pops, #pushes, #side_effects?

Constructor Details

#initialize(label) ⇒ Jump

Returns a new instance of Jump.



2220
2221
2222
# File 'lib/syntax_tree/yarv/instructions.rb', line 2220

def initialize(label)
  @label = label
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



2218
2219
2220
# File 'lib/syntax_tree/yarv/instructions.rb', line 2218

def label
  @label
end

Instance Method Details

#==(other) ⇒ Object



2236
2237
2238
# File 'lib/syntax_tree/yarv/instructions.rb', line 2236

def ==(other)
  other.is_a?(Jump) && other.label == label
end

#branch_targetsObject



2248
2249
2250
# File 'lib/syntax_tree/yarv/instructions.rb', line 2248

def branch_targets
  [label]
end

#call(vm) ⇒ Object



2244
2245
2246
# File 'lib/syntax_tree/yarv/instructions.rb', line 2244

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

#deconstruct_keys(_keys) ⇒ Object



2232
2233
2234
# File 'lib/syntax_tree/yarv/instructions.rb', line 2232

def deconstruct_keys(_keys)
  { label: label }
end

#disasm(fmt) ⇒ Object



2224
2225
2226
# File 'lib/syntax_tree/yarv/instructions.rb', line 2224

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

#lengthObject



2240
2241
2242
# File 'lib/syntax_tree/yarv/instructions.rb', line 2240

def length
  2
end

#to_a(_iseq) ⇒ Object



2228
2229
2230
# File 'lib/syntax_tree/yarv/instructions.rb', line 2228

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