Class: SyntaxTree::YARV::SetClassVariable
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::SetClassVariable
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
‘setclassvariable` looks for a class variable in the current class and sets its value to the value it pops off the top of the stack. It uses an inline cache to reduce the need to lookup the class variable in the class hierarchy every time.
### Usage
~~~ruby @@class_variable = 1 ~~~
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) ⇒ SetClassVariable
constructor
A new instance of SetClassVariable.
- #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) ⇒ SetClassVariable
Returns a new instance of SetClassVariable.
4949 4950 4951 4952 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4949 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
4947 4948 4949 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4947 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4947 4948 4949 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4947 def name @name end |
Instance Method Details
#==(other) ⇒ Object
4969 4970 4971 4972 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4969 def ==(other) other.is_a?(SetClassVariable) && other.name == name && other.cache == cache end |
#call(vm) ⇒ Object
4982 4983 4984 4985 4986 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4982 def call(vm) clazz = vm.frame._self clazz = clazz.class unless clazz.is_a?(Class) clazz.class_variable_set(name, vm.pop) end |
#deconstruct_keys(_keys) ⇒ Object
4965 4966 4967 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4965 def deconstruct_keys(_keys) { name: name, cache: cache } end |
#disasm(fmt) ⇒ Object
4954 4955 4956 4957 4958 4959 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4954 def disasm(fmt) fmt.instruction( "setclassvariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
4974 4975 4976 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4974 def length 3 end |
#pops ⇒ Object
4978 4979 4980 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4978 def pops 1 end |
#to_a(_iseq) ⇒ Object
4961 4962 4963 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4961 def to_a(_iseq) [:setclassvariable, name, cache] end |