public IList <CompileError> Compile(Stream outputStream) { var errors = new List <CompileError>(); try { // parse all the source files foreach (var path in mSourcePaths) { SourceFile source = MagpieParser.ParseSourceFile(path); AddNamespace(source.Name, source, source); } // build the function table mFunctions.AddRange(Intrinsic.All); mFunctions.AddRange(Intrinsic.AllGenerics); // bind the user-defined types and create their auto-generated functions mTypes.BindAll(); foreach (var structure in mTypes.Structs) { mFunctions.AddRange(structure.BuildFunctions()); } foreach (var union in mTypes.Unions) { mFunctions.AddRange(union.BuildFunctions()); } foreach (var structure in mTypes.GenericStructs) { mFunctions.AddRange(structure.BuildFunctions()); } foreach (var union in mTypes.GenericUnions) { mFunctions.AddRange(union.BuildFunctions()); } if (mForeignInterface != null) { mFunctions.AddRange(mForeignInterface.Functions.Cast <ICallable>()); } mFunctions.BindAll(); } catch (CompileException ex) { errors.Add(new CompileError(CompileStage.Compile, ex.Position, ex.Message)); } if (errors.Count == 0) { BytecodeFile file = new BytecodeFile(this); file.Save(outputStream); } return(errors); }
public static SourceFile ParseSourceFile(string filePath) { // chain the parsing passes together var scanner = new Scanner(filePath, File.ReadAllText(filePath)); var lineProcessor = new LineProcessor(scanner); var parser = new MagpieParser(lineProcessor); return parser.SourceFile(); }
public static SourceFile ParseSourceFile(string filePath) { // chain the parsing passes together var scanner = new Scanner(filePath, File.ReadAllText(filePath)); var lineProcessor = new LineProcessor(scanner); var parser = new MagpieParser(lineProcessor); return(parser.SourceFile()); }