Class: SyntaxTree::YARV::SetLocal
- Inherits:
-
Object
- Object
- 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
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(index, level) ⇒ SetLocal
constructor
A new instance of SetLocal.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(iseq) ⇒ Object
Constructor Details
#initialize(index, level) ⇒ SetLocal
4832 4833 4834 4835 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4832 def initialize(index, level) @index = index @level = level end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
4830 4831 4832 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4830 def index @index end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
4830 4831 4832 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4830 def level @level end |
Instance Method Details
#call(vm) ⇒ Object
4863 4864 4865 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4863 def call(vm) vm.local_set(index, level, vm.pop) end |
#canonical ⇒ Object
4859 4860 4861 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4859 def canonical self end |
#disasm(fmt) ⇒ Object
4837 4838 4839 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4837 def disasm(fmt) fmt.instruction("setlocal", [fmt.local(index, explicit: level)]) end |
#length ⇒ Object
4847 4848 4849 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4847 def length 3 end |
#pops ⇒ Object
4851 4852 4853 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4851 def pops 1 end |
#pushes ⇒ Object
4855 4856 4857 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4855 def pushes 0 end |
#to_a(iseq) ⇒ Object
4841 4842 4843 4844 4845 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4841 def to_a(iseq) current = iseq level.times { current = current.parent_iseq } [:setlocal, current.local_table.offset(index), level] end |