Class: SyntaxTree::YARV::GetClassVariable
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::GetClassVariable
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
‘getclassvariable` looks for a class variable in the current class and pushes its value onto 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 ~~~
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) ⇒ GetClassVariable
constructor
A new instance of GetClassVariable.
- #length ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pops, #side_effects?
Constructor Details
#initialize(name, cache) ⇒ GetClassVariable
Returns a new instance of GetClassVariable.
1599 1600 1601 1602 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1599 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
1597 1598 1599 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1597 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1597 1598 1599 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1597 def name @name end |
Instance Method Details
#==(other) ⇒ Object
1619 1620 1621 1622 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1619 def ==(other) other.is_a?(GetClassVariable) && other.name == name && other.cache == cache end |
#call(vm) ⇒ Object
1632 1633 1634 1635 1636 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1632 def call(vm) clazz = vm.frame._self clazz = clazz.class unless clazz.is_a?(Class) vm.push(clazz.class_variable_get(name)) end |
#deconstruct_keys(_keys) ⇒ Object
1615 1616 1617 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1615 def deconstruct_keys(_keys) { name: name, cache: cache } end |
#disasm(fmt) ⇒ Object
1604 1605 1606 1607 1608 1609 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1604 def disasm(fmt) fmt.instruction( "getclassvariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
1624 1625 1626 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1624 def length 3 end |
#pushes ⇒ Object
1628 1629 1630 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1628 def pushes 1 end |
#to_a(_iseq) ⇒ Object
1611 1612 1613 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1611 def to_a(_iseq) [:getclassvariable, name, cache] end |