[pypy-svn] r28824 - in pypy/dist/pypy: interpreter objspace/cpy translator/c

arigo at codespeak.net arigo at codespeak.net
Thu Jun 15 16:32:22 CEST 2006


Author: arigo
Date: Thu Jun 15 16:32:21 2006
New Revision: 28824

Added:
   pypy/dist/pypy/objspace/cpy/appsupport.py   (contents, props changed)
Modified:
   pypy/dist/pypy/interpreter/gateway.py
   pypy/dist/pypy/objspace/cpy/objspace.py
   pypy/dist/pypy/translator/c/database.py
   pypy/dist/pypy/translator/c/pyobj.py
Log:
Support (probably fragile) for the app-level parts of a MixedModule
in the CPyObjSpace.


Modified: pypy/dist/pypy/interpreter/gateway.py
==============================================================================
--- pypy/dist/pypy/interpreter/gateway.py	(original)
+++ pypy/dist/pypy/interpreter/gateway.py	Thu Jun 15 16:32:21 2006
@@ -770,6 +770,8 @@
         return Module(space, space.wrap(name), self.getwdict(space))
 
     def wget(self, space, name): 
+        if hasattr(space, '_applevelclass_hook'):   # XXX for the CPyObjSpace
+            return space._applevelclass_hook(self, name)
         w_globals = self.getwdict(space) 
         return space.getitem(w_globals, space.wrap(name))
 

Added: pypy/dist/pypy/objspace/cpy/appsupport.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/objspace/cpy/appsupport.py	Thu Jun 15 16:32:21 2006
@@ -0,0 +1,60 @@
+from pypy.rpython.extregistry import ExtRegistryEntry, lookup_type
+from pypy.interpreter.baseobjspace import W_Root, SpaceCache
+from pypy.objspace.cpy.ctypes_base import W_Object
+
+# ____________________________________________________________
+# Hacks to support the app-level parts of MixedModules
+
+class W_AppLevel(W_Root):
+    def __init__(self, space, app, name):
+        self.space = space
+        self.w_moddict = space.fromcache(AppSupportModuleCache).getorbuild(app)
+        self.name = name
+
+class W_AppLevelModDict(W_Root):
+    def __init__(self, space, app):
+        self.space = space
+        self.app = app
+
+class AppSupportModuleCache(SpaceCache):
+    def build(self, app):
+        return W_AppLevelModDict(self.space, app)
+
+# ____________________________________________________________
+
+class Entry(ExtRegistryEntry):
+    _type_ = W_AppLevel
+
+    def compute_annotation(self):
+        from pypy.annotation.bookkeeper import getbookkeeper
+        bk = getbookkeeper()
+        return lookup_type(W_Object).compute_annotation()
+
+    def genc_pyobj(self, pyobjmaker):
+        dictname = pyobjmaker.nameof(self.instance.w_moddict)
+        name = pyobjmaker.uniquename('gapp')
+        pyobjmaker.initcode_python(name, '%s[%r]' % (dictname,
+                                                     self.instance.name))
+        return name
+
+class Entry(ExtRegistryEntry):
+    _type_ = W_AppLevelModDict
+
+    def compute_annotation(self):
+        from pypy.annotation.bookkeeper import getbookkeeper
+        bk = getbookkeeper()
+        return lookup_type(W_Object).compute_annotation()
+
+    def genc_pyobj(self, pyobjmaker):
+        import marshal
+        app = self.instance.app
+        name = pyobjmaker.uniquename('gappmoddict_' + app.modname)
+        bytecodedump = marshal.dumps(app.code)
+        pyobjmaker.initcode.append("import marshal, __builtin__")
+        pyobjmaker.initcode.append("%s = {'__builtins__': __builtin__}" % (
+            name,))
+        pyobjmaker.initcode.append("co = marshal.loads(%s)" % (
+            pyobjmaker.nameof(bytecodedump),))
+        pyobjmaker.initcode.append("exec co in %s" % (
+            name))
+        return name

Modified: pypy/dist/pypy/objspace/cpy/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/objspace.py	(original)
+++ pypy/dist/pypy/objspace/cpy/objspace.py	Thu Jun 15 16:32:21 2006
@@ -1,5 +1,6 @@
 from pypy.objspace.cpy.capi import *
 from pypy.objspace.cpy.refcount import Py_Incref
+from pypy.objspace.cpy.appsupport import W_AppLevel
 from pypy.interpreter import baseobjspace
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.function import Function
@@ -73,6 +74,8 @@
 
     def interpclass_w(self, w_obj):
         "NOT_RPYTHON."
+        if isinstance(w_obj, W_AppLevel):
+            return None   # XXX
         from pypy.objspace.cpy.typedef import cpython2rpython_raw
         return cpython2rpython_raw(self, w_obj)
 
@@ -268,11 +271,16 @@
 
     def exec_(self, statement, w_globals, w_locals, hidden_applevel=False):
         "NOT_RPYTHON"
-        #raise NotImplementedError("space.exec_")
-        from types import CodeType
-        if not isinstance(statement, (str, CodeType)):
-            raise TypeError("CPyObjSpace.exec_(): only for CPython code objs")
-        exec statement in w_globals.value, w_locals.value
+        raise NotImplementedError("space.exec_")
+        #from types import CodeType
+        #if not isinstance(statement, (str, CodeType)):
+        #    raise TypeError("CPyObjSpace.exec_(): only for CPython code objs")
+        #exec statement in w_globals.value, w_locals.value
+
+    def _applevelclass_hook(self, app, name):
+        # hackish hook for gateway.py: in a MixedModule, all init-time gets
+        # from app-level files should arrive here
+        return W_AppLevel(self, app, name)
 
 
 # Register add, sub, neg, etc...

Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py	(original)
+++ pypy/dist/pypy/translator/c/database.py	Thu Jun 15 16:32:21 2006
@@ -12,7 +12,6 @@
 from pypy.translator.c.node import FixedSizeArrayDefNode
 from pypy.translator.c.node import ContainerNodeFactory, ExtTypeOpaqueDefNode
 from pypy.translator.c.support import cdecl, CNameManager, ErrorValue
-from pypy.translator.c.pyobj import PyObjMaker
 from pypy.translator.c.support import log
 from pypy.translator.c.extfunc import do_the_getting
 from pypy.translator.c.exceptiontransform import ExceptionTransformer
@@ -43,6 +42,7 @@
         self.late_initializations = []
         self.namespace = CNameManager()
         if not standalone:
+            from pypy.translator.c.pyobj import PyObjMaker
             self.pyobjmaker = PyObjMaker(self.namespace, self.get, translator)
 
         gcpolicy = gcpolicy or conftest.option.gcpolicy or 'ref'

Modified: pypy/dist/pypy/translator/c/pyobj.py
==============================================================================
--- pypy/dist/pypy/translator/c/pyobj.py	(original)
+++ pypy/dist/pypy/translator/c/pyobj.py	Thu Jun 15 16:32:21 2006
@@ -11,6 +11,7 @@
 
 from pypy.rpython.rarithmetic import r_int, r_uint
 from pypy.rpython.lltypesystem.lltype import pyobjectptr, LowLevelType
+from pypy.rpython import extregistry
 
 # XXX maybe this can be done more elegantly:
 # needed to convince should_translate_attr
@@ -273,6 +274,8 @@
         return False
 
     def nameof_instance(self, instance):
+        if extregistry.is_registered(instance):
+            return extregistry.lookup(instance).genc_pyobj(self)
         if instance in self.import_hints:
             return self.import_instance(instance)
         klass = instance.__class__



More information about the Pypy-commit mailing list