Class: SyntaxTree::YARV::SetGlobal

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject (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

#canonicalObject



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

#lengthObject



4735
4736
4737
# File 'lib/syntax_tree/yarv/instructions.rb', line 4735

def length
  2
end

#popsObject



4739
4740
4741
# File 'lib/syntax_tree/yarv/instructions.rb', line 4739

def pops
  1
end

#pushesObject



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