[pypy-svn] r4862 - in pypy/branch/src-newobjectmodel/pypy: interpreter interpreter/test objspace

arigo at codespeak.net arigo at codespeak.net
Thu Jun 3 12:46:48 CEST 2004


Author: arigo
Date: Thu Jun  3 12:46:47 2004
New Revision: 4862

Modified:
   pypy/branch/src-newobjectmodel/pypy/interpreter/extmodule.py
   pypy/branch/src-newobjectmodel/pypy/interpreter/gateway.py
   pypy/branch/src-newobjectmodel/pypy/interpreter/test/test_interpreter.py
   pypy/branch/src-newobjectmodel/pypy/objspace/descroperation.py
   pypy/branch/src-newobjectmodel/pypy/objspace/trivial.py
Log:
More bug fixes.  Soon time to clean up gateway.py...


Modified: pypy/branch/src-newobjectmodel/pypy/interpreter/extmodule.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/interpreter/extmodule.py	(original)
+++ pypy/branch/src-newobjectmodel/pypy/interpreter/extmodule.py	Thu Jun  3 12:46:47 2004
@@ -49,11 +49,13 @@
         w_builtins = space.w_builtins
         self.__saved_hooks = {}
         newhooks = {}
-        for name, hook in [
-            ('__interplevel__exec',     self.app_interplevelexec),
-            ('__interplevel__eval',     self.app_interpleveleval),
-            ('__interplevel__execfile', self.app_interplevelexecfile),
-            ('__import__',              self.app_interplevelimport)]:
+        
+        for name, impl in [
+            ('__interplevel__exec',     self.interplevelexec.im_func),
+            ('__interplevel__eval',     self.interpleveleval.im_func),
+            ('__interplevel__execfile', self.interplevelexecfile.im_func),
+            ('__import__',              self.interplevelimport.im_func)]:
+            hook = gateway.interp2app(impl).get_method(self)
             w_name = space.wrap(name)
             try:
                 self.__saved_hooks[name] = space.getitem(w_builtins, w_name)
@@ -143,11 +145,6 @@
                                        w_modulename, w_globals,
                                        w_locals, w_fromlist)
 
-    app_interplevelexec     = gateway.interp2app(interplevelexec)
-    app_interpleveleval     = gateway.interp2app(interpleveleval)
-    app_interplevelexecfile = gateway.interp2app(interplevelexecfile)
-    app_interplevelimport   = gateway.interp2app(interplevelimport)
-
     class AppModuleHack:
         """For interp-level convenience: 'from __applevel__ import func'
         imports the app-level function 'func' via an appropriate gateway.

Modified: pypy/branch/src-newobjectmodel/pypy/interpreter/gateway.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/interpreter/gateway.py	(original)
+++ pypy/branch/src-newobjectmodel/pypy/interpreter/gateway.py	Thu Jun  3 12:46:47 2004
@@ -137,30 +137,6 @@
         # and the result is a wrapped version of this Function.
         return space.wrap(self.get_function(space))
 
-    def __call__(self, space, *args_w, **kwds_w):
-        # to call the Gateway as a non-method, 'space' must be explicitely
-        # supplied. We build the Function object and call it.
-        fn = self.get_function(space)
-        return fn.descr_function_call(*args_w, **kwds_w)
-
-    def __get__(self, obj, cls=None):
-        # to get the Gateway as a method out of an instance, we build a
-        # Function and get it.
-        if obj is None:
-            return self   # Gateways as unbound methods not implemented
-        else:
-            # the object space is implicitely fetched out of the instance
-            if isinstance(self.code, BuiltinCode):
-                assert self.code.ismethod, (
-                    'global built-in function %r used as method' %
-                    self.code.func)
-            space = obj.space
-            fn = self.get_function(space)
-            if cls is None:
-                cls = obj.__class__
-            return Method(space, space.wrap(fn),
-                          space.wrap(obj), space.wrap(cls))
-
     def get_function(self, space):
         try:
             return self.functioncache[space]
@@ -198,6 +174,19 @@
             self.functioncache[space] = fn
         return fn
 
+    def get_method(self, obj):
+        # to get the Gateway as a method out of an instance, we build a
+        # Function and get it.
+        # the object space is implicitely fetched out of the instance
+        if isinstance(self.code, BuiltinCode):
+            assert self.code.ismethod, (
+                'global built-in function %r used as method' %
+                self.code.func)
+        space = obj.space
+        fn = self.get_function(space)
+        return Method(space, space.wrap(fn),
+                      space.wrap(obj), space.wrap(obj.__class__))
+
 
 class app2interp(Gateway):
     """Build a Gateway that calls 'app' at app-level."""
@@ -220,6 +209,19 @@
     def getdefaults(self, space):
         return [space.wrap(val) for val in self.staticdefs]
 
+    def __call__(self, space, *args_w, **kwds_w):
+        # to call the Gateway as a non-method, 'space' must be explicitely
+        # supplied. We build the Function object and call it.
+        fn = self.get_function(space)
+        return fn.descr_function_call(*args_w, **kwds_w)
+
+    def __get__(self, obj, cls=None):
+        if obj is None:
+            return self
+        else:
+            method = self.get_method(obj)
+            return method.descr_method_call
+
 class interp2app(Gateway):
     """Build a Gateway that calls 'f' at interp-level."""
     def __init__(self, f, app_name=None):

Modified: pypy/branch/src-newobjectmodel/pypy/interpreter/test/test_interpreter.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/interpreter/test/test_interpreter.py	(original)
+++ pypy/branch/src-newobjectmodel/pypy/interpreter/test/test_interpreter.py	Thu Jun  3 12:46:47 2004
@@ -23,7 +23,7 @@
         code = space.unwrap(w_code)
         code.exec_code(space, w_glob, w_glob)
 
-        wrappedargs = w(args)
+        wrappedargs = space.newtuple(args)
         wrappedfunc = space.getitem(w_glob, w(functionname))
         wrappedkwds = space.newdict([])
         try:

Modified: pypy/branch/src-newobjectmodel/pypy/objspace/descroperation.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/descroperation.py	(original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/descroperation.py	Thu Jun  3 12:46:47 2004
@@ -301,12 +301,17 @@
 
 def _make_inplace_impl(symbol,specialnames):
     specialname, = specialnames
+    assert specialname.startswith('__i') and specialname.endswith('__')
+    noninplacespacemethod = specialname[3:-2]
     def inplace_impl(space,w_lhs,w_rhs):
         w_impl = space.lookup(w_lhs,specialname)
-        if w_impl is None:
-            raise OperationError(space.w_TypeError,
-                    space.wrap("operands do not support inplace %s" % symbol))
-        return space.get_and_call_function(w_impl,w_lhs,w_rhs)
+        if w_impl is not None:
+            w_res = space.get_and_call_function(w_impl,w_lhs,w_rhs)
+            if _check_notimplemented(space,w_res):
+                return w_res
+        # XXX fix the error message we get here
+        return getattr(space, noninplacespacemethod)(w_lhs,w_rhs)
+
     return inplace_impl
 
 def _make_unaryop_impl(symbol,specialnames):

Modified: pypy/branch/src-newobjectmodel/pypy/objspace/trivial.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/trivial.py	(original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/trivial.py	Thu Jun  3 12:46:47 2004
@@ -120,8 +120,11 @@
     def is_(self, w_obj1, w_obj2):
         return self.unwrap(w_obj1) is self.unwrap(w_obj2)
 
-    def unpacktuple(self, w_tuple):
+    def unpacktuple(self, w_tuple, expected_length=None):
         assert isinstance(w_tuple, tuple)
+        if expected_length is not None and expected_length != len(w_tuple):
+            raise ValueError, "got a tuple of length %d instead of %d" % (
+                len(w_tuple), expected_length)
         return list(w_tuple)
 
     def reraise(self):



More information about the Pypy-commit mailing list