[pypy-dev] [patch] bitwise binary operators

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


Hello,

 Here is a small patch that add the and_, or_ and xor bitwise operators.
It also replaces the add method which is identical to union by a synonym.

Cheers,

                          Odie

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,19 @@
         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)

+    def xor((int1, int2)):
+        return SomeInteger(nonneg = int1.nonneg ^ int1.nonneg,
+                          unsigned = int1.unsigned or int2.unsigned)
+
 class __extend__(pairtype(SomeBool, SomeBool)):

     def union((boo1, boo2)):



More information about the Pypy-dev mailing list