// Build prototype. LuaPrototype BuildPrototype(LuaAST LuaAST) { // Enter block. block = new BlockBuilder(block, LuaAST.Block, 0); // Enter function. function = new FunctionBuilder(function, LuaAST, block); for (int parameter = 0; parameter < LuaAST.Parameters.Count; ++parameter) { function.DeclareLocal(LuaAST.Parameters[parameter]); } BuildBlock(LuaAST.Block); for (int parameter = LuaAST.Parameters.Count - 1; parameter >= 0; --parameter) { function.RetireLocal(LuaAST.Parameters[parameter]); } // End function. LuaPrototype prototype = function.Build(); function = function.Parent; // End of block. block = block.Parent; return(prototype); }
// Compiling. public static LuaPrototype Compile(TextWriter errorWriter, TextReader sourceReader, string sourceName) { // Parse the function. LuaAST LuaAST = LuaParser.Parse(errorWriter, sourceReader, sourceName); if (LuaAST == null) { return(null); } // Compile. BytecodeCompiler compiler = new BytecodeCompiler(sourceName); LuaPrototype prototype = compiler.BuildPrototype(LuaAST); return(prototype); }
public FunctionBuilder(FunctionBuilder parent, LuaAST function, BlockBuilder functionBlock) { Parent = parent; Function = function; constants = new List <object>(); prototypes = new List <LuaPrototype>(); instructions = new List <Instruction>(); instructionSourceSpans = new List <SourceSpan>(); labels = new Dictionary <Label, int>(); patchLabels = new Dictionary <Label, Patch>(); locals = new Dictionary <Variable, int>(); debugLocals = new List <Symbol>(); localTop = 0; top = 0; watermark = 0; }
public FunctionClosure(SourceSpan s, LuaAST function) : base(s) { Function = function; }