Parent

Voodoo::CommonCodeGenerator::Environment

Used for scoping. Maintains a symbol table and keeps track of the number of bytes that have been allocated on the stack.

Attributes

args[R]
bytes[RW]
locals[R]
offset[RW]
parent[R]
symbols[R]

Public Class Methods

gensym() click to toggle source

Generates a new, unique symbol.

# File voodoo/generators/common_code_generator.rb, line 721
def self.gensym
  @@gensym_counter = @@gensym_counter + 1
  "_G#{@@gensym_counter}".to_sym
end
initial_environment() click to toggle source

Returns an initial, top-level environment.

# File voodoo/generators/common_code_generator.rb, line 727
def self.initial_environment
  Environment.new
end
new(parent = nil) click to toggle source

Creates a new environment. If parent is specified, it will become the new environment’s parent. The new environment inherits all symbols from the parent environment.

# File voodoo/generators/common_code_generator.rb, line 651
def initialize parent = nil
  ## Parent environment
  @parent = parent
  ## Symbol lookup table
  @symbols = parent ? parent.symbols.dup : {}
  ## Number of arguments
  @args = parent ? parent.args : 0
  ## Number of local variables
  @locals = parent ? parent.locals : 0
  ## Offset between base pointer and end of frame.
  @offset = parent ? parent.offset : 0
  ## Number of bytes allocated in this environment.
  @bytes = 0
end

Public Instance Methods

[](symbol) click to toggle source

Looks up symbol in this environment.

# File voodoo/generators/common_code_generator.rb, line 716
def [] symbol
  @symbols[symbol]
end
add_arg(symbol, info = nil) click to toggle source

Adds symbol as an argument in this environment. info can be used by the code generator to store information it needs about the symbol.

# File voodoo/generators/common_code_generator.rb, line 669
def add_arg symbol, info = nil
  @symbols[symbol] = info
  @args = @args + 1
end
add_args(symbols) click to toggle source

Adds each of symbols to the arguments in this environment. Each entry in symbols can be either a symbol, or an array where the first element is the symbol and the second element is extra information to be stored with the symbol.

# File voodoo/generators/common_code_generator.rb, line 679
def add_args symbols
  symbols.each do |sym|
    if sym.respond_to? :[]
      add_arg *sym
    else
      add_arg sym
    end
  end
end
add_local(symbol, info = nil) click to toggle source

Adds symbol as a local variable in this environment.

# File voodoo/generators/common_code_generator.rb, line 690
def add_local symbol, info = nil
  @symbols[symbol] = info
  @locals = @locals + 1
end
add_locals(symbols) click to toggle source

Adds each of symbols to the local variables in this environment. Each entry in symbols can be either a symbol, or an array where the first element is the symbol and the second element is extra information to be stored with the symbol.

# File voodoo/generators/common_code_generator.rb, line 700
def add_locals symbols
  symbols.each do |sym|
    if sym.respond_to? :[]
      add_local *sym
    else
      add_local sym
    end
  end
end
gensym() click to toggle source

Generates a new, unique symbol.

# File voodoo/generators/common_code_generator.rb, line 711
def gensym
  Environment.gensym
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.