[pypy-svn] rev 2109 - in pypy/trunk/src/pypy/translator: . test

sanxiyn at codespeak.net sanxiyn at codespeak.net
Tue Oct 28 14:26:08 CET 2003


Author: sanxiyn
Date: Tue Oct 28 14:26:07 2003
New Revision: 2109

Modified:
   pypy/trunk/src/pypy/translator/annotation.py
   pypy/trunk/src/pypy/translator/gencl.py
   pypy/trunk/src/pypy/translator/test/test_cltrans.py
Log:
gencl, annotation: int/long
test_cltrans: give types of arguments where appropriate


Modified: pypy/trunk/src/pypy/translator/annotation.py
==============================================================================
--- pypy/trunk/src/pypy/translator/annotation.py	(original)
+++ pypy/trunk/src/pypy/translator/annotation.py	Tue Oct 28 14:26:07 2003
@@ -98,18 +98,24 @@
         type1 = annotations.get_type(arg1)
         type2 = annotations.get_type(arg2)
         if type1 is int and type2 is int:
-            annotations.set_type(op.result,int)
+            annotations.set_type(op.result, int)
+        elif type1 in (int, long) and type2 in (int, long):
+            annotations.set_type(op.result, long)
         if type1 is str and type2 is str:
             annotations.set_type(op.result, str)
         if type1 is list and type2 is list:
             annotations.set_type(op.result, list)
 
+    consider_op_inplace_add = consider_op_add
+
     def consider_op_sub(self, op, annotations):
         arg1, arg2 = op.args
         type1 = annotations.get_type(arg1)
         type2 = annotations.get_type(arg2)
         if type1 is int and type2 is int:
             annotations.set_type(op.result, int)
+        elif type1 in (int, long) and type2 in (int, long):
+            annotations.set_type(op.result, long)
 
     consider_op_and_ = consider_op_sub # trailing underline
     consider_op_inplace_lshift = consider_op_sub

Modified: pypy/trunk/src/pypy/translator/gencl.py
==============================================================================
--- pypy/trunk/src/pypy/translator/gencl.py	(original)
+++ pypy/trunk/src/pypy/translator/gencl.py	Tue Oct 28 14:26:07 2003
@@ -61,6 +61,9 @@
         print "(setq", s(result)
         table = {
             (int, int): "(+ %s %s)",
+            (int, long): "(+ %s %s)",
+            (long, int): "(+ %s %s)",
+            (long, long): "(+ %s %s)",
             (str, str): "(concatenate 'string %s %s)",
             (list, list): "(concatenate 'vector %s %s)",
         }
@@ -73,6 +76,7 @@
         table = {
             (bool,): "(not %s)",
             (int,): "(zerop %s)",
+            (long,): "(zerop %s)",
             (list,): "(zerop (length %s))",
         }
         self.gen.emit_typecase(table, arg1)
@@ -84,6 +88,7 @@
         table = {
             (bool,): "%s",
             (int,): "(not (zerop %s))",
+            (long,): "(not (zerop %s))",
             (list,): "(not (zerop (length %s)))",
         }
         self.gen.emit_typecase(table, arg1)
@@ -269,6 +274,7 @@
     typemap = {
         bool: "boolean",
         int: "fixnum",
+        long: "bignum",
         type(''): "string", # hack, 'str' is in the namespace!
         list: "vector",
     }

Modified: pypy/trunk/src/pypy/translator/test/test_cltrans.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/test_cltrans.py	(original)
+++ pypy/trunk/src/pypy/translator/test/test_cltrans.py	Tue Oct 28 14:26:07 2003
@@ -51,11 +51,11 @@
         self.assertEquals(cl_if(1, 50, 100), 50)
 
     def test_gcd(self):
-        cl_gcd = make_cl_func(t.my_gcd)
+        cl_gcd = make_cl_func(t.my_gcd, [int, int])
         self.assertEquals(cl_gcd(96, 64), 32)
 
     def test_is_perfect(self): # pun intended
-        cl_perfect = make_cl_func(t.is_perfect_number)
+        cl_perfect = make_cl_func(t.is_perfect_number, [int])
         self.assertEquals(cl_perfect(24), False)
         self.assertEquals(cl_perfect(28), True)
 
@@ -75,24 +75,24 @@
 
     def test_easy(self):
         # These are the Pyrex tests which were easy to adopt.
-        f1 = make_cl_func(t.simple_func)
+        f1 = make_cl_func(t.simple_func, [int])
         self.assertEquals(f1(1), 2)
-        f2 = make_cl_func(t.while_func)
+        f2 = make_cl_func(t.while_func, [int])
         self.assertEquals(f2(10), 55)
         f3 = make_cl_func(t.simple_id)
         self.assertEquals(f3(9), 9)
         f4 = make_cl_func(t.branch_id)
         self.assertEquals(f4(1, 2, 3), 2)
         self.assertEquals(f4(0, 2, 3), 3)
-        f5 = make_cl_func(t.int_id)
+        f5 = make_cl_func(t.int_id, [int])
         self.assertEquals(f5(3), 3)
-        f6 = make_cl_func(t.time_waster)
+        f6 = make_cl_func(t.time_waster, [int])
         self.assertEquals(f6(30), 3657)
 
     def test_string(self):
         cl_greet = make_cl_func(t.greet, [str])
         self.assertEquals(cl_greet("world"), "helloworld")
-        cl_stringmaker = make_cl_func(t.nested_whiles)
+        cl_stringmaker = make_cl_func(t.nested_whiles, [int, int])
         self.assertEquals(cl_stringmaker(111, 114),
                           "...!...!...!...!...!")
 
@@ -105,7 +105,7 @@
         self.assertEquals(cl_builtinusage(), 4)
 
     def test_slice(self):
-        cl_half = make_cl_func(t.half_of_n)
+        cl_half = make_cl_func(t.half_of_n, [int])
         self.assertEquals(cl_half(10), 5)
 
     def test_powerset(self):


More information about the Pypy-commit mailing list