Ejemplo n.º 1
0
        public static void Evaluate(CmdArgs args)
        {
#if DEBUG
            ErrorReporter.ThrowExceptions = true;
#endif
            ErrorReporter.Init();

            // All the files are processed together
            var AllFunctions        = new List <FunctionNode>();
            var AllGenericFunctions = new List <FunctionNode>();
            var AllTypes            = new List <TypeDefinitionNode>();

            var GlobalTypeTable = new TypeTable();

            foreach (var v in args.Files)
            {
                var(fs, genericfs, ts) = BuildAST(Parse(v), ref GlobalTypeTable);
                AllFunctions.AddRange(fs);
                AllGenericFunctions.AddRange(genericfs);
                AllTypes.AddRange(ts);
            }

            // Update allfunctions with potentially new functions
            AllFunctions =
                TypeCheck((AllFunctions, AllGenericFunctions, AllTypes), ref GlobalTypeTable);

            Optimize(AllFunctions);

            using (var h_output = new StreamWriter(File.Open(Path.Combine(args.BuildDir, args.Module + ".h"), FileMode.Create, FileAccess.ReadWrite)))
            {
                h_output.WriteLine("#ifndef _{0}_h", args.Module);
                h_output.WriteLine("#define _{0}_h", args.Module);

                foreach (var i in args.Imports.Split(','))
                {
                    if (i.StartsWith("std.", 0))
                    {
                        h_output.WriteLine("#include \"../dist/std/{0}.h\"", i.Substring(4));
                    }
                    else
                    {
                        h_output.WriteLine("#include \"{0}\"", i + ".h");
                    }
                }

                CompileHeader((AllFunctions, AllTypes), h_output);
                h_output.WriteLine("#endif");
            }

            using (var c_output = new StreamWriter(File.Open(Path.Combine(args.BuildDir, args.Module + ".c"), FileMode.Create, FileAccess.ReadWrite)))
            {
                c_output.WriteLine("#include \"{0}\"", args.Module + ".h");
                Compile((AllFunctions, AllTypes), c_output);
            }

            using (var fh_output = new StreamWriter(File.Open(Path.Combine(args.BuildDir, args.Module + ".fh"), FileMode.Create, FileAccess.ReadWrite)))
            {
                CompileFHeader((AllFunctions, AllTypes), fh_output);
            }
        }