Class: SyntaxTree::YARV::SetClassVariable
- Inherits:
-
Object
- Object
- 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
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(name, cache) ⇒ SetClassVariable
constructor
A new instance of SetClassVariable.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(name, cache) ⇒ SetClassVariable
4622 4623 4624 4625 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4622 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
4620 4621 4622 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4620 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4620 4621 4622 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4620 def name @name end |
Instance Method Details
#call(vm) ⇒ Object
4654 4655 4656 4657 4658 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4654 def call(vm) clazz = vm.frame._self clazz = clazz.class unless clazz.is_a?(Class) clazz.class_variable_set(name, vm.pop) end |
#canonical ⇒ Object
4650 4651 4652 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4650 def canonical self end |
#disasm(fmt) ⇒ Object
4627 4628 4629 4630 4631 4632 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4627 def disasm(fmt) fmt.instruction( "setclassvariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
4638 4639 4640 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4638 def length 3 end |
#pops ⇒ Object
4642 4643 4644 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4642 def pops 1 end |
#pushes ⇒ Object
4646 4647 4648 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4646 def pushes 0 end |
#to_a(_iseq) ⇒ Object
4634 4635 4636 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4634 def to_a(_iseq) [:setclassvariable, name, cache] end |