Class: SyntaxTree::YARV::GetClassVariable
- Inherits:
-
Object
- Object
- 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
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(name, cache) ⇒ GetClassVariable
constructor
A new instance of GetClassVariable.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(name, cache) ⇒ GetClassVariable
Returns a new instance of GetClassVariable.
1671 1672 1673 1674 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1671 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
1669 1670 1671 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1669 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1669 1670 1671 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1669 def name @name end |
Instance Method Details
#==(other) ⇒ Object
1691 1692 1693 1694 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1691 def ==(other) other.is_a?(GetClassVariable) && other.name == name && other.cache == cache end |
#call(vm) ⇒ Object
1712 1713 1714 1715 1716 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1712 def call(vm) clazz = vm.frame._self clazz = clazz.class unless clazz.is_a?(Class) vm.push(clazz.class_variable_get(name)) end |
#canonical ⇒ Object
1708 1709 1710 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1708 def canonical self end |
#deconstruct_keys(_keys) ⇒ Object
1687 1688 1689 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1687 def deconstruct_keys(_keys) { name: name, cache: cache } end |
#disasm(fmt) ⇒ Object
1676 1677 1678 1679 1680 1681 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1676 def disasm(fmt) fmt.instruction( "getclassvariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
1696 1697 1698 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1696 def length 3 end |
#pops ⇒ Object
1700 1701 1702 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1700 def pops 0 end |
#pushes ⇒ Object
1704 1705 1706 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1704 def pushes 1 end |
#to_a(_iseq) ⇒ Object
1683 1684 1685 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1683 def to_a(_iseq) [:getclassvariable, name, cache] end |