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
- #call(vm) ⇒ Object
- #canonical ⇒ 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
4723 4724 4725 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4723 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4721 4722 4723 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4721 def name @name end |
Instance Method Details
#call(vm) ⇒ Object
4751 4752 4753 4754 4755 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4751 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
4747 4748 4749 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4747 def canonical self end |
#disasm(fmt) ⇒ Object
4727 4728 4729 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4727 def disasm(fmt) fmt.instruction("setglobal", [fmt.object(name)]) end |
#length ⇒ Object
4735 4736 4737 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4735 def length 2 end |
#pops ⇒ Object
4739 4740 4741 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4739 def pops 1 end |
#pushes ⇒ Object
4743 4744 4745 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4743 def pushes 0 end |
#to_a(_iseq) ⇒ Object
4731 4732 4733 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4731 def to_a(_iseq) [:setglobal, name] end |