Exemple #1
0
 public void Set(string name, object value)
 {
     if (globalNames.ContainsKey(name))
     {
         globals.SetAttr(DefaultContext.Default, SymbolTable.StringToId(name), value);
     }
     else
     {
         Ops.SetIndex(locals, name, value);
     }
 }
Exemple #2
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);
        }
Exemple #3
0
        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);
        }