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

Inherits:
Instruction
  • 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

Methods inherited from Instruction

#branch_targets, #falls_through?, #leaves?, #pops, #side_effects?

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

#==(other) ⇒ Object



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

def ==(other)
  other.is_a?(GetClassVariable) && other.name == name
end

#call(vm) ⇒ Object



57
58
59
# File 'lib/syntax_tree/yarv/legacy.rb', line 57

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

#canonicalObject



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

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

#deconstruct_keys(_keys) ⇒ Object



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

def deconstruct_keys(_keys)
  { name: name }
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



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

def length
  2
end

#pushesObject



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

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