Class: SyntaxTree::YARV::GetLocal
- Inherits:
-
Object
- Object
- 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
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(index, level) ⇒ GetLocal
constructor
A new instance of GetLocal.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(iseq) ⇒ Object
Constructor Details
#initialize(index, level) ⇒ GetLocal
1720 1721 1722 1723 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1720 def initialize(index, level) @index = index @level = level end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
1718 1719 1720 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1718 def index @index end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
1718 1719 1720 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1718 def level @level end |
Instance Method Details
#call(vm) ⇒ Object
1751 1752 1753 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1751 def call(vm) vm.push(vm.local_get(index, level)) end |
#canonical ⇒ Object
1747 1748 1749 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1747 def canonical self end |
#disasm(fmt) ⇒ Object
1725 1726 1727 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1725 def disasm(fmt) fmt.instruction("getlocal", [fmt.local(index, explicit: level)]) end |
#length ⇒ Object
1735 1736 1737 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1735 def length 3 end |
#pops ⇒ Object
1739 1740 1741 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1739 def pops 0 end |
#pushes ⇒ Object
1743 1744 1745 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1743 def pushes 1 end |
#to_a(iseq) ⇒ Object
1729 1730 1731 1732 1733 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1729 def to_a(iseq) current = iseq level.times { current = current.parent_iseq } [:getlocal, current.local_table.offset(index), level] end |