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.
1652 1653 1654 1655 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1652 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
1650 1651 1652 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1650 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1650 1651 1652 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1650 def name @name end |
Instance Method Details
#==(other) ⇒ Object
1672 1673 1674 1675 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1672 def ==(other) other.is_a?(GetClassVariable) && other.name == name && other.cache == cache end |
#call(vm) ⇒ Object
1685 1686 1687 1688 1689 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1685 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
1668 1669 1670 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1668 def deconstruct_keys(_keys) { name: name, cache: cache } end |
#disasm(fmt) ⇒ Object
1657 1658 1659 1660 1661 1662 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1657 def disasm(fmt) fmt.instruction( "getclassvariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
1677 1678 1679 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1677 def length 3 end |
#pushes ⇒ Object
1681 1682 1683 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1681 def pushes 1 end |
#to_a(_iseq) ⇒ Object
1664 1665 1666 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1664 def to_a(_iseq) [:getclassvariable, name, cache] end |