Is this patch fine? I mean, look at the new testcase in pure.pyx...
Should we support all basic C types in cython.declare()?
BTW, I would really like to remove that "modifiers_and_name_to_type" dictionary
--
Lisandro Dalcin
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
diff -r 4304954b9cf8 Cython/Compiler/PyrexTypes.py
--- a/Cython/Compiler/PyrexTypes.py Fri Apr 09 17:54:41 2010 -0300
+++ b/Cython/Compiler/PyrexTypes.py Fri Apr 09 19:04:02 2010 -0300
@@ -2096,7 +2096,9 @@
c_double_type = CFloatType(8)
c_longdouble_type = CFloatType(9, math_h_modifier='l')
+c_float_complex_type = CComplexType(c_float_type)
c_double_complex_type = CComplexType(c_double_type)
+c_longdouble_complex_type = CComplexType(c_longdouble_type)
c_null_ptr_type = CNullPtrType(c_void_type)
c_char_array_type = CCharArrayType(None)
@@ -2158,34 +2160,55 @@
modifiers_and_name_to_type = {
#(signed, longness, name)
(0, 0, "char"): c_uchar_type,
+ (1, 0, "char"): c_char_type,
+ (2, 0, "char"): c_schar_type,
+
+ (0, 0, "short"): c_ushort_type,
+ (1, 0, "short"): c_short_type,
+ (2, 0, "short"): c_sshort_type,
+
(0, -1, "int"): c_ushort_type,
- (0, 0, "int"): c_uint_type,
- (0, 1, "int"): c_ulong_type,
- (0, 2, "int"): c_ulonglong_type,
- (1, 0, "void"): c_void_type,
- (1, 0, "char"): c_char_type,
+ (0, 0, "int"): c_uint_type,
+ (0, 1, "int"): c_ulong_type,
+ (0, 2, "int"): c_ulonglong_type,
(1, -1, "int"): c_short_type,
- (1, 0, "int"): c_int_type,
- (1, 1, "int"): c_long_type,
- (1, 2, "int"): c_longlong_type,
+ (1, 0, "int"): c_int_type,
+ (1, 1, "int"): c_long_type,
+ (1, 2, "int"): c_longlong_type,
+ (2, -1, "int"): c_sshort_type,
+ (2, 0, "int"): c_sint_type,
+ (2, 1, "int"): c_slong_type,
+ (2, 2, "int"): c_slonglong_type,
+
+ (0, 0, "long"): c_ulong_type,
+ (1, 0, "long"): c_long_type,
+ (2, 0, "long"): c_slong_type,
+
+ (0, 0, "longlong"): c_ulong_type,
+ (1, 0, "longlong"): c_longlong_type,
+ (2, 0, "longlong"): c_slonglong_type,
+
(1, 0, "float"): c_float_type,
+ (1, 1, "float"): c_double_type,
(1, 0, "double"): c_double_type,
(1, 1, "double"): c_longdouble_type,
+ (1, 0, "longdouble"): c_longdouble_type,
+
+ (1, 0, "complex"): c_float_complex_type,
+ (1, 1, "complex"): c_double_complex_type,
+ (1, 0, "floatcomplex"): c_float_complex_type,
+ (1, 1, "floatcomplex"): c_double_complex_type,
+ (1, 0, "doublecomplex"): c_double_complex_type,
+ (1, 1, "doublecomplex"): c_longdouble_complex_type,
+ (1, 0, "longdoublecomplex"): c_longdouble_complex_type,
+
+ (1, 0, "void"): c_void_type,
(1, 0, "object"): py_object_type,
(1, 0, "bint"): c_bint_type,
- (2, 0, "char"): c_schar_type,
- (2, -1, "int"): c_sshort_type,
- (2, 0, "int"): c_sint_type,
- (2, 1, "int"): c_slong_type,
- (2, 2, "int"): c_slonglong_type,
-
+ (1, 0, "Py_ssize_t"): c_py_ssize_t_type,
(2, 0, "Py_ssize_t"): c_py_ssize_t_type,
(0, 0, "size_t") : c_size_t_type,
-
- (1, 0, "long"): c_long_type,
- (1, 0, "short"): c_short_type,
- (1, 0, "longlong"): c_longlong_type,
- (1, 0, "bint"): c_bint_type,
+ (1, 0, "size_t") : c_size_t_type,
}
def is_promotion0(src_type, dst_type):
@@ -2399,6 +2422,9 @@
return CPtrType(base)
elif name.startswith('u'):
return simple_c_type(0, 0, name[1:])
+ elif (name.startswith('s') and
+ name[1:] in rank_to_type_name[:4]+('longlong',)):
+ return simple_c_type(2, 0, name[1:])
else:
return simple_c_type(1, 0, name)
@@ -2429,19 +2455,6 @@
else:
return CReferenceType(base_type)
-def Node_to_type(node, env):
- from ExprNodes import NameNode, AttributeNode, StringNode, error
- if isinstance(node, StringNode):
- node = NameNode(node.pos, name=node.value)
- if isinstance(node, NameNode) and node.name in rank_to_type_name:
- return simple_c_type(1, 0, node.name)
- elif isinstance(node, (AttributeNode, NameNode)):
- node.analyze_types(env)
- if not node.entry.is_type:
- pass
- else:
- error(node.pos, "Bad type")
-
def same_type(type1, type2):
return type1.same_as(type2)
diff -r 4304954b9cf8 Cython/Shadow.py
--- a/Cython/Shadow.py Fri Apr 09 17:54:41 2010 -0300
+++ b/Cython/Shadow.py Fri Apr 09 19:04:02 2010 -0300
@@ -153,6 +153,7 @@
+py_complex = complex
py_float = float
py_int = int
try:
@@ -173,16 +174,24 @@
# Predefined types
-int_types = ['char', 'short', 'int', 'long', 'longlong', 'Py_ssize_t']
-float_types = ['double', 'float']
+int_types = ['char', 'short', 'int', 'long', 'longlong', 'Py_ssize_t', 'size_t']
+float_types = ['longdouble', 'double', 'float']
+complex_types = ['longdoublecomplex', 'doublecomplex', 'floatcomplex', 'complex']
other_types = ['bint', 'void']
+
gs = globals()
for name in int_types:
gs[name] = typedef(py_int)
+for name in int_types[:-2]:
gs['u'+name] = typedef(py_int)
-double = float = typedef(py_float)
+for name in float_types:
+ gs[name] = typedef(py_float)
+
+for name in complex_types:
+ gs[name] = typedef(py_complex)
+
bint = typedef(bool)
void = typedef(int)
diff -r 4304954b9cf8 tests/run/pure.pyx
--- a/tests/run/pure.pyx Fri Apr 09 17:54:41 2010 -0300
+++ b/tests/run/pure.pyx Fri Apr 09 19:04:02 2010 -0300
@@ -104,3 +104,42 @@
MyStruct3 = typedef(MyStruct[3])
MyStruct4 = my_typedef(MyStruct[4])
MyStruct5 = cy.typedef(MyStruct[5])
+
+def test_declare_c_types(n):
+ """
+ >>> test_declare_c_types(0)
+ >>> test_declare_c_types(1)
+ >>> test_declare_c_types(2)
+ """
+ #
+ b00 = cython.declare(cython.bint, 0)
+ b01 = cython.declare(cython.bint, 1)
+ b02 = cython.declare(cython.bint, 2)
+ #
+ i00 = cython.declare(cython.uchar, n)
+ i01 = cython.declare(cython.char, n)
+ i02 = cython.declare(cython.schar, n)
+ i03 = cython.declare(cython.ushort, n)
+ i04 = cython.declare(cython.short, n)
+ i05 = cython.declare(cython.sshort, n)
+ i06 = cython.declare(cython.uint, n)
+ i07 = cython.declare(cython.int, n)
+ i08 = cython.declare(cython.sint, n)
+ i09 = cython.declare(cython.slong, n)
+ i10 = cython.declare(cython.long, n)
+ i11 = cython.declare(cython.ulong, n)
+ i12 = cython.declare(cython.slonglong, n)
+ i13 = cython.declare(cython.longlong, n)
+ i14 = cython.declare(cython.ulonglong, n)
+
+ i20 = cython.declare(cython.Py_ssize_t, n)
+ i21 = cython.declare(cython.size_t, n)
+ #
+ f00 = cython.declare(cython.float, n)
+ f01 = cython.declare(cython.double, n)
+ f02 = cython.declare(cython.longdouble, n)
+ #
+ ## z00 = cython.declare(cython.complex, n+1j)
+ ## z01 = cython.declare(cython.floatcomplex, n+1j)
+ ## z02 = cython.declare(cython.doublecomplex, n+1j)
+ ## z03 = cython.declare(cython.longdoublecomplex, n+1j)
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev