Class: SyntaxTree::YARV::SetGlobal
Overview
### Summary
setglobal sets the value of a global variable to a value popped off the top of the stack.
### Usage
~~~ruby $global = 5 ~~~
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pushes, #side_effects?
Constructor Details
#initialize(name) ⇒ SetGlobal
5109
5110
5111
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5109
def initialize(name)
@name = name
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5107
5108
5109
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5107
def name
@name
end
|
Instance Method Details
#==(other) ⇒ Object
5125
5126
5127
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5125
def ==(other)
other.is_a?(SetGlobal) && other.name == name
end
|
#call(vm) ⇒ Object
5137
5138
5139
5140
5141
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5137
def call(vm)
eval("#{name} = vm.pop", binding, __FILE__, __LINE__)
end
|
#deconstruct_keys(_keys) ⇒ Object
5121
5122
5123
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5121
def deconstruct_keys(_keys)
{ name: name }
end
|
#disasm(fmt) ⇒ Object
5113
5114
5115
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5113
def disasm(fmt)
fmt.instruction("setglobal", [fmt.object(name)])
end
|
#length ⇒ Object
5129
5130
5131
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5129
def length
2
end
|
#pops ⇒ Object
5133
5134
5135
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5133
def pops
1
end
|
#to_a(_iseq) ⇒ Object
5117
5118
5119
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5117
def to_a(_iseq)
[:setglobal, name]
end
|