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.
5007 5008 5009 5010 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5007 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
5005 5006 5007 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5005 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5005 5006 5007 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5005 def name @name end |
Instance Method Details
#==(other) ⇒ Object
5027 5028 5029 5030 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5027 def ==(other) other.is_a?(SetClassVariable) && other.name == name && other.cache == cache end |
#call(vm) ⇒ Object
5040 5041 5042 5043 5044 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5040 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
5023 5024 5025 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5023 def deconstruct_keys(_keys) { name: name, cache: cache } end |
#disasm(fmt) ⇒ Object
5012 5013 5014 5015 5016 5017 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5012 def disasm(fmt) fmt.instruction( "setclassvariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
5032 5033 5034 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5032 def length 3 end |
#pops ⇒ Object
5036 5037 5038 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5036 def pops 1 end |
#to_a(_iseq) ⇒ Object
5019 5020 5021 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5019 def to_a(_iseq) [:setclassvariable, name, cache] end |