private static void CompileArguments(ElaIncrementalLinker linker) { for (var i = 0; i < opt.Arguments.Count; i++) { linker.AddArgument(opt.Arguments[i].Name, opt.Arguments[i].Value); } }
public HtmGenerator(ElaProgram prog, Doc doc, ElaIncrementalLinker lnk, ElaMachine vm) { this.prog = prog; this.doc = doc; this.vm = vm; this.lnk = lnk; }
internal void ResetSession() { link = null; if (vm != null) { vm.Dispose(); vm = null; } lastOffset = 0; }
private CompiledAssembly InternalBuild(string source, Document doc, IBuildLogger logger, params ExtendedOption[] options) { logger.WriteBuildInfo("Ela", ElaVersionInfo.Version); var bo = new BuildOptionsManager(App); var lopt = bo.CreateLinkerOptions(); var copt = bo.CreateCompilerOptions(); if (options.Set(ForceRecompile.Code)) { lopt.ForceRecompile = true; } if (!options.Set(NoDebug.Code)) { copt.GenerateDebugInfo = true; } if (options.Set(NoWarnings.Code)) { copt.NoWarnings = true; } logger.WriteBuildOptions("Compiler options: {0}", copt); logger.WriteBuildOptions("Linker options: {0}", lopt); logger.WriteBuildOptions("Module lookup directories:"); lopt.CodeBase.Directories.ForEach(d => logger.WriteBuildOptions(d)); var lnk = new ElaIncrementalLinker(lopt, copt, doc.FileInfo == null ? new ModuleFileInfo(doc.Title) : doc.FileInfo.ToModuleFileInfo()); lnk.ModuleResolve += (o, e) => { //TBD }; var res = lnk.Build(source); var messages = res.Messages.Take(100).ToList(); logger.WriteMessages(messages.Select(m => new MessageItem( m.Type == MessageType.Error ? MessageItemType.Error : (m.Type == MessageType.Warning ? MessageItemType.Warning : MessageItemType.Information), String.Format("ELA{0}: {1}", m.Code, m.Message), m.File == null || !new FileInfo(m.File.FullName).Exists ? doc : new VirtualDocument(new FileInfo(m.File.FullName)), m.Line, m.Column) { Tag = m.Code }) , m => (Int32)m.Tag < 600); //Exclude linker messages return(res.Success ? new CompiledAssembly(doc, res.Assembly) : null); }
internal bool RunCode(string code, bool fastFail = false, bool onlyErrors = false) { if (link == null) { var bo = new BuildOptionsManager(App); link = new ElaIncrementalLinker(bo.CreateLinkerOptions(), bo.CreateCompilerOptions()); } link.SetSource(code.Trim('\0')); var lr = link.Build(); if (!lr.Success && fastFail) { return(false); } foreach (var m in lr.Messages) { if (m.Type == Ela.MessageType.Error || !onlyErrors) { var tag = m.Type == Ela.MessageType.Error ? "``!!!" : m.Type == Ela.MessageType.Warning ? "``|||" : "``???"; Con.PrintLine(String.Format("{0}{1} ({2},{3}): {4} ELA{5}: {6}", tag, m.File.Name, m.Line, m.Column, m.Type, m.Code, m.Message)); } } if (lr.Success) { var th = new Thread(() => ExecuteInput(lr.Assembly)); Con.SetExecControl(th); App.GetService <IStatusBarService>().SetStatusString(StatusType.Information, "Executing code in Interactive..."); th.Start(); return(true); } else { Con.PrintLine(); Con.Print(Con.Prompt + ">"); Con.ScrollToCaret(); return(false); } }
private static int InterpretFile(string fileName) { var res = default(LinkerResult); try { linker = new ElaIncrementalLinker(CreateLinkerOptions(), CreateCompilerOptions(), new ModuleFileInfo(fileName)); if (opt.Arguments.Count > 0) { CompileArguments(linker); } res = linker.Build(); } catch (ElaException ex) { helper.PrintInternalError(ex); return(R_ERR); } helper.PrintErrors(res.Messages); if (!res.Success) { return(R_ERR); } else { var ret = Execute(res.Assembly, false); if (ret == R_OK && opt.LunchInteractive) { StartInteractiveMode(); } return(ret); } }
private static int InterpretString(string source) { if (linker == null) { linker = new ElaIncrementalLinker(CreateLinkerOptions(), CreateCompilerOptions()); if (opt.Arguments.Count > 0) { CompileArguments(linker); } } linker.SetSource(source); var res = linker.Build(); helper.PrintErrors(res.Messages); if (!res.Success) { if (res.Assembly != null) { var r = res.Assembly.GetRootModule(); if (r != null) { lastOffset = r.Ops.Count; } } return(R_ERR); } else { return(Execute(res.Assembly, true)); } }
private static void StartInteractiveMode() { codeLines = new StringBuilder(); helper.PrintPrompt(); var app = String.Empty; for (;;) { var source = app + Console.ReadLine(); if (!String.IsNullOrEmpty(source)) { source = source.Trim('\0'); if (source.Length > 0) { if (source[0] == '#') { var cmd = new InteractiveCommands(vm, helper, opt); var res = cmd.ProcessCommand(source); if (res == InteractiveAction.Reset || res == InteractiveAction.EvalFile) { lastOffset = 0; linker = null; vm = null; } if (res == InteractiveAction.EvalFile) { InterpretFile(cmd.Data); } helper.PrintPrompt(); app = String.Empty; } else { if (!opt.Multiline) { Console.WriteLine(); InterpretString(source); helper.PrintPrompt(); app = String.Empty; } else { if (source.Length >= 2 && source[source.Length - 1] == ';' && source[source.Length - 2] == ';') { codeLines.AppendLine(source.TrimEnd(';')); Console.WriteLine(); InterpretString(codeLines.ToString()); codeLines = new StringBuilder(); helper.PrintPrompt(); app = String.Empty; } else { codeLines.AppendLine(source); helper.PrintSecondaryPrompt(); var indent = IndentHelper.GetIndent(source); app = new String(' ', indent); Console.Write(app); } } } } } } }
static int Run(string file, string outputFile) { Console.Write("\r\nGenerating documentation file: {0}...", outputFile); var fi = new FileInfo(file); var doc = default(Doc); using (var sr = new StreamReader(file)) { var lst = new List <String>(); var line = String.Empty; while ((line = sr.ReadLine()) != null) { lst.Add(line); } var p = new DocParser(); doc = p.Parse(lst.ToArray()); } var gen = default(HtmGenerator); var lopt = new LinkerOptions(); var copt = new CompilerOptions { Prelude = "prelude" }; ConfigurationManager.AppSettings["refs"].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries) .ToList().ForEach(s => lopt.CodeBase.Directories.Add(s)); if (!String.IsNullOrEmpty(doc.File) && doc.File.Trim(' ').Length != 0) { var elaFile = new FileInfo(Path.Combine(fi.DirectoryName, doc.File)); if (!elaFile.Exists) { foreach (var d in lopt.CodeBase.Directories) { elaFile = new FileInfo(Path.Combine(d, doc.File)); if (elaFile.Exists) { break; } } } var elap = new ElaParser(); var res = elap.Parse(elaFile); if (!res.Success) { res.Messages.ToList().ForEach(m => Console.WriteLine("\r\n" + m)); return(-1); } lopt.CodeBase.Directories.Add(elaFile.Directory.FullName); var lnk = new ElaIncrementalLinker(lopt, copt, new ModuleFileInfo(elaFile.FullName)); var lres = lnk.Build(); if (!lres.Success) { lres.Messages.ToList().ForEach(m => Console.Write("\r\n" + m)); return(-1); } var vm = new ElaMachine(lres.Assembly); vm.Run(); gen = new HtmGenerator(res.Program, doc, lnk, vm); } else { var lnk = new ElaIncrementalLinker(lopt, copt); gen = new HtmGenerator(null, doc, lnk, null); } var src = gen.Generate(); var outFi = new FileInfo(outputFile); if (!outFi.Directory.Exists) { outFi.Directory.Create(); } using (var fs = new StreamWriter(File.Create(outputFile))) fs.Write(src); Console.Write(" Done"); return(0); }
private static void StartInteractiveMode() { codeLines = new StringBuilder(); helper.PrintPrompt(); var app = String.Empty; for (;;) { var source = app + Console.ReadLine(); if (!String.IsNullOrEmpty(source)) { source = source.Trim('\0'); if (source.Length > 0) { if (source[0] == '#') { var cmd = new InteractiveCommands(vm, helper, opt); var res = cmd.ProcessCommand(source); if (res == InteractiveAction.Reset || res == InteractiveAction.EvalFile) { lastOffset = 0; linker = null; vm = null; } if (res == InteractiveAction.EvalFile) InterpretFile(cmd.Data); helper.PrintPrompt(); app = String.Empty; } else { if (!opt.Multiline) { Console.WriteLine(); InterpretString(source); helper.PrintPrompt(); app = String.Empty; } else { if (source.Length >= 2 && source[source.Length - 1] == ';' && source[source.Length - 2] == ';') { codeLines.AppendLine(source.TrimEnd(';')); Console.WriteLine(); InterpretString(codeLines.ToString()); codeLines = new StringBuilder(); helper.PrintPrompt(); app = String.Empty; } else { codeLines.AppendLine(source); helper.PrintSecondaryPrompt(); var indent = IndentHelper.GetIndent(source); app = new String(' ', indent); Console.Write(app); } } } } } } }
private static int InterpretString(string source) { if (linker == null) { linker = new ElaIncrementalLinker(CreateLinkerOptions(), CreateCompilerOptions()); if (opt.Arguments.Count > 0) CompileArguments(linker); } linker.SetSource(source); var res = linker.Build(); helper.PrintErrors(res.Messages); if (!res.Success) { if (res.Assembly != null) { var r = res.Assembly.GetRootModule(); if (r != null) lastOffset = r.Ops.Count; } return R_ERR; } else return Execute(res.Assembly, true); }
private static int InterpretFile(string fileName) { var res = default(LinkerResult); try { linker = new ElaIncrementalLinker(CreateLinkerOptions(), CreateCompilerOptions(), new FileInfo(fileName)); if (opt.Arguments.Count > 0) CompileArguments(linker); res = linker.Build(); } catch (ElaException ex) { helper.PrintInternalError(ex); return R_ERR; } helper.PrintErrors(res.Messages); if (!res.Success) return R_ERR; else { var ret = Execute(res.Assembly, false); if (ret == R_OK && opt.LunchInteractive) StartInteractiveMode(); return ret; } }
private static void CompileArguments(ElaIncrementalLinker linker) { for (var i = 0; i < opt.Arguments.Count; i++) linker.AddArgument(opt.Arguments[i].Name, opt.Arguments[i].Value); }