Added cython builtin scope
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Mon, 4 Aug 2008 16:44:30 +0000 (18:44 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Mon, 4 Aug 2008 16:44:30 +0000 (18:44 +0200)
Cython/Compiler/CythonScope.py [new file with mode: 0644]
Cython/Compiler/Main.py

diff --git a/Cython/Compiler/CythonScope.py b/Cython/Compiler/CythonScope.py
new file mode 100644 (file)
index 0000000..f489622
--- /dev/null
@@ -0,0 +1,20 @@
+from Symtab import ModuleScope
+from PyrexTypes import *
+
+shape_func_type = CFuncType(
+    c_ptr_type(c_py_ssize_t_type),
+    [CFuncTypeArg("buffer", py_object_type, None)])
+
+class CythonScope(ModuleScope):
+    def __init__(self, context):
+        ModuleScope.__init__(self, u'cython', None, context)
+        self.pxd_file_loaded = True
+
+        self.shape_entry = self.declare_cfunction('shape',
+                                                  shape_func_type,
+                                                  pos=None,
+                                                  visibility='public',
+                                                  cname='<error>')
+
+def create_cython_scope(context):
+    return CythonScope(context)
index 237d0a3c0d89458ea59e9a99a13f7df0013fe1a0..a68d2ead1608ca23bf968a564411353b1352f889 100644 (file)
@@ -23,6 +23,7 @@ from Errors import PyrexError, CompileError, error
 from Symtab import BuiltinScope, ModuleScope
 from Cython import Utils
 from Cython.Utils import open_new_file, replace_suffix
+import CythonScope
 
 module_name_pattern = re.compile(r"[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$")
 
@@ -60,8 +61,9 @@ class Context:
     
     def __init__(self, include_directories, pragma_overrides):
         #self.modules = {"__builtin__" : BuiltinScope()}
-        import Builtin
+        import Builtin, CythonScope
         self.modules = {"__builtin__" : Builtin.builtin_scope}
+        self.modules["cython"] = CythonScope.create_cython_scope(self)
         self.include_directories = include_directories
         self.future_directives = set()
         self.pragma_overrides = pragma_overrides
@@ -77,7 +79,7 @@ class Context:
         from ParseTreeTransforms import WithTransform, NormalizeTree, PostParse, PxdPostParse
         from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform
         from ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor, DecoratorTransform
-        from ParseTreeTransforms import ResolveOptions
+        from ParseTreeTransforms import ResolveOptions, SpecialFunctions
         from Optimize import FlattenInListTransform, SwitchTransform, OptimizeRefcounting
         from Buffer import IntroduceBufferAuxiliaryVars
         from ModuleNode import check_c_classes
@@ -103,6 +105,7 @@ class Context:
             AnalyseExpressionsTransform(self),
             SwitchTransform(),
             OptimizeRefcounting(self),
+            SpecialFunctions(self),
             #        CreateClosureClasses(context),
             ]
 
@@ -127,7 +130,7 @@ class Context:
             return module_node
 
         return ([
-                create_parse(self)
+                create_parse(self),
             ] + self.create_pipeline(pxd=False) + [
                 inject_pxd_code,
                 generate_pyx_code,
@@ -182,6 +185,7 @@ class Context:
         if debug_find_module:
             print("Context.find_module: module_name = %s, relative_to = %s, pos = %s, need_pxd = %s" % (
                     module_name, relative_to, pos, need_pxd))
+
         scope = None
         pxd_pathname = None
         if not module_name_pattern.match(module_name):