comments, builtin objects
authorRobert Bradshaw <robertwb@math.washington.edu>
Thu, 26 Apr 2007 05:04:07 +0000 (22:04 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Thu, 26 Apr 2007 05:04:07 +0000 (22:04 -0700)
Cython/Compiler/PyrexTypes.py
Cython/Compiler/Symtab.py

index 267e637d1f3aedc56024bec4e415d62af06c385b..1cad073580202bc8351e0fade09e555098e7043f 100644 (file)
@@ -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"
     
index c1e57b394e4f71724f726e1f099ad1a949c7bdbc..6fd45f1aea64e7d51558f97518c58df82aa80edc 100644 (file)
@@ -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