Class: SyntaxTree::YARV::SetClassVariable
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. It uses an
inline cache to reduce the need to lookup the class variable in the class
hierarchy every time.
Usage
@@class_variable = 1
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pushes, #side_effects?
Constructor Details
Returns a new instance of SetClassVariable.
5108
5109
5110
5111
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5108
def initialize(name, cache)
@name = name
@cache = cache
end
|
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
5106
5107
5108
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5106
def cache
@cache
end
|
#name ⇒ Object
Returns the value of attribute name.
5106
5107
5108
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5106
def name
@name
end
|
Instance Method Details
#==(other) ⇒ Object
5128
5129
5130
5131
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5128
def ==(other)
other.is_a?(SetClassVariable) && other.name == name &&
other.cache == cache
end
|
#call(vm) ⇒ Object
5141
5142
5143
5144
5145
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5141
def call(vm)
clazz = vm.frame._self
clazz = clazz.class unless clazz.is_a?(Class)
clazz.class_variable_set(name, vm.pop)
end
|
#deconstruct_keys(_keys) ⇒ Object
5124
5125
5126
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5124
def deconstruct_keys(_keys)
{ name: name, cache: cache }
end
|
#disasm(fmt) ⇒ Object
5113
5114
5115
5116
5117
5118
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5113
def disasm(fmt)
fmt.instruction(
"setclassvariable",
[fmt.object(name), fmt.inline_storage(cache)]
)
end
|
#length ⇒ Object
5133
5134
5135
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5133
def length
3
end
|
#pops ⇒ Object
5137
5138
5139
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5137
def pops
1
end
|
#to_a(_iseq) ⇒ Object
5120
5121
5122
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5120
def to_a(_iseq)
[:setclassvariable, name, cache]
end
|