[pypy-svn] r10016 - pypy/dist/pypy/interpreter

pedronis at codespeak.net pedronis at codespeak.net
Mon Mar 21 21:03:38 CET 2005


Author: pedronis
Date: Mon Mar 21 21:03:37 2005
New Revision: 10016

Modified:
   pypy/dist/pypy/interpreter/interactive.py
   pypy/dist/pypy/interpreter/main.py
Log:
let's interactive console and run func share one __main__ module.



Modified: pypy/dist/pypy/interpreter/interactive.py
==============================================================================
--- pypy/dist/pypy/interpreter/interactive.py	(original)
+++ pypy/dist/pypy/interpreter/interactive.py	Mon Mar 21 21:03:37 2005
@@ -1,7 +1,7 @@
 import autopath
 
 from pypy.interpreter import error
-from pypy.interpreter import executioncontext, baseobjspace, module
+from pypy.interpreter import executioncontext, baseobjspace, module, main
 import sys
 import code
 import time
@@ -15,11 +15,8 @@
         self.ec = executioncontext.ExecutionContext(self.space)
 
         space=self.space
-        w_main = space.wrap('__main__')
-        mainmodule = module.Module(space, w_main)
-        w_modules = space.sys.get('modules')
-        space.setitem(w_modules, w_main, mainmodule)
 
+        mainmodule = main.ensure__main__(space)
         self.w_globals = mainmodule.w_dict
         space.setitem(self.w_globals, space.wrap('__builtins__'), space.builtin)
         # XXX check: do we need self.ec, self.w_globals?

Modified: pypy/dist/pypy/interpreter/main.py
==============================================================================
--- pypy/dist/pypy/interpreter/main.py	(original)
+++ pypy/dist/pypy/interpreter/main.py	Mon Mar 21 21:03:37 2005
@@ -3,6 +3,18 @@
 from pypy.interpreter.error import OperationError
 import sys
 
+def ensure__main__(space):
+    w_main = space.wrap('__main__')
+    w_modules = space.sys.get('modules')
+    try:
+        return space.getitem(w_modules, w_main)
+    except OperationError, e:
+        if not e.match(space, space.w_KeyError):
+            raise
+    mainmodule = module.Module(space, w_main)
+    space.setitem(w_modules, w_main, mainmodule)
+    return mainmodule
+
 def _run_eval_string(source, filename, space, eval):
     if eval:
         cmd = 'eval'
@@ -17,12 +29,10 @@
         w = space.wrap
         w_code = space.builtin.call('compile', 
                  w(source), w(filename), w(cmd), w(0), w(0))
-        w_main = space.wrap('__main__')
-        mainmodule = module.Module(space, w_main)
-        w_modules = space.sys.get('modules')
-        space.setitem(w_modules, w_main, mainmodule)
 
+        mainmodule = ensure__main__(space)
         w_globals = mainmodule.w_dict
+
         space.setitem(w_globals, w('__builtins__'), space.builtin)
 
         pycode = space.interpclass_w(w_code)



More information about the Pypy-commit mailing list