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.
5063 5064 5065 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5063 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5061 5062 5063 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5061 def name @name end |
Instance Method Details
#==(other) ⇒ Object
5079 5080 5081 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5079 def ==(other) other.is_a?(SetGlobal) && other.name == name end |
#call(vm) ⇒ Object
5091 5092 5093 5094 5095 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5091 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
5075 5076 5077 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5075 def deconstruct_keys(_keys) { name: name } end |
#disasm(fmt) ⇒ Object
5067 5068 5069 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5067 def disasm(fmt) fmt.instruction("setglobal", [fmt.object(name)]) end |
#length ⇒ Object
5083 5084 5085 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5083 def length 2 end |
#pops ⇒ Object
5087 5088 5089 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5087 def pops 1 end |
#to_a(_iseq) ⇒ Object
5071 5072 5073 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5071 def to_a(_iseq) [:setglobal, name] end |