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

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

Methods inherited from Instruction

#branch_targets, #falls_through?, #leaves?, #pushes, #side_effects?

Constructor Details

#initialize(name) ⇒ SetClassVariable

Returns a new instance of SetClassVariable.



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

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



214
215
216
# File 'lib/syntax_tree/yarv/legacy.rb', line 214

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

#call(vm) ⇒ Object



230
231
232
# File 'lib/syntax_tree/yarv/legacy.rb', line 230

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

#canonicalObject



226
227
228
# File 'lib/syntax_tree/yarv/legacy.rb', line 226

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

#deconstruct_keys(_keys) ⇒ Object



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

def deconstruct_keys(_keys)
  { name: name }
end

#disasm(fmt) ⇒ Object



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

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

#lengthObject



218
219
220
# File 'lib/syntax_tree/yarv/legacy.rb', line 218

def length
  2
end

#popsObject



222
223
224
# File 'lib/syntax_tree/yarv/legacy.rb', line 222

def pops
  1
end

#to_a(_iseq) ⇒ Object



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

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