Merge; disabled activation of unfinished closure code
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Tue, 1 Jul 2008 21:02:49 +0000 (23:02 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Tue, 1 Jul 2008 21:02:49 +0000 (23:02 +0200)
1  2 
Cython/Compiler/Main.py
Cython/Compiler/Nodes.py
Cython/Compiler/ParseTreeTransforms.py
Cython/TestUtils.py

index 6c77e432a96d2c75fad2cb96f751f1ec876f61f8,e3fbcb313a0471b3176065a03ac7edcb0aa8e531..9214dcac52d196276792b80308052aea30b93a53
@@@ -334,20 -334,18 +334,20 @@@ def create_generate_code(context, optio
      return generate_code
  
  def create_default_pipeline(context, options, result):
-     from ParseTreeTransforms import WithTransform, PostParse
+     from ParseTreeTransforms import WithTransform, NormalizeTree, PostParse
      from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform
 +    from ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor
      from ModuleNode import check_c_classes
      
      return [
          create_parse(context),
-         PostParse(),
-         WithTransform(),
-         MarkClosureVisitor(), 
-         AnalyseDeclarationsTransform(),
+         NormalizeTree(context),
+         PostParse(context),
+         WithTransform(context),
+         AnalyseDeclarationsTransform(context),
          check_c_classes,
-         AnalyseExpressionsTransform(),
-         CreateClosureClasses(),
+         AnalyseExpressionsTransform(context),
++#        CreateClosureClasses(context),
          create_generate_code(context, options, result)
      ]
  
Simple merge
index ccffb974c834e3d6640760d57cf5d58b48c02897,b31642dd2137c5e5fd4e09179eeba64ed7ff750e..d420d43fef4525e705fefd89b49101357cf450e8
@@@ -1,10 -1,13 +1,13 @@@
- from Cython.Compiler.Visitor import VisitorTransform, temp_name_handle
+ from Cython.Compiler.Visitor import VisitorTransform, temp_name_handle, CythonTransform
 +from Cython.Compiler.ModuleNode import ModuleNode
  from Cython.Compiler.Nodes import *
  from Cython.Compiler.ExprNodes import *
  from Cython.Compiler.TreeFragment import TreeFragment
+ from Cython.Utils import EncodedString
+ from Cython.Compiler.Errors import CompileError
+ from sets import Set as set
  
- class PostParse(VisitorTransform):
 -
+ class NormalizeTree(CythonTransform):
      """
      This transform fixes up a few things after parsing
      in order to make the parse tree more suitable for
@@@ -164,12 -232,8 +232,7 @@@ class AnalyseDeclarationsTransform(Cyth
          self.env_stack.pop()
          return node
          
-     def visit_Node(self, node):
-         self.visitchildren(node)
-         return node
- class AnalyseExpressionsTransform(VisitorTransform):
+ class AnalyseExpressionsTransform(CythonTransform):
 -
      def visit_ModuleNode(self, node):
          node.body.analyse_expressions(node.scope)
          self.visitchildren(node)
          self.visitchildren(node)
          return node
          
-     def visit_Node(self, node):
-         self.visitchildren(node)
-         return node
- class MarkClosureVisitor(VisitorTransform):
++class MarkClosureVisitor(CythonTransform):
 +    
 +    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):
++class CreateClosureClasses(CythonTransform):
 +    # 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
  
index 6383f44f34e3c9ea6e3286fcda73fa0e613fa89b,0588ee4acec4fc22e945a5387742b47d1d4f0a28..f3ceda0d293321727c987394f42072a3b7e039d1
@@@ -64,11 -55,37 +64,31 @@@ class CythonTest(unittest.TestCase)
          name = self.id()
          if name.startswith("__main__."): name = name[len("__main__."):]
          name = name.replace(".", "_")
-         return TreeFragment(code, name, pxds)
+         return TreeFragment(code, name, pxds, pipeline=pipeline)
  
      def treetypes(self, root):
 -        """Returns a string representing the tree by class names.
 -        There's a leading and trailing whitespace so that it can be
 -        compared by simple string comparison while still making test
 -        cases look ok."""
 -        w = NodeTypeWriter()
 -        w.visit(root)
 -        return u"\n".join([u""] + w.result + [u""])
 +        return treetypes(root)
  
+     def should_fail(self, func, exc_type=Exception):
+         """Calls "func" and fails if it doesn't raise the right exception
+         (any exception by default). Also returns the exception in question.
+         """
+         try:
+             func()
+             self.fail("Expected an exception of type %r" % exc_type)
+         except exc_type, e:
+             self.assert_(isinstance(e, exc_type))
+             return e
+     def should_not_fail(self, func):
+         """Calls func and succeeds if and only if no exception is raised
+         (i.e. converts exception raising into a failed testcase). Returns
+         the return value of func."""
+         try:
+             return func()
+         except:
+             self.fail()
  class TransformTest(CythonTest):
      """
      Utility base class for transform unit tests. It is based around constructing