Class: SyntaxTree::YARV::SetGlobal
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::SetGlobal
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(name) ⇒ SetGlobal
constructor
A new instance of SetGlobal.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(name) ⇒ SetGlobal
5425 5426 5427 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5425 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5423 5424 5425 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5423 def name @name end |
Instance Method Details
#==(other) ⇒ Object
5441 5442 5443 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5441 def ==(other) other.is_a?(SetGlobal) && other.name == name end |
#call(vm) ⇒ Object
5461 5462 5463 5464 5465 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5461 def call(vm) # Evaluating the name of the global variable because there isn't a # reflection API for global variables. eval("#{name} = vm.pop", binding, __FILE__, __LINE__) end |
#canonical ⇒ Object
5457 5458 5459 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5457 def canonical self end |
#deconstruct_keys(_keys) ⇒ Object
5437 5438 5439 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5437 def deconstruct_keys(_keys) { name: name } end |
#disasm(fmt) ⇒ Object
5429 5430 5431 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5429 def disasm(fmt) fmt.instruction("setglobal", [fmt.object(name)]) end |
#length ⇒ Object
5445 5446 5447 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5445 def length 2 end |
#pops ⇒ Object
5449 5450 5451 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5449 def pops 1 end |
#pushes ⇒ Object
5453 5454 5455 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5453 def pushes 0 end |
#to_a(_iseq) ⇒ Object
5433 5434 5435 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5433 def to_a(_iseq) [:setglobal, name] end |