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.
5161 5162 5163 5164 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5161 def initialize(index, level) @index = index @level = level end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
5159 5160 5161 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5159 def index @index end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
5159 5160 5161 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5159 def level @level end |
Instance Method Details
#==(other) ⇒ Object
5180 5181 5182 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5180 def ==(other) other.is_a?(SetLocal) && other.index == index && other.level == level end |
#call(vm) ⇒ Object
5192 5193 5194 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5192 def call(vm) vm.local_set(index, level, vm.pop) end |
#deconstruct_keys(_keys) ⇒ Object
5176 5177 5178 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5176 def deconstruct_keys(_keys) { index: index, level: level } end |
#disasm(fmt) ⇒ Object
5166 5167 5168 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5166 def disasm(fmt) fmt.instruction("setlocal", [fmt.local(index, explicit: level)]) end |
#length ⇒ Object
5184 5185 5186 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5184 def length 3 end |
#pops ⇒ Object
5188 5189 5190 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5188 def pops 1 end |
#to_a(iseq) ⇒ Object
5170 5171 5172 5173 5174 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5170 def to_a(iseq) current = iseq level.times { current = current.parent_iseq } [:setlocal, current.local_table.offset(index), level] end |