Class: SyntaxTree::YARV::SetGlobal
- Inherits:
-
Instruction
- Object
- Instruction
- 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
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(name) ⇒ SetGlobal
constructor
A new instance of SetGlobal.
- #length ⇒ Object
- #pops ⇒ Object
- #to_a(_iseq) ⇒ Object
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pushes, #side_effects?
Constructor Details
#initialize(name) ⇒ SetGlobal
Returns a new instance of SetGlobal.
5109 5110 5111 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5109 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
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) # 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 |
#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 |