[pypy-svn] rev 463 - in pypy/trunk/src/pypy: interpreter module objspace/std

arigo at codespeak.net arigo at codespeak.net
Mon May 26 17:43:36 CEST 2003


Author: arigo
Date: Mon May 26 17:43:35 2003
New Revision: 463

Modified:
   pypy/trunk/src/pypy/interpreter/appfile.py
   pypy/trunk/src/pypy/interpreter/baseobjspace.py
   pypy/trunk/src/pypy/interpreter/extmodule.py
   pypy/trunk/src/pypy/interpreter/main.py
   pypy/trunk/src/pypy/interpreter/pyframe.py
   pypy/trunk/src/pypy/module/builtin.py
   pypy/trunk/src/pypy/objspace/std/objspace.py
Log:
builtin_app.py is now loaded

Modified: pypy/trunk/src/pypy/interpreter/appfile.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/appfile.py	(original)
+++ pypy/trunk/src/pypy/interpreter/appfile.py	Mon May 26 17:43:35 2003
@@ -35,10 +35,12 @@
 
 class Namespace:
 
-    def __init__(self, space):
+    def __init__(self, space, w_namespace=None):
         self.space = space
         ec = space.getexecutioncontext()
-        self.w_namespace = ec.make_standard_w_globals()
+        if w_namespace is None:
+            w_namespace = ec.make_standard_w_globals()
+        self.w_namespace = w_namespace
 
     def get(self, objname):
         "Returns a wrapped copy of an object by name."
@@ -68,6 +70,6 @@
 
 class AppHelper(Namespace):
 
-    def __init__(self, space, bytecode):
-        Namespace.__init__(self, space)
-        self.runbytecode(bytecode)
+    def __init__(self, space, appfile, w_namespace=None):
+        Namespace.__init__(self, space, w_namespace)
+        self.runbytecode(appfile.bytecode)

Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/trunk/src/pypy/interpreter/baseobjspace.py	Mon May 26 17:43:35 2003
@@ -17,6 +17,7 @@
 
     def __init__(self):
         "Basic initialization of objects."
+        self.w_builtins = self.newdict([]) #temporary! changed by make_builtins()
         self.w_modules = self.newdict([])
         self.appfile_helpers = {}
         self.initialize()
@@ -48,7 +49,7 @@
             helper = self.appfile_helpers[applicationfile]
         except KeyError:
             from appfile import AppHelper
-            helper = AppHelper(self, applicationfile.bytecode)
+            helper = AppHelper(self, applicationfile)
             self.appfile_helpers[applicationfile] = helper
         return helper
 

Modified: pypy/trunk/src/pypy/interpreter/extmodule.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/extmodule.py	(original)
+++ pypy/trunk/src/pypy/interpreter/extmodule.py	Mon May 26 17:43:35 2003
@@ -1,4 +1,5 @@
 from pycode import PyBaseCode
+from appfile import AppHelper
 
 class appmethod(object):
     def __init__(self, func):
@@ -45,6 +46,7 @@
 
 
 class BuiltinModule:
+    __appfile__ = None
 
     def __init__(self, space):
         self.space = space
@@ -61,4 +63,8 @@
             elif isinstance(value, appdata):
                 w_data = space.wrap(value.data)
                 space.setattr(w_module, space.wrap(key), w_data)
+        appfile = self.__appfile__
+        if appfile:
+            w_dict = space.getattr(w_module, space.wrap("__dict__"))
+            AppHelper(space, appfile, w_dict)
         return w_module

Modified: pypy/trunk/src/pypy/interpreter/main.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/main.py	(original)
+++ pypy/trunk/src/pypy/interpreter/main.py	Mon May 26 17:43:35 2003
@@ -4,6 +4,7 @@
 import sys
 
 def run_string(source, fname):
+    space = None   # in case StdObjSpace.__init__() crashes
     try:
         space = StdObjSpace()
 
@@ -40,6 +41,8 @@
     try:
         run_file(argv[1])
     except baseobjspace.PyPyError, pypyerr:
+        if pypyerr.space is None:
+            raise pypyerr.operationerr   # does anyone have a better idea?
         pypyerr.operationerr.print_detailed_traceback(pypyerr.space)
     except baseobjspace.OperationError, operationerr:
         operationerr.print_detailed_traceback(operationerr.space)

Modified: pypy/trunk/src/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/pyframe.py	(original)
+++ pypy/trunk/src/pypy/interpreter/pyframe.py	Mon May 26 17:43:35 2003
@@ -145,7 +145,12 @@
         # initialize self.w_builtins.  This cannot be done in the '.app.py'
         # file for bootstrapping reasons.
         w_builtinsname = self.space.wrap("__builtins__")
-        w_builtins = self.space.getitem(self.w_globals, w_builtinsname)
+        try:
+            w_builtins = self.space.getitem(self.w_globals, w_builtinsname)
+        except OperationError, e:
+            if not e.match(self.space, self.space.w_KeyError):
+                raise
+            w_builtins = self.space.w_builtins  # fall-back for bootstrapping
         # w_builtins can be a module object or a dictionary object.
         # In frameobject.c we explicitely check if w_builtins is a module
         # object.  Here we will just try to read its __dict__ attribute and

Modified: pypy/trunk/src/pypy/module/builtin.py
==============================================================================
--- pypy/trunk/src/pypy/module/builtin.py	(original)
+++ pypy/trunk/src/pypy/module/builtin.py	Mon May 26 17:43:35 2003
@@ -1,5 +1,6 @@
 from pypy.interpreter.extmodule import *
 from pypy.interpreter.pycode import PyByteCode
+from pypy.interpreter.appfile import AppFile
 from pypy.interpreter.executioncontext import OperationError
 
 #######################
@@ -10,6 +11,7 @@
 
 class Builtin(BuiltinModule):
     __pythonname__ = '__builtin__'
+    __appfile__ = AppFile(__name__, ["module"])
 
     def chr(self, w_ascii):
         w_character = self.space.newstring([w_ascii])

Modified: pypy/trunk/src/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/objspace.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/objspace.py	Mon May 26 17:43:35 2003
@@ -27,17 +27,21 @@
         self.w_None  = W_NoneObject()
         self.w_False = W_BoolObject(False)
         self.w_True  = W_BoolObject(True)
-        self.make_builtins()
         # hack in the exception classes
         import __builtin__, types
+        newstuff = {"False": self.w_False,
+                    "True" : self.w_True,
+                    "None" : self.w_None,
+                    }
         for n, c in __builtin__.__dict__.iteritems():
             if isinstance(c, types.ClassType) and issubclass(c, Exception):
                 w_c = W_CPythonObject(c)
                 setattr(self, 'w_' + c.__name__, w_c)
-                self.setitem(self.w_builtins, self.wrap(c.__name__), w_c)
-        self.setitem(self.w_builtins, self.wrap("False"), self.w_False)
-        self.setitem(self.w_builtins, self.wrap("True"), self.w_True)
-        self.setitem(self.w_builtins, self.wrap("None"), self.w_None)
+                newstuff[c.__name__] = w_c
+        self.make_builtins()
+        # insert these into the newly-made builtins
+        for key, w_value in newstuff.items():
+            self.setitem(self.w_builtins, self.wrap(key), w_value)
         # add a dummy __import__  XXX fixme
         w_import = self.wrap(__import__)
         self.setitem(self.w_builtins, self.wrap("__import__"), w_import)


More information about the Pypy-commit mailing list