Class: SyntaxTree::YARV::Legacy::GetClassVariable

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/yarv/legacy.rb

Overview

### Summary

getclassvariable looks for a class variable in the current class and pushes its value onto the stack.

This version of the getclassvariable instruction is no longer used since in Ruby 3.0 it gained an inline cache.‘

### Usage

~~~ruby @@class_variable ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ GetClassVariable

Returns a new instance of GetClassVariable.



25
26
27
# File 'lib/syntax_tree/yarv/legacy.rb', line 25

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/syntax_tree/yarv/legacy.rb', line 23

def name
  @name
end

Instance Method Details

#call(vm) ⇒ Object



53
54
55
# File 'lib/syntax_tree/yarv/legacy.rb', line 53

def call(vm)
  canonical.call(vm)
end

#canonicalObject



49
50
51
# File 'lib/syntax_tree/yarv/legacy.rb', line 49

def canonical
  YARV::GetClassVariable.new(name, nil)
end

#disasm(fmt) ⇒ Object



29
30
31
# File 'lib/syntax_tree/yarv/legacy.rb', line 29

def disasm(fmt)
  fmt.instruction("getclassvariable", [fmt.object(name)])
end

#lengthObject



37
38
39
# File 'lib/syntax_tree/yarv/legacy.rb', line 37

def length
  2
end

#popsObject



41
42
43
# File 'lib/syntax_tree/yarv/legacy.rb', line 41

def pops
  0
end

#pushesObject



45
46
47
# File 'lib/syntax_tree/yarv/legacy.rb', line 45

def pushes
  1
end

#to_a(_iseq) ⇒ Object



33
34
35
# File 'lib/syntax_tree/yarv/legacy.rb', line 33

def to_a(_iseq)
  [:getclassvariable, name]
end