private int RunFileInNewModule(string fileName, string moduleName, bool skipLine, out bool exitRaised) { CompilerContext context = new CompilerContext(fileName); Parser p = Parser.FromFile(engineContext.SystemState, context, skipLine, false); Stmt s = p.ParseFileInput(); PythonModule mod = OutputGenerator.GenerateModule(engineContext.SystemState, context, s, moduleName); Sys.modules[mod.ModuleName] = mod; engineContext.ResetModule(mod); mod.SetAttr(engineContext, SymbolTable.File, fileName); exitRaised = false; try { mod.Initialize(); } catch (PythonSystemExit e) { exitRaised = true; return(e.GetExitCode(engineContext)); } return(0); }
public int RunFile(string fileName) { Parser p = Parser.FromFile(engineContext.SystemState, context.CopyWithNewSourceFile(fileName)); Stmt s = p.ParseFileInput(); string moduleName = "tmp" + counter++; PythonModule mod = OutputGenerator.GenerateModule(engineContext.SystemState, p.CompilerContext, s, moduleName); foreach (KeyValuePair <SymbolId, object> name in engineContext.Module.__dict__.SymbolAttributes) { mod.SetAttr(engineContext, name.Key, name.Value); } mod.SetAttr(engineContext, SymbolTable.File, fileName); try { mod.Initialize(); } catch (PythonSystemExit e) { return(e.GetExitCode(engineContext)); } return(0); }