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

ale at codespeak.net ale at codespeak.net
Fri Jun 24 18:25:43 CEST 2005


Author: ale
Date: Fri Jun 24 18:25:41 2005
New Revision: 13824

Added:
   pypy/dist/pypy/translator/c/unichar_include.h
Modified:
   pypy/dist/pypy/translator/c/g_include.h
   pypy/dist/pypy/translator/c/primitive.py
   pypy/dist/pypy/translator/c/test/test_typed.py
Log:
Preliminary support for Unicode chars (arre,ale)

Modified: pypy/dist/pypy/translator/c/g_include.h
==============================================================================
--- pypy/dist/pypy/translator/c/g_include.h	(original)
+++ pypy/dist/pypy/translator/c/g_include.h	Fri Jun 24 18:25:41 2005
@@ -17,6 +17,7 @@
 
 #include "int_include.h"
 #include "char_include.h"
+#include "unichar_include.h"
 #include "float_include.h"
 #include "ll_include.h"
 #include "pyobj_include.h"

Modified: pypy/dist/pypy/translator/c/primitive.py
==============================================================================
--- pypy/dist/pypy/translator/c/primitive.py	(original)
+++ pypy/dist/pypy/translator/c/primitive.py	Fri Jun 24 18:25:41 2005
@@ -31,11 +31,17 @@
 def name_void(value):
     return '/* nothing */'
 
+def name_unichar(value):
+    assert type(value) is unicode and len(value) == 1
+    return '%d' % ord(value)
+    
+
 PrimitiveName = {
     Signed:   name_signed,
     Unsigned: name_unsigned,
     Float:    name_float,
     Char:     name_char,
+    UniChar:  name_unichar,
     Bool:     name_bool,
     Void:     name_void,
     }
@@ -45,6 +51,7 @@
     Unsigned: 'unsigned long @',
     Float:    'double @',
     Char:     'char @',
+    UniChar:  'pypy_unichar @',
     Bool:     'char @',
     Void:     'void @',
     }
@@ -54,6 +61,7 @@
     Unsigned: '((unsigned) -1)',
     Float:    '-1.0',
     Char:     '((char) -1)',
+    UniChar:  '((pypy_unichar) -1)',
     Bool:     '((char) -1)',
     Void:     '/* error */',
     }

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	Fri Jun 24 18:25:41 2005
@@ -169,6 +169,26 @@
             for j in range(3):
                 res = fn(i, j)
                 assert res == fn(i, j)
+    
+    def xtest_unichr_eq(self):
+        l = list(u'Hello world')
+        def f(i=int,j=int):
+            return l[i] == l[j]
+        fn = self.getcompiled(f) #,view=True)
+        for i in range(len(l)):
+            for j in range(len(l)):
+                res = fn(i,j)
+                assert res == f(i,j) 
+    
+    def xtest_unichr_ne(self):
+        l = list(u'Hello world')
+        def f(i=int,j=int):
+            return l[i] != l[j]
+        fn = self.getcompiled(f) #,view=True)
+        for i in range(len(l)):
+            for j in range(len(l)):
+                res = fn(i,j)
+                assert res == f(i,j)
 
     def test_slice_long(self):
         "the parent's test_slice_long() makes no sense here"

Added: pypy/dist/pypy/translator/c/unichar_include.h
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/c/unichar_include.h	Fri Jun 24 18:25:41 2005
@@ -0,0 +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));
+



More information about the Pypy-commit mailing list