class SyntaxTree::YARV::GetClassVariable

### 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 ~~~

Attributes

cache[R]
name[R]

Public Class Methods

new(name, cache) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1599
def initialize(name, cache)
  @name = name
  @cache = cache
end

Public Instance Methods

==(other) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1619
def ==(other)
  other.is_a?(GetClassVariable) && other.name == name &&
    other.cache == cache
end
call(vm) click to toggle source
# 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) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1615
def deconstruct_keys(_keys)
  { name: name, cache: cache }
end
disasm(fmt) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1604
def disasm(fmt)
  fmt.instruction(
    "getclassvariable",
    [fmt.object(name), fmt.inline_storage(cache)]
  )
end
length() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1624
def length
  3
end
pushes() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1628
def pushes
  1
end
to_a(_iseq) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1611
def to_a(_iseq)
  [:getclassvariable, name, cache]
end