//This step compiles instances - this should be done after types (as soon as instances //reference types) and after the first step as well (as soon as instances reference type classes //and can reference any other local and non-local names). It is important however to compile //instances before any user typeId gets executed because they effectively mutate function tables. private void ProcessInstances(ElaProgram prog, LabelMap map) { if (prog.Instances != null) { CompileInstances(prog.Instances, map); } }
public CompilerResult Compile(ElaProgram prog, CompilerOptions options, ExportVars builtins, CodeFrame frame, Scope globalScope) { Options = options; var helper = new Builder(frame, this, builtins, globalScope); try { helper.CompileUnit(prog); } catch (TerminationException) { //Nothing should be done here. This was thrown to stop compilation. } #if !DEBUG catch (Exception ex) { if (ex is ElaCompilerException) { throw; } throw new ElaCompilerException(Strings.GetMessage("Ice", ex.Message), ex); } #endif frame.Symbols = frame.Symbols == null ? helper.Symbols : helper.Symbols != null?frame.Symbols.Merge(helper.Symbols) : frame.Symbols; frame.GlobalScope = globalScope; return(new CompilerResult(frame, helper.Success, helper.Errors.ToArray())); }
public HtmGenerator(ElaProgram prog, Doc doc, ElaIncrementalLinker lnk, ElaMachine vm) { this.prog = prog; this.doc = doc; this.vm = vm; this.lnk = lnk; }
//An entry method for includes compilation private void CompileModuleIncludes(ElaProgram prog, LabelMap map) { var inc = prog.Includes; for (var i = 0; i < inc.Count; i++) { CompileModuleInclude(inc[i], map); } }
//Main compilation method that runs compilation in seven steps by rewriting binding order. private void CompileProgram(ElaProgram prog, LabelMap map) { ProcessIncludesClassesTypes(prog, map); var list = RunForwardDeclaration(prog.TopLevel.Equations, map); list = ProcessFunctions(list, map); ProcessInstances(prog, map); list = ProcessBindings(list, map); ProcessExpressions(list, map); }
//Type class declarations, modules includes and type declarations can be compiled in the first place. private void ProcessIncludesClassesTypes(ElaProgram prog, LabelMap map) { CompileModuleIncludes(prog, map); if (prog.Classes != null) { CompileClass(prog.Classes, map); } if (prog.Types != null) { CompileTypes(prog.Types, map); } }
//Includes Prelude module private void IncludePrelude(ElaProgram prog, bool addVariable) { IncludeModule( options.Prelude, //alias options.Prelude, //name null, //dllname null, //path 0, //line 0, //col false, //qualified prog.TopLevel, //ElaExpression addVariable, //add variable true); //NoPrelude }
public CompilerResult Compile(ElaProgram prog, CompilerOptions options, ExportVars builtins) { var frame = new CodeFrame(); return(Compile(prog, options, builtins, frame, new Scope(false, null))); }
internal AstTreeBuilder(ElaProgram root) { this.root = root; }
//Entry point internal void CompileUnit(ElaProgram prog) { frame.Layouts.Add(new MemoryLayout(0, 0, 1)); //top level layout cw.StartFrame(0); //Handles and references should be of the same length. This might not //be the case, if we are resuming in interactive mode. We should "align" them, //so they are of the same length. if (refs.Count != frame.HandleMap.Count) { for (var i = 0; i < frame.HandleMap.Count; i++) { refs.Add(null); } } //Determine whether this is fresh session. var scratch = cw.Offset == 0; //We always include prelude, but a module variable is created just once //(We check if we are not resuming in interactive mode (cw.Offset==0) and if yes //we don't create a variable 'prelude'. if (!String.IsNullOrEmpty(options.Prelude) && scratch) { IncludePrelude(prog, scratch); } //Always include arguments module if (scratch) { IncludeArguments(); } //Another workaround that is needed for interactive mode. We need //to restore a reference list with correct indices (LogicalHandle). //It can be done by working through the reference map and requesting all referenced //modules one more time. if (cw.Offset != 0) { var arr = new ModuleReference[frame.References.Count]; foreach (var kv in frame.References) { arr[kv.Value.LogicalHandle] = kv.Value; } for (var i = 0; i < arr.Length; i++) { var e = new ModuleEventArgs(arr[i]); comp.OnModuleInclude(e); refs[i] = e.Frame; } } var map = new LabelMap(); //Main compilation routine CompileProgram(prog, map); //Forcing evaluation of a program retval cw.Emit(Op.Force); //Every Ela module should end with a Stop op typeId cw.Emit(Op.Stop); cw.CompileOpList(); frame.Layouts[0].Size = currentCounter; frame.Layouts[0].StackSize = cw.FinishFrame(); }
internal ParserResult(ElaProgram prog, bool success, IEnumerable <ElaMessage> messages) : base(success, messages) { Program = prog; }