From: Robert Bradshaw Date: Thu, 19 Jun 2008 20:49:23 +0000 (-0700) Subject: First pass at PersistentLocalScope X-Git-Tag: 0.9.8.1~49^2~116 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4510e2ef51c3f216d90119ddb53e1a3353dc2aed;p=cython.git First pass at PersistentLocalScope --- diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py index 8ae57153..7b8efb85 100644 --- a/Cython/Compiler/Main.py +++ b/Cython/Compiler/Main.py @@ -349,13 +349,14 @@ def create_generate_code(context, options): def create_default_pipeline(context, options): from ParseTreeTransforms import WithTransform, PostParse - from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform + from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform, MarkClosureVisitor from ModuleNode import check_c_classes return [ create_parse(context), PostParse(), WithTransform(), + MarkClosureVisitor(), AnalyseDeclarationsTransform(), check_c_classes, AnalyseExpressionsTransform(), diff --git a/Cython/Compiler/Naming.py b/Cython/Compiler/Naming.py index 4598e5b7..926b336c 100644 --- a/Cython/Compiler/Naming.py +++ b/Cython/Compiler/Naming.py @@ -72,6 +72,7 @@ optional_args_cname = pyrex_prefix + "optional_args" no_opt_args = pyrex_prefix + "no_opt_args" import_star = pyrex_prefix + "import_star" import_star_set = pyrex_prefix + "import_star_set" +scope_obj_cname = pyrex_prefix + "scope" line_c_macro = "__LINE__" diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index f363f17d..3e1291de 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -10,7 +10,7 @@ import Naming import PyrexTypes import TypeSlots from PyrexTypes import py_object_type, error_type, CTypedefType, CFuncType -from Symtab import ModuleScope, LocalScope, \ +from Symtab import ModuleScope, LocalScope, PersistentLocalScope, \ StructOrUnionScope, PyClassScope, CClassScope from Cython.Utils import open_new_file, replace_suffix, EncodedString import Options @@ -773,9 +773,11 @@ class FuncDefNode(StatNode, BlockNode): # return_type PyrexType # #filename string C name of filename string const # entry Symtab.Entry + # needs_closure boolean Whether or not this function has inner functions/classes/yield py_func = None assmt = None + needs_closure = False def analyse_default_values(self, env): genv = env.global_scope() @@ -807,7 +809,10 @@ class FuncDefNode(StatNode, BlockNode): genv = env while env.is_py_class_scope or env.is_c_class_scope: env = env.outer_scope - lenv = LocalScope(name = self.entry.name, outer_scope = genv) + if self.needs_closure: + lenv = PersistentLocalScope(name = self.entry.name, outer_scope = genv) + else: + lenv = LocalScope(name = self.entry.name, outer_scope = genv) lenv.return_type = self.return_type type = self.entry.type if type.is_cfunction: diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index 35418182..f20400d4 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -185,7 +185,7 @@ class AnalyseExpressionsTransform(VisitorTransform): self.visitchildren(node) return node -class MarkClosureNode(VisitorTransform): +class MarkClosureVisitor(VisitorTransform): needs_closure = False diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index b98bdc3f..77a49cc1 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -1,5 +1,5 @@ # -# Pyrex - Symbol Table +# Symbol Table # import re @@ -1121,6 +1121,11 @@ class LocalScope(Scope): self.entries[name] = entry +class PersistentLocalScope(LocalScope): + + def mangle(self, prefix, name): + return "%s->%s" % (scope_obj_cname, name) + class StructOrUnionScope(Scope): # Namespace of a C struct or union.