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.
5320 5321 5322 5323 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5320 def initialize(index, level) @index = index @level = level end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
5318 5319 5320 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5318 def index @index end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
5318 5319 5320 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5318 def level @level end |
Instance Method Details
#==(other) ⇒ Object
5339 5340 5341 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5339 def ==(other) other.is_a?(SetLocal) && other.index == index && other.level == level end |
#call(vm) ⇒ Object
5351 5352 5353 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5351 def call(vm) vm.local_set(index, level, vm.pop) end |
#deconstruct_keys(_keys) ⇒ Object
5335 5336 5337 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5335 def deconstruct_keys(_keys) { index: index, level: level } end |
#disasm(fmt) ⇒ Object
5325 5326 5327 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5325 def disasm(fmt) fmt.instruction("setlocal", [fmt.local(index, explicit: level)]) end |
#length ⇒ Object
5343 5344 5345 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5343 def length 3 end |
#pops ⇒ Object
5347 5348 5349 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5347 def pops 1 end |
#to_a(iseq) ⇒ Object
5329 5330 5331 5332 5333 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5329 def to_a(iseq) current = iseq level.times { current = current.parent_iseq } [:setlocal, current.local_table.offset(index), level] end |