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
- #call(vm) ⇒ Object
- #canonical ⇒ 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
1494 1495 1496 1497 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1494 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
1492 1493 1494 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1492 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1492 1493 1494 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1492 def name @name end |
Instance Method Details
#call(vm) ⇒ Object
1526 1527 1528 1529 1530 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1526 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
1522 1523 1524 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1522 def canonical self end |
#disasm(fmt) ⇒ Object
1499 1500 1501 1502 1503 1504 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1499 def disasm(fmt) fmt.instruction( "getclassvariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
1510 1511 1512 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1510 def length 3 end |
#pops ⇒ Object
1514 1515 1516 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1514 def pops 0 end |
#pushes ⇒ Object
1518 1519 1520 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1518 def pushes 1 end |
#to_a(_iseq) ⇒ Object
1506 1507 1508 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1506 def to_a(_iseq) [:getclassvariable, name, cache] end |