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.
1541 1542 1543 1544 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1541 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
1539 1540 1541 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1539 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1539 1540 1541 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1539 def name @name end |
Instance Method Details
#==(other) ⇒ Object
1561 1562 1563 1564 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1561 def ==(other) other.is_a?(GetClassVariable) && other.name == name && other.cache == cache end |
#call(vm) ⇒ Object
1574 1575 1576 1577 1578 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1574 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
1557 1558 1559 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1557 def deconstruct_keys(_keys) { name: name, cache: cache } end |
#disasm(fmt) ⇒ Object
1546 1547 1548 1549 1550 1551 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1546 def disasm(fmt) fmt.instruction( "getclassvariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
1566 1567 1568 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1566 def length 3 end |
#pushes ⇒ Object
1570 1571 1572 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1570 def pushes 1 end |
#to_a(_iseq) ⇒ Object
1553 1554 1555 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1553 def to_a(_iseq) [:getclassvariable, name, cache] end |