class SyntaxTree::YARV::SetClassVariable

### Summary

‘setclassvariable` looks for a class variable in the current class and sets its value to the value it pops off the top of 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 = 1 ~~~

Attributes

cache[R]
name[R]

Public Class Methods

new(name, cache) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4961
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 4981
def ==(other)
  other.is_a?(SetClassVariable) && other.name == name &&
    other.cache == cache
end
call(vm) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4994
def call(vm)
  clazz = vm.frame._self
  clazz = clazz.class unless clazz.is_a?(Class)
  clazz.class_variable_set(name, vm.pop)
end
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4977
def deconstruct_keys(_keys)
  { name: name, cache: cache }
end
disasm(fmt) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4966
def disasm(fmt)
  fmt.instruction(
    "setclassvariable",
    [fmt.object(name), fmt.inline_storage(cache)]
  )
end
length() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4986
def length
  3
end
pops() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4990
def pops
  1
end
to_a(_iseq) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4973
def to_a(_iseq)
  [:setclassvariable, name, cache]
end