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
- #call(vm) ⇒ Object
- #canonical ⇒ 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
Returns a new instance of SetInstanceVariable.
4777 4778 4779 4780 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4777 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
4775 4776 4777 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4775 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4775 4776 4777 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4775 def name @name end |
Instance Method Details
#call(vm) ⇒ Object
4809 4810 4811 4812 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4809 def call(vm) method = Object.instance_method(:instance_variable_set) method.bind(vm.frame._self).call(name, vm.pop) end |
#canonical ⇒ Object
4805 4806 4807 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4805 def canonical self end |
#disasm(fmt) ⇒ Object
4782 4783 4784 4785 4786 4787 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4782 def disasm(fmt) fmt.instruction( "setinstancevariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
4793 4794 4795 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4793 def length 3 end |
#pops ⇒ Object
4797 4798 4799 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4797 def pops 1 end |
#pushes ⇒ Object
4801 4802 4803 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4801 def pushes 0 end |
#to_a(_iseq) ⇒ Object
4789 4790 4791 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4789 def to_a(_iseq) [:setinstancevariable, name, cache] end |