Esempio n. 1
0
        static void Main(string[] args)
        {
            char[] options = args.Where(x => x.StartsWith("-")).SelectMany(x => x.Substring(1).ToCharArray()).ToArray();
            args = args.Where(x => !x.StartsWith("-")).ToArray();
            if (args.Length < 2)
            {
                Console.WriteLine("Autolithium command line tool : ");
                Console.WriteLine("Autolithium.compiler.exe \"MainSource.aul\" \"DestinationFile.(exe or dll)\" [Optional] \"Destination plateform\" [Default : Win]");
                Console.WriteLine("Options: ");
                Console.WriteLine("\t- -r : run after generation");
                Console.Write("Press any key to exit...");
                Console.ReadKey();
                return;
            }
            string Script   = File.ReadAllText(args[0]);
            var    Compiled = AppDomain.CurrentDomain.DefineDynamicAssembly(
                new AssemblyName("Autolithium-" + Path.GetFileName(args[1])), // call it whatever you want
                AssemblyBuilderAccess.Save);

            var dm = Compiled.DefineDynamicModule("MainModule", Path.GetFileName(args[1]));

            List <Assembly> Include = new List <Assembly>()
            {
                ASMInclude.IncludeDLL(dm, @"Autolithium.core.dll", "dyn_type")
            };

            if (args.Length < 3)
            {
                Array.Resize(ref args, 3); args[2] = "win";
            }
            switch (args[2].ToLower())
            {
            case "win":
                Include.Add(ASMInclude.IncludeDLL(dm, @"Autolithium.ion.dll", "dyn_type"));
                Include.Add(ASMInclude.RequireNetFXASM("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
                Include.Add(ASMInclude.RequireNetFXASM("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
                break;
            }
            var Main = CompileMain(dm, Script, Include.ToArray());

            if (Main != null)
            {
                Compiled.SetEntryPoint(Main);
            }
            Compiled.Save(args[1]);
            if (options.Contains('r'))
            {
                System.Diagnostics.Process.Start(args[1]);
            }
        }
Esempio n. 2
0
        public static MethodBuilder CompileMain(ModuleBuilder M, string Script, params Assembly[] References)
        {
            var           T = M.DefineType("Autolithium-" + Script.GetHashCode());
            MethodBuilder DelegateBinder = T.DefineMethod("&=.DelegateBinder", MethodAttributes.Static);

            ASMInclude.ResxLoader(T, DelegateBinder);

            var ASMScope = new AssemblyScope(M, T);
            var lambda   = LiParser.Parse(
                Script,
                ASMScope,
                References);

            ASMInclude.GenerateDelegateBinder(DelegateBinder, ASMScope.ScopeFunctions);
            MethodBuilder Method = null;

            if (lambda != null)
            {
                Method = T.DefineMethod("Autolithium-Main", MethodAttributes.Public | MethodAttributes.Static, typeof(int), new Type[] { typeof(string[]) });
                lambda.CompileToMethod(Method);
            }
            T.CreateType();
            return(Method);
        }