Fix PersistentNode analyse
authorRobert Bradshaw <robertwb@math.washington.edu>
Wed, 16 Jul 2008 03:37:27 +0000 (20:37 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Wed, 16 Jul 2008 03:37:27 +0000 (20:37 -0700)
Cython/Compiler/ExprNodes.py
Cython/Compiler/Main.py
Cython/Compiler/Visitor.py

index 7d7149bf018cb8c15c8419551c89de193de54cec..bf94764a8f9530d17be6d7229bd84324b216d7ec 100644 (file)
@@ -4037,6 +4037,7 @@ class PersistentNode(ExprNode):
     subexprs = ["arg"]
     temp_counter = 0
     generate_counter = 0
+    analyse_counter = 0
     result_code = None
     
     def __init__(self, arg, uses):
@@ -4045,13 +4046,15 @@ class PersistentNode(ExprNode):
         self.uses = uses
         
     def analyse_types(self, env):
-        self.arg.analyse_types(env)
-        self.type = self.arg.type
-        self.result_ctype = self.arg.result_ctype
-        self.is_temp = 1
+        if self.analyse_counter == 0:
+            self.arg.analyse_types(env)
+            self.type = self.arg.type
+            self.result_ctype = self.arg.result_ctype
+            self.is_temp = 1
+        self.analyse_counter += 1
     
     def calculate_result_code(self):
-        return self.arg.result_code
+        return self.result_code
 
     def generate_evaluation_code(self, code):
         if self.generate_counter == 0:
@@ -4071,13 +4074,16 @@ class PersistentNode(ExprNode):
     def allocate_temps(self, env, result=None):
         if self.temp_counter == 0:
             self.arg.allocate_temps(env)
-            if result is None:
-                self.result_code = env.allocate_temp(self.type)
-            else:
-                self.result_code = result
+            self.allocate_temp(env, result)
             self.arg.release_temp(env)
         self.temp_counter += 1
         
+    def allocate_temp(self, env, result=None):
+        if result is None:
+            self.result_code = env.allocate_temp(self.type)
+        else:
+            self.result_code = result
+        
     def release_temp(self, env):
         if self.temp_counter == self.uses:
             env.release_temp(self.result_code)
index c52b46ecbd424e91cf3c19122e77215185a99991..59fdf8403ced169664e16e1b8c11fd7eb52e7c93 100644 (file)
@@ -354,6 +354,7 @@ def create_generate_code(context, options, result):
     return generate_code
 
 def create_default_pipeline(context, options, result):
+    from Visitor import PrintTree
     from ParseTreeTransforms import WithTransform, NormalizeTree, PostParse
     from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform
     from ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor, DecoratorTransform
index 52fe2c2b4d6d19f81f743b35baa239141e83025a..3da3403b45412002014449b65ebda37a4286a24c 100644 (file)
@@ -213,6 +213,7 @@ class PrintTree(TreeVisitor):
     def __call__(self, tree, phase=None):
         print("Parse tree dump at phase '%s'" % phase)
         self.visit(tree)
+        return tree
 
     # Don't do anything about process_list, the defaults gives
     # nice-looking name[idx] nodes which will visually appear