Rober, here you have a patch populating builtin types in Bultin.py and Symtab.py. The full testsuite pass with Py2.3.6 and Py2.5.2 and Py2.6 (recent trunk checkout). Additionally, you have attached a new test (should go to 'tests/run' dir) for isinstance optimization with builtin types. Some notes below
* I deliberately added 'set' to the builtin types. If set is ever used in Cython sources, then that source will not compile in Python 2.3.x. Perhaps the 'set' and 'frozenset' builtins could be somewhat emulated in Py2.3.x with 'sets.Set' and 'set.InmutableSet' from the Python(2.3) stdlib. * The 'str' builtin is mapped to PyString_Type. In Py3, Cython #define's PyString_Type to PyBytes_Type, so this map is safe. Of course, I still believe that Cython should #define PyString_Type to PyUnicode_Type for Py3. But that discussion is for the future. Regards, and let me know if you ever push this. -- Lisandro Dalcín --------------- 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 3152381ccf89 Cython/Compiler/Builtin.py
--- a/Cython/Compiler/Builtin.py Sat Sep 27 14:35:03 2008 -0700
+++ b/Cython/Compiler/Builtin.py Mon Sep 29 12:26:31 2008 -0300
@@ -83,23 +83,34 @@ builtin_types_table = [
builtin_types_table = [
("type", "PyType_Type", []),
-# ("str", "PyBytes_Type", []),
+
+ ("bool", "PyBool_Type", []),
+ ("int", "PyInt_Type", []),
+ ("long", "PyLong_Type", []),
+ ("float", "PyFloat_Type", []),
+ ("complex", "PyComplex_Type", []),
+
+ ("bytes", "PyBytes_Type", []),
+ ("str", "PyString_Type", []),
("unicode", "PyUnicode_Type", []),
- ("file", "PyFile_Type", []),
-# ("slice", "PySlice_Type", []),
-# ("set", "PySet_Type", []),
- ("frozenset", "PyFrozenSet_Type", []),
("tuple", "PyTuple_Type", []),
-
+
("list", "PyList_Type", [("append", "OO", "i", "PyList_Append"),
("insert", "OiO", "i", "PyList_Insert"),
("sort", "O", "i", "PyList_Sort"),
("reverse","O", "i", "PyList_Reverse")]),
-
+
("dict", "PyDict_Type", [("items", "O", "O", "PyDict_Items"),
("keys", "O", "O", "PyDict_Keys"),
("values","O", "O", "PyDict_Values")]),
+
+ ("set", "PySet_Type", []),
+ ("frozenset", "PyFrozenSet_Type", []),
+
+ ("slice", "PySlice_Type", []),
+ ("file", "PyFile_Type", []),
+
]
builtin_structs_table = [
diff -r 3152381ccf89 Cython/Compiler/Symtab.py
--- a/Cython/Compiler/Symtab.py Sat Sep 27 14:35:03 2008 -0700
+++ b/Cython/Compiler/Symtab.py Mon Sep 29 12:26:31 2008 -0300
@@ -718,21 +718,27 @@ class BuiltinScope(Scope):
def builtin_scope(self):
return self
-
+
builtin_entries = {
+
+ "type": ["((PyObject*)&PyType_Type)", py_object_type],
+
+ "bool": ["((PyObject*)&PyBool_Type)", py_object_type],
"int": ["((PyObject*)&PyInt_Type)", py_object_type],
"long": ["((PyObject*)&PyLong_Type)", py_object_type],
"float": ["((PyObject*)&PyFloat_Type)", py_object_type],
-
- "str": ["((PyObject*)&PyBytes_Type)", py_object_type],
+ "complex":["((PyObject*)&PyComplex_Type)", py_object_type],
+
+ "bytes": ["((PyObject*)&PyBytes_Type)", py_object_type],
+ "str": ["((PyObject*)&PyString_Type)", py_object_type],
"unicode":["((PyObject*)&PyUnicode_Type)", py_object_type],
+
"tuple": ["((PyObject*)&PyTuple_Type)", py_object_type],
"list": ["((PyObject*)&PyList_Type)", py_object_type],
"dict": ["((PyObject*)&PyDict_Type)", py_object_type],
"set": ["((PyObject*)&PySet_Type)", py_object_type],
"frozenset": ["((PyObject*)&PyFrozenSet_Type)", py_object_type],
-
- "type": ["((PyObject*)&PyType_Type)", py_object_type],
+
"slice": ["((PyObject*)&PySlice_Type)", py_object_type],
"file": ["((PyObject*)&PyFile_Type)", py_object_type],
testisinstance.pyx
Description: Binary data
_______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
