Class: SyntaxTree::YARV::Jump
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::Jump
- 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
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #branch_targets ⇒ Object
- #call(vm) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(label) ⇒ Jump
constructor
A new instance of Jump.
- #length ⇒ Object
- #to_a(_iseq) ⇒ Object
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
#label ⇒ Object (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_targets ⇒ Object
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 |
#length ⇒ Object
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 |