示例#1
0
        public LOLMethod(FunctionRef info, LOLProgram prog)
        {
            this.info = info;
            this.args = new ArgumentRef[info.Arity + (info.IsVariadic ? 1 : 0)];
            this.program = prog;
            this.locals = new Scope(prog.globals);

            LocalRef it = new LocalRef("IT");
            locals.AddSymbol(it);
        }
示例#2
0
        public LOLMethod(FunctionRef info, LOLProgram prog)
        {
            this.info    = info;
            this.args    = new ArgumentRef[info.Arity + (info.IsVariadic ? 1 : 0)];
            this.program = prog;
            this.locals  = new Scope(prog.globals);

            LocalRef it = new LocalRef("IT");

            locals.AddSymbol(it);
        }
        private CompilerResults CompileAssemblyFromStreamBatch(CompilerParameters options, string[] filenames, Stream[] streams)
        {
            AssemblyName name = new AssemblyName();

            name.Name = Path.GetFileName(options.OutputAssembly);

            AssemblyBuilder ab = Thread.GetDomain().DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave);

            if (options.IncludeDebugInformation)
            {
                ConstructorInfo        daCtor    = typeof(DebuggableAttribute).GetConstructor(new Type[] { typeof(DebuggableAttribute.DebuggingModes) });
                CustomAttributeBuilder daBuilder = new CustomAttributeBuilder(daCtor, new object[] { DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations });
                ab.SetCustomAttribute(daBuilder);
            }

            ModuleBuilder mb = ab.DefineDynamicModule(Path.GetFileName(options.OutputAssembly), options.IncludeDebugInformation);

            CompilerResults ret = new CompilerResults(options.TempFiles);

            LOLProgram prog = new LOLProgram(options);

            for (int i = 0; i < streams.Length; i++)
            {
                if (!streams[i].CanSeek)
                {
                    throw new ArgumentException("Streams passed to CompileAssemblyFromStream[Batch] must be seekable");
                }

                LOLCode.Parser.Pass1.Parser pass1 = notdot.LOLCode.Parser.Pass1.Parser.GetParser(prog, filenames[i], streams[i], ret);
                pass1.Parse();
                if (ret.Errors.HasErrors)
                {
                    return(ret);
                }

                streams[i].Seek(0, SeekOrigin.Begin);

                LOLCode.Parser.v1_2.Parser p = LOLCode.Parser.v1_2.Parser.GetParser(mb, prog, filenames[i], streams[i], ret);
                p.Parse();
                if (ret.Errors.HasErrors)
                {
                    return(ret);
                }
            }

            MethodInfo entryMethod = prog.Emit(ret.Errors, mb);

            if (ret.Errors.HasErrors)
            {
                return(ret);
            }

            ab.SetEntryPoint(entryMethod);

            if (!options.GenerateInMemory)
            {
                ab.Save(options.OutputAssembly);
            }

            ret.CompiledAssembly = ab;

            return(ret);
        }
        private CompilerResults CompileAssemblyFromStreamBatch(CompilerParameters options, string[] filenames, Stream[] streams)
        {
            AssemblyName name = new AssemblyName();
            name.Name = Path.GetFileName(options.OutputAssembly);

            AssemblyBuilder ab = Thread.GetDomain().DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave);

            if (options.IncludeDebugInformation)
            {
                ConstructorInfo daCtor = typeof(DebuggableAttribute).GetConstructor(new Type[] { typeof(DebuggableAttribute.DebuggingModes) });
                CustomAttributeBuilder daBuilder = new CustomAttributeBuilder(daCtor, new object[] { DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations });
                ab.SetCustomAttribute(daBuilder);
            }

            ModuleBuilder mb = ab.DefineDynamicModule(Path.GetFileName(options.OutputAssembly), options.IncludeDebugInformation);

            CompilerResults ret = new CompilerResults(options.TempFiles);

            LOLProgram prog = new LOLProgram(options);
            for (int i = 0; i < streams.Length; i++)
            {
                if (!streams[i].CanSeek)
                    throw new ArgumentException("Streams passed to CompileAssemblyFromStream[Batch] must be seekable");

                LOLCode.Parser.Pass1.Parser pass1 = notdot.LOLCode.Parser.Pass1.Parser.GetParser(prog, filenames[i], streams[i], ret);
                pass1.Parse();
                if (ret.Errors.HasErrors)
                    return ret;

                streams[i].Seek(0, SeekOrigin.Begin);

                LOLCode.Parser.v1_2.Parser p = LOLCode.Parser.v1_2.Parser.GetParser(mb, prog, filenames[i], streams[i], ret);
                p.Parse();
                if (ret.Errors.HasErrors)
                    return ret;
            }

            MethodInfo entryMethod = prog.Emit(ret.Errors, mb);
            if (ret.Errors.HasErrors)
                return ret;

            ab.SetEntryPoint(entryMethod);

            if (!options.GenerateInMemory)
                ab.Save(options.OutputAssembly);

            ret.CompiledAssembly = ab;

            return ret;
        }