[pypy-svn] r13840 - in pypy/dist/pypy/translator/c: . test

ac at codespeak.net ac at codespeak.net
Sat Jun 25 12:49:56 CEST 2005


Author: ac
Date: Sat Jun 25 12:49:56 2005
New Revision: 13840

Modified:
   pypy/dist/pypy/translator/c/int_include.h
   pypy/dist/pypy/translator/c/test/test_typed.py
   pypy/dist/pypy/translator/c/unichar_include.h   (contents, props changed)
Log:
Add C support for ord on unicode characters and unichr.


Modified: pypy/dist/pypy/translator/c/int_include.h
==============================================================================
--- pypy/dist/pypy/translator/c/int_include.h	(original)
+++ pypy/dist/pypy/translator/c/int_include.h	Sat Jun 25 12:49:56 2005
@@ -145,6 +145,9 @@
 #define OP_CAST_INT_TO_CHAR(x,r,err)    r = (char)(x);
 #define OP_CAST_PTR_TO_INT(x,r,err)     r = (long)(x);    /* XXX */
 
+#define OP_CAST_UNICHAR_TO_INT(x,r,err)    r = (long)(x);
+#define OP_CAST_INT_TO_UNICHAR(x,r,err)    r = (unsigned)(x);
+
 /* bool operations */
 
 #define OP_BOOL_NOT(x, r, err) r = !(x);

Modified: pypy/dist/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_typed.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_typed.py	Sat Jun 25 12:49:56 2005
@@ -174,7 +174,7 @@
         l = list(u'Hello world')
         def f(i=int,j=int):
             return l[i] == l[j]
-        fn = self.getcompiled(f) #,view=True)
+        fn = self.getcompiled(f)
         for i in range(len(l)):
             for j in range(len(l)):
                 res = fn(i,j)
@@ -184,12 +184,31 @@
         l = list(u'Hello world')
         def f(i=int,j=int):
             return l[i] != l[j]
-        fn = self.getcompiled(f) #,view=True)
+        fn = self.getcompiled(f)
         for i in range(len(l)):
             for j in range(len(l)):
                 res = fn(i,j)
                 assert res == f(i,j)
 
+    def test_unichr_ord(self):
+        l = list(u'Hello world')
+        def f(i=int):
+            return ord(l[i]) 
+        fn = self.getcompiled(f)
+        for i in range(len(l)):
+            res = fn(i)
+            assert res == f(i)
+
+    def test_unichr_unichr(self):
+        l = list(u'Hello world')
+        def f(i=int, j=int):
+            return l[i] == unichr(j)
+        fn = self.getcompiled(f)
+        for i in range(len(l)):
+            for j in range(len(l)):
+                res = fn(i, ord(l[j]))
+                assert res == f(i, ord(l[j]))
+
     def test_slice_long(self):
         "the parent's test_slice_long() makes no sense here"
 

Modified: pypy/dist/pypy/translator/c/unichar_include.h
==============================================================================
--- pypy/dist/pypy/translator/c/unichar_include.h	(original)
+++ pypy/dist/pypy/translator/c/unichar_include.h	Sat Jun 25 12:49:56 2005
@@ -1,11 +1,11 @@
-/************************************************************/
-/***  C header subsection: operations between chars       ***/
-
-/*** unary operations ***/
-
-/***  binary operations ***/
-
-/* typedef unsigned pypy_unichar;
 */
-#define OP_UNICHAR_EQ(x,y,r,err)	 r = ((x) == (y));
-#define OP_UNICHAR_NE(x,y,r,err)	 r = ((x) != (y));
-
+/************************************************************/
+/***  C header subsection: operations between chars       ***/
+
+/*** unary operations ***/
+
+/***  binary operations ***/
+
+/* typedef unsigned pypy_unichar; */
+#define OP_UNICHAR_EQ(x,y,r,err)	 r = ((x) == (y));
+#define OP_UNICHAR_NE(x,y,r,err)	 r = ((x) != (y));
+



More information about the Pypy-commit mailing list