[pypy-svn] r6005 - in pypy/trunk/src/pypy/objspace: . std

arigo at codespeak.net arigo at codespeak.net
Tue Aug 17 17:35:05 CEST 2004


Author: arigo
Date: Tue Aug 17 17:35:05 2004
New Revision: 6005

Modified:
   pypy/trunk/src/pypy/objspace/descroperation.py
   pypy/trunk/src/pypy/objspace/std/fake.py
Log:
Removed two lines in descroperation.py about the type of type(None).__repr__.
To do that, fake.py now makes wrap() return a normal Function object when
asked to wrap a built-in function, method, or slot_wrapper instance.  The
Function object's code is a fake.CPythonFakeCode instance, which just calls
the CPython callable.



Modified: pypy/trunk/src/pypy/objspace/descroperation.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/descroperation.py	(original)
+++ pypy/trunk/src/pypy/objspace/descroperation.py	Tue Aug 17 17:35:05 2004
@@ -73,8 +73,6 @@
                 if w_result is not None:
                     return w_result
             return descr.call_args(args.prepend(w_obj))
-        elif type(descr) is type(space.wrap(SlotWrapper)):
-            return descr.call_args(args.prepend(w_obj))
         else:
             w_impl = space.get(w_descr, w_obj)
             return space.call_args(w_impl, args)

Modified: pypy/trunk/src/pypy/objspace/std/fake.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/fake.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/fake.py	Tue Aug 17 17:35:05 2004
@@ -1,4 +1,6 @@
 from pypy.interpreter.error import OperationError
+from pypy.interpreter import eval
+from pypy.interpreter.function import Function
 from pypy.objspace.std.stdtypedef import *
 from pypy.objspace.std.objspace import W_Object, StdObjSpace
 from pypy.objspace.std.default import UnwrapError
@@ -63,24 +65,41 @@
     StdObjSpace.unwrap.register(fake_unwrap, W_Fake)
     W_Fake.__name__ = 'W_Fake%s'%(cpy_type.__name__.capitalize())
     W_Fake.typedef.fakedcpytype = cpy_type
-    # XXX obviously this entire file is something of a hack, but it
-    # manages to get worse here:
-    if cpy_type is type(type(None).__repr__):
-        def call_args(self, args):
-            try:
-                unwrappedargs = [self.space.unwrap(w_arg) for w_arg in args.args_w]
-                unwrappedkwds = dict([(key, self.space.unwrap(w_value))
-                                      for key, w_value in args.kwds_w.items()])
-            except UnwrapError, e:
-                raise UnwrapError('calling %s: %s' % (cpy_type, e))
-            try:
-                assert callable(self.val), self.val
-                result = apply(self.val, unwrappedargs, unwrappedkwds)
-            except:
-                wrap_exception(self.space)
-            return self.space.wrap(result)
-
-        setattr(W_Fake, "call_args", call_args)
     _fake_type_cache[cpy_type] = W_Fake
     return W_Fake
 
+# ____________________________________________________________
+#
+# Special case for built-in functions, methods, and slot wrappers.
+
+class CPythonFakeCode(eval.Code):
+    def __init__(self, cpy_callable):
+        eval.Code.__init__(self, getattr(cpy_callable, '__name__', '?'))
+        self.cpy_callable = cpy_callable
+        assert callable(cpy_callable), cpy_callable
+    def create_frame(self, space, w_globals, closure=None):
+        return CPythonFakeFrame(space, self, w_globals)
+    def signature(self):
+        return [], 'args', 'kwds'
+
+class CPythonFakeFrame(eval.Frame):
+    def run(self):
+        fn = self.code.cpy_callable
+        w_args, w_kwds = self.fastlocals_w
+        try:
+            unwrappedargs = self.space.unwrap(w_args)
+            unwrappedkwds = self.space.unwrap(w_kwds)
+        except UnwrapError, e:
+            raise UnwrapError('calling %s: %s' % (cpy_type, e))
+        try:
+            result = apply(fn, unwrappedargs, unwrappedkwds)
+        except:
+            wrap_exception(self.space)
+        return self.space.wrap(result)
+
+def fake_builtin_callable(space, val):
+    return Function(space, CPythonFakeCode(val))
+
+_fake_type_cache[type(len)] = fake_builtin_callable
+_fake_type_cache[type(list.append)] = fake_builtin_callable
+_fake_type_cache[type(type(None).__repr__)] = fake_builtin_callable



More information about the Pypy-commit mailing list