Class: SyntaxTree::YARV::GetClassVariable

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

Overview

### Summary

getclassvariable looks for a class variable in the current class and pushes its value onto 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 ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, cache) ⇒ GetClassVariable



1494
1495
1496
1497
# File 'lib/syntax_tree/yarv/instructions.rb', line 1494

def initialize(name, cache)
  @name = name
  @cache = cache
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



1492
1493
1494
# File 'lib/syntax_tree/yarv/instructions.rb', line 1492

def cache
  @cache
end

#nameObject (readonly)

Returns the value of attribute name.



1492
1493
1494
# File 'lib/syntax_tree/yarv/instructions.rb', line 1492

def name
  @name
end

Instance Method Details

#call(vm) ⇒ Object



1526
1527
1528
1529
1530
# File 'lib/syntax_tree/yarv/instructions.rb', line 1526

def call(vm)
  clazz = vm.frame._self
  clazz = clazz.class unless clazz.is_a?(Class)
  vm.push(clazz.class_variable_get(name))
end

#canonicalObject



1522
1523
1524
# File 'lib/syntax_tree/yarv/instructions.rb', line 1522

def canonical
  self
end

#disasm(fmt) ⇒ Object



1499
1500
1501
1502
1503
1504
# File 'lib/syntax_tree/yarv/instructions.rb', line 1499

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

#lengthObject



1510
1511
1512
# File 'lib/syntax_tree/yarv/instructions.rb', line 1510

def length
  3
end

#popsObject



1514
1515
1516
# File 'lib/syntax_tree/yarv/instructions.rb', line 1514

def pops
  0
end

#pushesObject



1518
1519
1520
# File 'lib/syntax_tree/yarv/instructions.rb', line 1518

def pushes
  1
end

#to_a(_iseq) ⇒ Object



1506
1507
1508
# File 'lib/syntax_tree/yarv/instructions.rb', line 1506

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