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.
5105 5106 5107 5108 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5105 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
5103 5104 5105 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5103 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5103 5104 5105 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5103 def name @name end |
Instance Method Details
#==(other) ⇒ Object
5125 5126 5127 5128 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5125 def ==(other) other.is_a?(SetInstanceVariable) && other.name == name && other.cache == cache end |
#call(vm) ⇒ Object
5138 5139 5140 5141 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5138 def call(vm) method = Object.instance_method(:instance_variable_set) method.bind(vm.frame._self).call(name, vm.pop) end |
#deconstruct_keys(_keys) ⇒ Object
5121 5122 5123 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5121 def deconstruct_keys(_keys) { name: name, cache: cache } end |
#disasm(fmt) ⇒ Object
5110 5111 5112 5113 5114 5115 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5110 def disasm(fmt) fmt.instruction( "setinstancevariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
5130 5131 5132 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5130 def length 3 end |
#pops ⇒ Object
5134 5135 5136 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5134 def pops 1 end |
#to_a(_iseq) ⇒ Object
5117 5118 5119 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5117 def to_a(_iseq) [:setinstancevariable, name, cache] end |