Class: SyntaxTree::YARV::Legacy::SetClassVariable

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

Overview

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

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

### Usage

~~~ruby @@class_variable = 1 ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ SetClassVariable

Returns a new instance of SetClassVariable.



181
182
183
# File 'lib/syntax_tree/yarv/legacy.rb', line 181

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



179
180
181
# File 'lib/syntax_tree/yarv/legacy.rb', line 179

def name
  @name
end

Instance Method Details

#call(vm) ⇒ Object



209
210
211
# File 'lib/syntax_tree/yarv/legacy.rb', line 209

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

#canonicalObject



205
206
207
# File 'lib/syntax_tree/yarv/legacy.rb', line 205

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

#disasm(fmt) ⇒ Object



185
186
187
# File 'lib/syntax_tree/yarv/legacy.rb', line 185

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

#lengthObject



193
194
195
# File 'lib/syntax_tree/yarv/legacy.rb', line 193

def length
  2
end

#popsObject



197
198
199
# File 'lib/syntax_tree/yarv/legacy.rb', line 197

def pops
  1
end

#pushesObject



201
202
203
# File 'lib/syntax_tree/yarv/legacy.rb', line 201

def pushes
  0
end

#to_a(_iseq) ⇒ Object



189
190
191
# File 'lib/syntax_tree/yarv/legacy.rb', line 189

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