Class: SyntaxTree::YARV::GetInstanceVariable
- Inherits:
-
Object
- Object
- 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
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(name, cache) ⇒ GetInstanceVariable
constructor
A new instance of GetInstanceVariable.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(name, cache) ⇒ GetInstanceVariable
1867 1868 1869 1870 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1867 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
1865 1866 1867 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1865 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1865 1866 1867 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1865 def name @name end |
Instance Method Details
#==(other) ⇒ Object
1887 1888 1889 1890 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1887 def ==(other) other.is_a?(GetInstanceVariable) && other.name == name && other.cache == cache end |
#call(vm) ⇒ Object
1908 1909 1910 1911 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1908 def call(vm) method = Object.instance_method(:instance_variable_get) vm.push(method.bind(vm.frame._self).call(name)) end |
#canonical ⇒ Object
1904 1905 1906 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1904 def canonical self end |
#deconstruct_keys(_keys) ⇒ Object
1883 1884 1885 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1883 def deconstruct_keys(_keys) { name: name, cache: cache } end |
#disasm(fmt) ⇒ Object
1872 1873 1874 1875 1876 1877 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1872 def disasm(fmt) fmt.instruction( "getinstancevariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
1892 1893 1894 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1892 def length 3 end |
#pops ⇒ Object
1896 1897 1898 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1896 def pops 0 end |
#pushes ⇒ Object
1900 1901 1902 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1900 def pushes 1 end |
#to_a(_iseq) ⇒ Object
1879 1880 1881 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1879 def to_a(_iseq) [:getinstancevariable, name, cache] end |