avoid calling TupleNode.allocate_temps() in iter-dict transform
authorStefan Behnel <scoder@users.berlios.de>
Tue, 18 Nov 2008 18:36:29 +0000 (19:36 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 18 Nov 2008 18:36:29 +0000 (19:36 +0100)
Cython/Compiler/Optimize.py

index b5f2efa244a2639abafd191f8844eeee1cf70f22..49f7323a33c2036eb190be4b7730fcc34c1049ae 100644 (file)
@@ -51,7 +51,6 @@ class DictIterTransform(Visitor.VisitorTransform):
             return node
         dict_obj = function.obj
         method = function.attribute
-        env = self.env_stack[-1]
 
         keys = values = False
         if method == 'iterkeys':
@@ -121,12 +120,20 @@ class DictIterTransform(Visitor.VisitorTransform):
                                       stats = [node.body])
 
         if tuple_target:
-            tuple_result = ExprNodes.TupleNode(
+            temp = UtilNodes.TempHandle(py_object_ptr)
+            temps.append(temp)
+            temp_tuple = temp.ref(tuple_target.pos)
+            class TempTupleNode(ExprNodes.TupleNode):
+                # FIXME: remove this after result-code refactoring
+                def result(self):
+                    return temp_tuple.result()
+
+            tuple_result = TempTupleNode(
                 pos = tuple_target.pos,
-                args = [key_cast, value_cast]
+                args = [key_cast, value_cast],
+                is_temp = 1,
+                type = Builtin.tuple_type,
                 )
-            tuple_result.analyse_types(env)
-            tuple_result.allocate_temps(env)
             body.stats.insert(0, Nodes.SingleAssignmentNode(
                     pos = tuple_target.pos,
                     lhs = tuple_target,
@@ -174,17 +181,6 @@ class DictIterTransform(Visitor.VisitorTransform):
                 stats = result_code
                 ))
 
-    def visit_ModuleNode(self, node):
-        self.env_stack = [node.scope]
-        self.visitchildren(node)
-        return node
-
-    def visit_FuncDefNode(self, node):
-        self.env_stack.append(node.local_scope)
-        self.visitchildren(node)
-        self.env_stack.pop()
-        return node
-
     def visit_Node(self, node):
         self.visitchildren(node)
         return node