[pypy-svn] r24356 - in pypy/dist/pypy/translator/squeak: . test

nik at codespeak.net nik at codespeak.net
Tue Mar 14 11:56:22 CET 2006


Author: nik
Date: Tue Mar 14 11:56:11 2006
New Revision: 24356

Modified:
   pypy/dist/pypy/translator/squeak/gensqueak.py
   pypy/dist/pypy/translator/squeak/test/test_llops.py
Log:
more awkward code to support uint llops. some major refactoring will be
required soon, mainly splitting up code into more modules.


Modified: pypy/dist/pypy/translator/squeak/gensqueak.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/gensqueak.py	(original)
+++ pypy/dist/pypy/translator/squeak/gensqueak.py	Tue Mar 14 11:56:11 2006
@@ -7,6 +7,7 @@
 from pypy.translator.unsimplify import remove_direct_loops
 from pypy.translator.simplify import simplify_graph
 from pypy.rpython.ootypesystem.ootype import Instance, ROOT
+from pypy.rpython.rarithmetic import r_int, r_uint
 from pypy import conftest
 try:
     set
@@ -262,7 +263,7 @@
     
     primitive_opprefixes = "int", "uint", "llong", "ullong", "float"
 
-    primitive_wrapping_ops = "add", "sub", "mul"
+    primitive_wrapping_ops = "neg", "invert", "add", "sub", "mul"
 
     primitive_masks = {
         # XXX horrendous, but I can't figure out how to do this cleanly
@@ -272,6 +273,9 @@
                     ^ i + %s \\\\ %s - %s
                   """ % (sys.maxint, -sys.maxint-1,
                       sys.maxint+1, 2*(sys.maxint+1), sys.maxint+1)),
+        "uint": (Selector("maskUint", 1),
+                """maskUint: i 
+                    ^ i bitAnd: %s""" % r_uint.MASK),
     }
 
     def render_body(self, startblock):

Modified: pypy/dist/pypy/translator/squeak/test/test_llops.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/test/test_llops.py	(original)
+++ pypy/dist/pypy/translator/squeak/test/test_llops.py	Tue Mar 14 11:56:11 2006
@@ -1,8 +1,9 @@
 import sys
 from pypy.translator.squeak.test.runtest import compile_function
+from pypy.rpython.rarithmetic import r_uint
 from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy
 from pypy.rpython.lltypesystem.lloperation import llop
-from pypy.rpython.lltypesystem.lltype import Signed, Bool
+from pypy.rpython.lltypesystem.lltype import Signed, Unsigned, Bool
 from pypy.rpython.test.test_llinterp import interpret
 
 def optest(testcase):
@@ -23,26 +24,39 @@
     res = sqfunc(*args)
     assert res == str(expected_res).lower() # lowercasing for booleans
 
-def test_intoperations():
-    tests = [
-        # unary
-        ("int_abs", Signed, 7),
-        ("int_abs", Signed, -7),
-        ("int_is_true", Bool, 8),
-        ("int_is_true", Bool, 0),
-        ("int_neg", Signed, 2),
-        ("int_neg", Signed, -2),
-        ("int_invert", Signed, 5),
-        ("int_invert", Signed, -5),
-
-        # binary
-        ("int_add", Signed, 1, 2),
-        ("int_sub", Signed, 1, 3),
-        ("int_mul", Signed, 2, 3),
-        ("int_div", Signed, 7, 3),
-        ("int_floordiv", Signed, 7, 3),
-        ("int_floordiv", Signed, -7, 3),
+def adapt_tests(tests, type, RESTYPE, prefix):
+    adapted = []
+    for test in tests:
+        llop = "%s_%s" % (prefix, test[0]) 
+        RES = test[1]
+        if RES == Signed:
+            RES = RESTYPE
+        args = [type(arg) for arg in test[2:]]
+        adapted.append((llop, RES) + tuple(args))
+    return adapted
+
+general_tests = [
+    # unary
+    ("abs", Signed, 7),
+    ("abs", Signed, -7),
+    ("is_true", Bool, 8),
+    ("is_true", Bool, 0),
+    ("neg", Signed, 2),
+    ("neg", Signed, -2),
+    ("invert", Signed, 5),
+    ("invert", Signed, -5),
+
+    # binary
+    ("add", Signed, 1, 2),
+    ("sub", Signed, 1, 3),
+    ("mul", Signed, 2, 3),
+    ("div", Signed, 7, 3),
+    ("floordiv", Signed, 7, 3),
+    ("floordiv", Signed, -7, 3),
+]
 
+def test_intoperations():
+    tests = adapt_tests(general_tests, int, Signed, "int") + [
         # binary wraparounds
         ("int_add", Signed, sys.maxint, 1),
         ("int_sub", Signed, -sys.maxint-1, 2),
@@ -51,3 +65,12 @@
     for t in tests:
         yield optest, t
 
+def test_uintoperations():
+    tests = adapt_tests(general_tests, r_uint, Unsigned, "uint") + [
+        # binary wraparounds
+        ("uint_add", Unsigned, r_uint(2*sys.maxint), r_uint(2)),
+        ("uint_mul", Unsigned, r_uint(sys.maxint), r_uint(3)),
+    ]
+    for t in tests:
+        yield optest, t
+



More information about the Pypy-commit mailing list