Class: SyntaxTree::YARV::SetInstanceVariable
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::SetInstanceVariable
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### 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 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) ⇒ SetInstanceVariable
constructor
A new instance of SetInstanceVariable.
- #length ⇒ Object
- #pops ⇒ Object
- #to_a(_iseq) ⇒ Object
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pushes, #side_effects?
Constructor Details
#initialize(name, cache) ⇒ SetInstanceVariable
Returns a new instance of SetInstanceVariable.
5163 5164 5165 5166 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5163 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
5161 5162 5163 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5161 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5161 5162 5163 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5161 def name @name end |
Instance Method Details
#==(other) ⇒ Object
5183 5184 5185 5186 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5183 def ==(other) other.is_a?(SetInstanceVariable) && other.name == name && other.cache == cache end |
#call(vm) ⇒ Object
5196 5197 5198 5199 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5196 def call(vm) method = Object.instance_method(:instance_variable_set) method.bind(vm.frame._self).call(name, vm.pop) end |
#deconstruct_keys(_keys) ⇒ Object
5179 5180 5181 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5179 def deconstruct_keys(_keys) { name: name, cache: cache } end |
#disasm(fmt) ⇒ Object
5168 5169 5170 5171 5172 5173 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5168 def disasm(fmt) fmt.instruction( "setinstancevariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
5188 5189 5190 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5188 def length 3 end |
#pops ⇒ Object
5192 5193 5194 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5192 def pops 1 end |
#to_a(_iseq) ⇒ Object
5175 5176 5177 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5175 def to_a(_iseq) [:setinstancevariable, name, cache] end |