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.
2162 2163 2164 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2162 def initialize(label) @label = label end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
2160 2161 2162 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2160 def label @label end |
Instance Method Details
#==(other) ⇒ Object
2178 2179 2180 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2178 def ==(other) other.is_a?(Jump) && other.label == label end |
#branch_targets ⇒ Object
2190 2191 2192 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2190 def branch_targets [label] end |
#call(vm) ⇒ Object
2186 2187 2188 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2186 def call(vm) vm.jump(label) end |
#deconstruct_keys(_keys) ⇒ Object
2174 2175 2176 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2174 def deconstruct_keys(_keys) { label: label } end |
#disasm(fmt) ⇒ Object
2166 2167 2168 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2166 def disasm(fmt) fmt.instruction("jump", [fmt.label(label)]) end |
#length ⇒ Object
2182 2183 2184 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2182 def length 2 end |
#to_a(_iseq) ⇒ Object
2170 2171 2172 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2170 def to_a(_iseq) [:jump, label.name] end |