Object
Used for scoping. Maintains a symbol table and keeps track of the number of bytes that have been allocated on the stack.
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
Returns an initial, top-level environment.
# File voodoo/generators/common_code_generator.rb, line 727 def self.initial_environment Environment.new end
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
Looks up symbol in this environment.
# File voodoo/generators/common_code_generator.rb, line 716 def [] symbol @symbols[symbol] end
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
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
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
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
Generated with the Darkfish Rdoc Generator 2.