Class: SyntaxTree::YARV::GetLocal
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::GetLocal
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
‘getlocal` fetches the value of a local variable from 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 pushes the value it finds onto the stack.
### Usage
~~~ruby value = 5 tap { tap { value } } ~~~
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) ⇒ GetLocal
constructor
A new instance of GetLocal.
- #length ⇒ Object
- #pushes ⇒ Object
- #to_a(iseq) ⇒ Object
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pops, #side_effects?
Constructor Details
#initialize(index, level) ⇒ GetLocal
Returns a new instance of GetLocal.
1831 1832 1833 1834 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1831 def initialize(index, level) @index = index @level = level end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
1829 1830 1831 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1829 def index @index end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
1829 1830 1831 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1829 def level @level end |
Instance Method Details
#==(other) ⇒ Object
1850 1851 1852 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1850 def ==(other) other.is_a?(GetLocal) && other.index == index && other.level == level end |
#call(vm) ⇒ Object
1862 1863 1864 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1862 def call(vm) vm.push(vm.local_get(index, level)) end |
#deconstruct_keys(_keys) ⇒ Object
1846 1847 1848 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1846 def deconstruct_keys(_keys) { index: index, level: level } end |
#disasm(fmt) ⇒ Object
1836 1837 1838 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1836 def disasm(fmt) fmt.instruction("getlocal", [fmt.local(index, explicit: level)]) end |
#length ⇒ Object
1854 1855 1856 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1854 def length 3 end |
#pushes ⇒ Object
1858 1859 1860 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1858 def pushes 1 end |
#to_a(iseq) ⇒ Object
1840 1841 1842 1843 1844 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1840 def to_a(iseq) current = iseq level.times { current = current.parent_iseq } [:getlocal, current.local_table.offset(index), level] end |