Class: SyntaxTree::YARV::SetLocal
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::SetLocal
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
‘setlocal` sets the value of a local variable on a frame determined by the level and index arguments. The level is the number of frames back to look and the index is the index in the local table. It pops the value it is setting off the stack.
### Usage
~~~ruby value = 5 tap { tap { value = 10 } } ~~~
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(index, level) ⇒ SetLocal
constructor
A new instance of SetLocal.
- #length ⇒ Object
- #pops ⇒ Object
- #to_a(iseq) ⇒ Object
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pushes, #side_effects?
Constructor Details
#initialize(index, level) ⇒ SetLocal
Returns a new instance of SetLocal.
5173 5174 5175 5176 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5173 def initialize(index, level) @index = index @level = level end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
5171 5172 5173 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5171 def index @index end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
5171 5172 5173 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5171 def level @level end |
Instance Method Details
#==(other) ⇒ Object
5192 5193 5194 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5192 def ==(other) other.is_a?(SetLocal) && other.index == index && other.level == level end |
#call(vm) ⇒ Object
5204 5205 5206 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5204 def call(vm) vm.local_set(index, level, vm.pop) end |
#deconstruct_keys(_keys) ⇒ Object
5188 5189 5190 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5188 def deconstruct_keys(_keys) { index: index, level: level } end |
#disasm(fmt) ⇒ Object
5178 5179 5180 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5178 def disasm(fmt) fmt.instruction("setlocal", [fmt.local(index, explicit: level)]) end |
#length ⇒ Object
5196 5197 5198 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5196 def length 3 end |
#pops ⇒ Object
5200 5201 5202 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5200 def pops 1 end |
#to_a(iseq) ⇒ Object
5182 5183 5184 5185 5186 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5182 def to_a(iseq) current = iseq level.times { current = current.parent_iseq } [:setlocal, current.local_table.offset(index), level] end |