public static void DumpSnippets() { if (Options.SaveAndReloadBinaries) { snippetAssembly.Dump(); } snippetAssembly = CreateNewSnippetAssembly(); }
internal static TypeGen GenerateModuleType(string moduleName, AssemblyGen ag) { TypeGen tg = ag.DefinePublicType(moduleName, typeof(CustomFieldIdDict)); tg.AddModuleField(typeof(PythonModule)); tg.DefaultConstructor = tg.myType.DefineDefaultConstructor(MethodAttributes.Public); return(tg); }
private static PythonModule DoGenerateModule(SystemState state, CompilerContext context, GlobalSuite gs, string moduleName, string sourceFileName, string outSuffix) { string fullPath; string outDir; string fileName; if (sourceFileName == "<stdin>") { fullPath = Environment.CurrentDirectory; outDir = Environment.CurrentDirectory; fileName = "__stdin__"; } else { fullPath = Path.GetFullPath(sourceFileName); outDir = Options.BinariesDirectory == null?Path.GetDirectoryName(fullPath) : Options.BinariesDirectory; fileName = Path.GetFileNameWithoutExtension(sourceFileName); } AssemblyGen ag = new AssemblyGen(moduleName + outSuffix, outDir, fileName + outSuffix + ".exe", true); ag.SetPythonSourceFile(fullPath); TypeGen tg = GenerateModuleType(moduleName, ag); CodeGen cg = GenerateModuleInitialize(context, gs, tg); CodeGen main = GenerateModuleEntryPoint(tg, cg, moduleName, null); ag.SetEntryPoint(main.MethodInfo, PEFileKinds.ConsoleApplication); Type ret = tg.FinishType(); Assembly assm = ag.DumpAndLoad(); ret = assm.GetType(moduleName); CustomFieldIdDict dict = (CustomFieldIdDict)ret.GetConstructor(Type.EmptyTypes).Invoke(new object[0]); InitializeModule init = (InitializeModule)Delegate.CreateDelegate( typeof(InitializeModule), dict, "Initialize"); PythonModule pmod = new PythonModule(moduleName, dict, state, init); pmod.InitializeBuiltins(); return(pmod); }
public TypeGen(AssemblyGen myAssembly, TypeBuilder myType) { this.myAssembly = myAssembly; this.myType = myType; //!!!AddModuleField(myType); }