예제 #1
0
 public override void Compile(ILGenerator il)
 {
     foreach (Variable arg in ValueArguments)
     {
         SymbolTable.DefineArgument(arg.Name);
     }
     if (HasResultArgument)
     {
         SymbolTable.DefineResultArgument(ResultArgument.Name);
     }
     EmitDebugInfo(il, 0, true);
     Statements.Compile(il);
     EmitDebugInfo(il, 1, true);
     il.Emit(OpCodes.Ret);
     SymbolTable.Clear();
 }
예제 #2
0
        public void Compile(string filename)
        {
            AssemblyName    name     = new AssemblyName(filename);
            AssemblyBuilder assembly = Thread.GetDomain().DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave);

            Node.Module = assembly.DefineDynamicModule(filename, Options.Debug);
            MethodBuilder mainMethod = Module.DefineGlobalMethod("Main", MethodAttributes.HideBySig | MethodAttributes.Static | MethodAttributes.Public, typeof(void), new Type[] { });

            if (Options.Debug)
            {
                Node.DebugWriter = Module.DefineDocument(Options.InputFilename, Guid.Empty, Guid.Empty, SymDocumentType.Text);
            }

            Procedures.Compile(null);

            ILGenerator il = mainMethod.GetILGenerator();

            if (Options.BookVersion)
            {
                SymbolTable.PushScope();
            }

            if (SequencePoints.Count > 0)   //Make possible to start on "begin" statement
            {
                EmitDebugInfo(il, 0, true);
            }

            Statements.Compile(il);
            if (SequencePoints.Count > 0)   //Make possible to end on "end" statement
            {
                EmitDebugInfo(il, 1, true);
            }
            il.Emit(OpCodes.Ret);


            Module.CreateGlobalFunctions();
            assembly.SetEntryPoint(mainMethod, PEFileKinds.ConsoleApplication);
            if (Options.Debug)
            {
                Module.SetUserEntryPoint(mainMethod);
            }
            assembly.Save(filename);
        }