[pypy-svn] r4851 - pypy/branch/src-newobjectmodel/pypy/objspace

pedronis at codespeak.net pedronis at codespeak.net
Thu Jun 3 10:51:49 CEST 2004


Author: pedronis
Date: Thu Jun  3 10:51:48 2004
New Revision: 4851

Modified:
   pypy/branch/src-newobjectmodel/pypy/objspace/descroperation.py
Log:
try at pow (__pow__,__rpow__)



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 10:51:48 2004
@@ -128,7 +128,32 @@
                    space.wrap("cannot delete items from object"))
         return space.get_and_call_function(w_descr,w_obj,w_key)
 
+    def pow(space,w_obj1,w_obj2,w_obj3):
+        w_typ1 = space.type(w_obj1)
+        w_typ2 = space.type(w_obj2)
+        w_left_impl = space.lookup(w_obj1,'__pow__')
+        if space.is_true(space.is_(w_typ1,w_typ2)):
+            w_right_impl = None
+        else:
+            w_right_impl = space.lookup(w_obj2,'__rpow__')
+            if space.issubtype(w_typ1,w_typ2):
+                w_obj1,w_obj2 = w_obj2,w_obj1
+                w_left_impl,w_right_impl = w_right_impl,w_left_impl
+        if w_left_impl is not None:
+            w_res = space.get_and_call_function(w_left_impl,w_obj1,w_obj2,
+                                                w_obj3)
+            if _check_notimplemented(w_res):
+                return w_res
+        if w_right_impl is not None:
+           w_res = space.get_and_call_function(w_right_impl,w_obj2,w_obj1,
+                                                w_obj3)
+           if _check_notimplemented(w_res):
+               return w_res
 
+        raise OperationError(space.w_TypeError,
+                space.wrap("operands do not support **"))
+        
+    
     # not_ has a default implementation
 
     # xxx round, ord
@@ -137,10 +162,13 @@
 
 # helpers
 
-def _invoke_binop(self,w_impl,w_obj1,w_obj2):
+def _check_notimplemented(space,w_obj):
+    return not space.is_true(space.is_(w_res,space.w_NotImplemented))
+
+def _invoke_binop(space,w_impl,w_obj1,w_obj2):
     if w_impl is not None:
         w_res = space.get_and_call_function(w_impl,w_obj1,w_obj2)
-        if not space.is_true(space.is_(w_res,space.w_NotImplemented)):
+        if _check_notimplemented(w_res):
             return w_res
     return None
 
@@ -245,6 +273,7 @@
     return inplace_impl
 
 def _make_unaryop_impl(symbol,specialnames):
+    specialname, = specialnames
     def unaryop_impl(space,w_obj):
         w_impl = space.lookup(w_obj,specialname)
         if w_impl is None:
@@ -276,7 +305,7 @@
         elif _name not in ['id','type','issubtype',
                            # not really to be defined in DescrOperation
                            'ord','not_','round']:
-            print "missing %s" % _name
+            raise Exception,"missing def for operation%s" % _name
             
             
 



More information about the Pypy-commit mailing list