From a19500d317606b438b66646435a697dc470312c5 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 25 Apr 2007 22:04:07 -0700 Subject: [PATCH] comments, builtin objects --- Cython/Compiler/PyrexTypes.py | 4 +++- Cython/Compiler/Symtab.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 267e637d..1cad0735 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -344,7 +344,9 @@ class CIntType(CNumericType): class CBIntType(CIntType): - + + # TODO: this should be a macro "(__ ? Py_True : Py_False)" + # and no error checking should be needed (just an incref). to_py_function = "PyBool_FromLong" from_py_function = "PyObject_IsTrue" diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index c1e57b39..6fd45f1a 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -455,6 +455,9 @@ class BuiltinScope(Scope): cname, type, arg_types, exception_value, exception_check = definition function = CFuncType(type, [CFuncTypeArg("", t, None) for t in arg_types], False, exception_value, exception_check) self.add_cfunction(name, function, None, cname, False) + for name, definition in self.builtin_entries.iteritems(): + cname, type = definition + self.declare_var(name, type, None, cname) self.cached_entries = [] self.undeclared_cached_entries = [] @@ -474,6 +477,7 @@ class BuiltinScope(Scope): return self # TODO: built in functions conflict with built in types of same name... + # TODO: perhapse these should all be declared in some universal .pxi file? builtin_functions = { "hasattr": ["PyObject_HasAttrString", c_bint_type, (py_object_type, c_char_ptr_type)], @@ -499,6 +503,27 @@ class BuiltinScope(Scope): # "tuple": ["PySequence_Tuple", py_object_type, (py_object_type, ), 0], } + + builtin_entries = { + "int": ["PyInt_Type", py_object_type], + "long": ["PyLong_Type", py_object_type], + "float": ["PyFloat_Type", py_object_type], + + "str": ["PyString_Type", py_object_type], + "tuple": ["PyTuple_Type", py_object_type], + "list": ["PyList_Type", py_object_type], + "dict": ["PyDict_Type", py_object_type], + "set": ["PySet_Type", py_object_type], + "frozenset": ["PyFrozenSet_Type", py_object_type], + + "type": ["PyType_Type", py_object_type], + "slice": ["PySlice_Type", py_object_type], + "file": ["PyFile_Type", py_object_type], + + "None": ["Py_None", py_object_type], + "False": ["Py_False", py_object_type], + "True": ["Py_True", py_object_type], + } class ModuleScope(Scope): # module_name string Python name of the module -- 2.26.2