Class: SyntaxTree::YARV::SetInstanceVariable
- Inherits:
-
Object
- Object
- 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
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(name, cache) ⇒ SetInstanceVariable
constructor
A new instance of SetInstanceVariable.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(name, cache) ⇒ SetInstanceVariable
5487 5488 5489 5490 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5487 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
5485 5486 5487 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5485 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5485 5486 5487 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5485 def name @name end |
Instance Method Details
#==(other) ⇒ Object
5507 5508 5509 5510 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5507 def ==(other) other.is_a?(SetInstanceVariable) && other.name == name && other.cache == cache end |
#call(vm) ⇒ Object
5528 5529 5530 5531 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5528 def call(vm) method = Object.instance_method(:instance_variable_set) method.bind(vm.frame._self).call(name, vm.pop) end |
#canonical ⇒ Object
5524 5525 5526 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5524 def canonical self end |
#deconstruct_keys(_keys) ⇒ Object
5503 5504 5505 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5503 def deconstruct_keys(_keys) { name: name, cache: cache } end |
#disasm(fmt) ⇒ Object
5492 5493 5494 5495 5496 5497 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5492 def disasm(fmt) fmt.instruction( "setinstancevariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
5512 5513 5514 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5512 def length 3 end |
#pops ⇒ Object
5516 5517 5518 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5516 def pops 1 end |
#pushes ⇒ Object
5520 5521 5522 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5520 def pushes 0 end |
#to_a(_iseq) ⇒ Object
5499 5500 5501 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5499 def to_a(_iseq) [:setinstancevariable, name, cache] end |