merge
authorRobert Bradshaw <robertwb@math.washington.edu>
Thu, 19 Jun 2008 23:54:55 +0000 (16:54 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Thu, 19 Jun 2008 23:54:55 +0000 (16:54 -0700)
1  2 
Cython/Compiler/Main.py
Cython/Compiler/ParseTreeTransforms.py

index 7b8efb851e3f2f2ad3950965e0067e2db1b0e9c8,481946135c2061ba0ad746e87dd95eb9d2f9459f..6c77e432a96d2c75fad2cb96f751f1ec876f61f8
@@@ -347,9 -333,10 +333,10 @@@ def create_generate_code(context, optio
          return result
      return generate_code
  
- def create_default_pipeline(context, options):
+ def create_default_pipeline(context, options, result):
      from ParseTreeTransforms import WithTransform, PostParse
-     from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform, MarkClosureVisitor
+     from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform
 -    from ParseTreeTransforms import CreateClosureClasses
++    from ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor
      from ModuleNode import check_c_classes
      
      return [
index f20400d420f77e0eb2520661d6c45b1ac03d76a1,ffb79e71513218e83993ac7b0e69d113d17ba608..ccffb974c834e3d6640760d57cf5d58b48c02897
@@@ -185,26 -184,35 +184,58 @@@ class AnalyseExpressionsTransform(Visit
          self.visitchildren(node)
          return node
  
 +class MarkClosureVisitor(VisitorTransform):
 +    
 +    needs_closure = False
 +    
 +    def visit_FuncDefNode(self, node):
 +        self.needs_closure = False
 +        self.visitchildren(node)
 +        node.needs_closure = self.needs_closure
 +        self.needs_closure = True
 +        return node
 +        
 +    def visit_ClassDefNode(self, node):
 +        self.visitchildren(node)
 +        self.needs_closure = True
 +        return node
 +        
 +    def visit_YieldNode(self, node):
 +        self.needs_closure = True
 +        
 +    def visit_Node(self, node):
 +        self.visitchildren(node)
 +        return node
 +
+ class CreateClosureClasses(VisitorTransform):
+     # Output closure classes in module scope for all functions
+     # that need it. 
+     
+     def visit_ModuleNode(self, node):
+         self.module_scope = node.scope
+         self.visitchildren(node)
+         return node
+     def create_class_from_scope(self, node, target_module_scope):
+         as_name = temp_name_handle("closure")
+         func_scope = node.local_scope
+         entry = target_module_scope.declare_c_class(name = as_name,
+             pos = node.pos, defining = True, implementing = True)
+         class_scope = entry.type.scope
+         for entry in func_scope.entries.values():
+             class_scope.declare_var(pos=node.pos,
+                                     name=entry.name,
+                                     cname=entry.cname,
+                                     type=entry.type,
+                                     is_cdef=True)
+             
+     def visit_FuncDefNode(self, node):
+         self.create_class_from_scope(node, self.module_scope)
+         return node
+         
+     def visit_Node(self, node):
+         self.visitchildren(node)
+         return node