class SyntaxTree::YARV::SetGlobal

### Summary

‘setglobal` sets the value of a global variable to a value popped off the top of the stack.

### Usage

~~~ruby $global = 5 ~~~

Attributes

name[R]

Public Class Methods

new(name) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5063
def initialize(name)
  @name = name
end

Public Instance Methods

==(other) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5079
def ==(other)
  other.is_a?(SetGlobal) && other.name == name
end
call(vm) click to toggle source
# 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) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5075
def deconstruct_keys(_keys)
  { name: name }
end
disasm(fmt) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5067
def disasm(fmt)
  fmt.instruction("setglobal", [fmt.object(name)])
end
length() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5083
def length
  2
end
pops() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5087
def pops
  1
end
to_a(_iseq) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5071
def to_a(_iseq)
  [:setglobal, name]
end