Class: SyntaxTree::YARV::GetInstanceVariable
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::GetInstanceVariable
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
‘getinstancevariable` pushes the value of an instance variable onto the stack. It uses an inline cache to avoid having to look up the instance variable in the class hierarchy every time.
This instruction has two forms, but both have the same structure. Before Ruby 3.2, the inline cache corresponded to both the get and set instructions and could be shared. Since Ruby 3.2, it uses object shapes instead so the caches are unique per instruction.
### Usage
~~~ruby ~~~
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(name, cache) ⇒ GetInstanceVariable
constructor
A new instance of GetInstanceVariable.
- #length ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pops, #side_effects?
Constructor Details
#initialize(name, cache) ⇒ GetInstanceVariable
Returns a new instance of GetInstanceVariable.
1828 1829 1830 1831 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1828 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
1826 1827 1828 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1826 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1826 1827 1828 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1826 def name @name end |
Instance Method Details
#==(other) ⇒ Object
1848 1849 1850 1851 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1848 def ==(other) other.is_a?(GetInstanceVariable) && other.name == name && other.cache == cache end |
#call(vm) ⇒ Object
1861 1862 1863 1864 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1861 def call(vm) method = Object.instance_method(:instance_variable_get) vm.push(method.bind(vm.frame._self).call(name)) end |
#deconstruct_keys(_keys) ⇒ Object
1844 1845 1846 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1844 def deconstruct_keys(_keys) { name: name, cache: cache } end |
#disasm(fmt) ⇒ Object
1833 1834 1835 1836 1837 1838 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1833 def disasm(fmt) fmt.instruction( "getinstancevariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
1853 1854 1855 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1853 def length 3 end |
#pushes ⇒ Object
1857 1858 1859 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1857 def pushes 1 end |
#to_a(_iseq) ⇒ Object
1840 1841 1842 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1840 def to_a(_iseq) [:getinstancevariable, name, cache] end |