public bool Compile(string fileName, out Unit unit) { unit = null; var made = default(Result <Unit>); try { var buffer = SourceBuffer.FromFile(fileName); made = Linker.Compile(buffer); } catch (Exception ex) { Printer.Error($"Unable to read file \"{fileName}\": {ex.Message}"); return(false); } if (made.Messages.Any()) { Printer.PrintErrors(made.Messages); } if (!made.Success) { return(false); } unit = made.Value; return(true); }
private static IList <FunSet> Compile(IEnumerable <string> files, BuilderOptions buildOptions, out List <BuildMessage> warns) { var funColl = new List <FunSet>(); warns = new List <BuildMessage>(); foreach (var file in files) { var linker = new DyLinker(FileLookup.Create(Path.GetDirectoryName(file)), buildOptions); var cres = linker.Make(SourceBuffer.FromFile(file)); var funs = new FunSet(); funs.Funs = new Dictionary <string, DyFunction>(StringComparer.OrdinalIgnoreCase); funs.FileName = file; if (!cres.Success) { throw new DyBuildException(cres.Messages); } warns.AddRange(cres.Messages.Where(m => m.Type == BuildMessageType.Warning)); var ctx = DyMachine.CreateExecutionContext(cres.Value); funs.Context = ctx; DyMachine.Execute(ctx); foreach (var v in DyMachine.DumpVariables(ctx)) { if (v.Value is DyFunction fn) { funs.Funs.Remove(v.Name); funs.Funs.Add(v.Name, fn); } } funColl.Add(funs); } return(funColl); }