[pypy-dev] [patch] bitwise binary operators

Olivier Dormond olivier.dormond at gmail.com
Tue Dec 7 17:56:56 CET 2004


Oops!

 Armin told me that nonneg means that we know for sure that the value
is not negative
(i.e. postive or null).
In that case the xor behave differently.

Hopefully this patch will do it right.

Cheers,

Olivier

Index: pypy/annotation/binaryop.py
===================================================================
--- pypy/annotation/binaryop.py (revision 7771)
+++ pypy/annotation/binaryop.py (working copy)
@@ -20,6 +20,7 @@

 # XXX unify this with ObjSpace.MethodTable
 BINARY_OPERATIONS = set(['add', 'sub', 'mul', 'div', 'mod',
+                         'and_', 'or_', 'xor',
                          'getitem', 'setitem',
                          'inplace_add', 'inplace_sub',
                          'lt', 'le', 'eq', 'ne', 'gt', 'ge', 'is_',
@@ -125,16 +126,17 @@
         return SomeInteger(nonneg = int1.nonneg and int2.nonneg,
                            unsigned = int1.unsigned or int2.unsigned)

-    def add((int1, int2)):
-        return SomeInteger(nonneg = int1.nonneg and int2.nonneg,
-                           unsigned = int1.unsigned or int2.unsigned)
+    add = mul = div = mod = or_ = union

-    mul = div = mod = add
-
     def sub((int1, int2)):
         return SomeInteger(unsigned = int1.unsigned or int2.unsigned)

+    def and_((int1, int2)):
+        return SomeInteger(nonneg = int1.nonneg or int1.nonneg,
+                           unsigned = int1.unsigned or int2.unsigned)

+    xor = and_
+
 class __extend__(pairtype(SomeBool, SomeBool)):

     def union((boo1, boo2)):



More information about the Pypy-dev mailing list