class SyntaxTree::YARV::SetInstanceVariable
### Summary
‘setinstancevariable` pops a value off the top of the stack and then sets the instance variable associated with the instruction to that value.
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 = 1 ~~~
Attributes
Public Class Methods
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5264 def initialize(name, cache) @name = name @cache = cache end
Public Instance Methods
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5284 def ==(other) other.is_a?(SetInstanceVariable) && other.name == name && other.cache == cache end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5297 def call(vm) method = Object.instance_method(:instance_variable_set) method.bind(vm.frame._self).call(name, vm.pop) end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5280 def deconstruct_keys(_keys) { name: name, cache: cache } end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5269 def disasm(fmt) fmt.instruction( "setinstancevariable", [fmt.object(name), fmt.inline_storage(cache)] ) end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5276 def to_a(_iseq) [:setinstancevariable, name, cache] end