First pass at PersistentLocalScope
authorRobert Bradshaw <robertwb@math.washington.edu>
Thu, 19 Jun 2008 20:49:23 +0000 (13:49 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Thu, 19 Jun 2008 20:49:23 +0000 (13:49 -0700)
Cython/Compiler/Main.py
Cython/Compiler/Naming.py
Cython/Compiler/Nodes.py
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/Symtab.py

index 8ae57153a8504c3329374b302ff30ada12614dfa..7b8efb851e3f2f2ad3950965e0067e2db1b0e9c8 100644 (file)
@@ -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(),
index 4598e5b72eb69182bfd709a109c2ba8dd4179b4c..926b336c6dd00062c2fb646714ce9d93cd6db127 100644 (file)
@@ -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__"
 
index f363f17ddc360eb2be1eee7aa7e5b1ffb2389198..3e1291de380473541ffd6b72ba27371e3f6cabe5 100644 (file)
@@ -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:
index 35418182985eccc647b79f5c4a70939722c216e5..f20400d420f77e0eb2520661d6c45b1ac03d76a1 100644 (file)
@@ -185,7 +185,7 @@ class AnalyseExpressionsTransform(VisitorTransform):
         self.visitchildren(node)
         return node
 
-class MarkClosureNode(VisitorTransform):
+class MarkClosureVisitor(VisitorTransform):
     
     needs_closure = False
     
index b98bdc3f5df8eee0e461f17e3d1826b0389bfdd3..77a49cc11b57b503a5bcc8c66936a8d7b6a29a65 100644 (file)
@@ -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.