From 267a657befd7aaccb24ee4aa40040963839db5f1 Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Mon, 4 Aug 2008 18:44:30 +0200 Subject: [PATCH] Added cython builtin scope --- Cython/Compiler/CythonScope.py | 20 ++++++++++++++++++++ Cython/Compiler/Main.py | 10 +++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 Cython/Compiler/CythonScope.py diff --git a/Cython/Compiler/CythonScope.py b/Cython/Compiler/CythonScope.py new file mode 100644 index 00000000..f4896221 --- /dev/null +++ b/Cython/Compiler/CythonScope.py @@ -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='') + +def create_cython_scope(context): + return CythonScope(context) diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py index 237d0a3c..a68d2ead 100644 --- a/Cython/Compiler/Main.py +++ b/Cython/Compiler/Main.py @@ -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): -- 2.26.2