[pypy-svn] r10057 - pypy/dist/pypy/objspace

arigo at codespeak.net arigo at codespeak.net
Tue Mar 22 16:20:45 CET 2005


Author: arigo
Date: Tue Mar 22 16:20:45 2005
New Revision: 10057

Modified:
   pypy/dist/pypy/objspace/idhack.py
   pypy/dist/pypy/objspace/thunk_and_idhack.py
Log:
- made idhack composable (i.e. a proxy obj space)
- thunk_and_idhack compose thunk and idhack in the other order


Modified: pypy/dist/pypy/objspace/idhack.py
==============================================================================
--- pypy/dist/pypy/objspace/idhack.py	(original)
+++ pypy/dist/pypy/objspace/idhack.py	Tue Mar 22 16:20:45 2005
@@ -12,38 +12,16 @@
 
 """
 
-from pypy.objspace import std
+from proxy import create_proxy_space
 from pypy.interpreter import gateway
 
 # ____________________________________________________________
 
-def idhack(w_obj):
+def canonical(w_obj):
     try:
-        w_obj = w_obj.__unified_with[-1]
+        return w_obj.__unified_with[-1]
     except AttributeError:
-        pass
-    return id(w_obj)  # XXX call the inherited space.id(), maybe
-
-
-class IdHackSpace(std.Space):
-
-    def initialize(self):
-        super(IdHackSpace, self).initialize()
-        self.setitem(self.builtin.w_dict, self.wrap('become'),
-                     self.wrap(app_become))
-
-    def is_(self, w_one, w_two):
-        if idhack(w_one) == idhack(w_two):
-            return self.w_True
-        return self.w_False
-
-    def id(self, w_obj):
-        return self.wrap(idhack(w_obj))
-
-
-Space = IdHackSpace
-
-# ____________________________________________________________
+        return w_obj
 
 def become(space, w_target, w_source):
     try:
@@ -57,3 +35,22 @@
         w_obj.__dict__  = w_source.__dict__
     return space.w_None
 app_become = gateway.interp2app(become)
+
+# ____________________________________________________________
+
+def proxymaker(space, opname, parentfn):
+    if opname == 'id':
+        def proxy(w_obj):
+            return parentfn(canonical(w_obj))
+    elif opname == 'is_':
+        def proxy(w_a, w_b):
+            return parentfn(canonical(w_a), canonical(w_b))
+    else:
+        proxy = parentfn
+    return proxy
+
+def Space(space=None):
+    space = create_proxy_space('idhack', proxymaker, space=space)
+    space.setitem(space.builtin.w_dict, space.wrap('become'),
+                 space.wrap(app_become))
+    return space

Modified: pypy/dist/pypy/objspace/thunk_and_idhack.py
==============================================================================
--- pypy/dist/pypy/objspace/thunk_and_idhack.py	(original)
+++ pypy/dist/pypy/objspace/thunk_and_idhack.py	Tue Mar 22 16:20:45 2005
@@ -1,5 +1,6 @@
 import thunk, idhack
 
 def Space():
-    space = idhack.IdHackSpace()
-    return thunk.Space(space)
+    space = thunk.Space()
+    space = idhack.Space(space)
+    return space



More information about the Pypy-commit mailing list