class SyntaxTree::YARV::GetInstanceVariable
### 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_variable ~~~
Attributes
Public Class Methods
Source
# File lib/syntax_tree/yarv/instructions.rb, line 1828 def initialize(name, cache) @name = name @cache = cache end
Public Instance Methods
Source
# File lib/syntax_tree/yarv/instructions.rb, line 1848 def ==(other) other.is_a?(GetInstanceVariable) && other.name == name && other.cache == cache end
Source
# 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
Source
# File lib/syntax_tree/yarv/instructions.rb, line 1844 def deconstruct_keys(_keys) { name: name, cache: cache } end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 1833 def disasm(fmt) fmt.instruction( "getinstancevariable", [fmt.object(name), fmt.inline_storage(cache)] ) end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 1840 def to_a(_iseq) [:getinstancevariable, name, cache] end