eliminate StopIterationNode
authorStefan Behnel <scoder@users.berlios.de>
Sat, 11 Dec 2010 02:15:46 +0000 (03:15 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Sat, 11 Dec 2010 02:15:46 +0000 (03:15 +0100)
Cython/Compiler/ExprNodes.py
Cython/Compiler/Nodes.py
Cython/Compiler/ParseTreeTransforms.py

index 544a04b459ec9c84cf29363948efb389626a2fcf..74eff016163695b8225cd2f4bcbf93e796397ce3 100755 (executable)
@@ -5033,20 +5033,6 @@ class YieldExprNode(ExprNode):
         else:
             code.putln(code.error_goto_if_null(Naming.sent_value_cname, self.pos))
 
-class StopIterationNode(Node):
-    # XXX: is it okay?
-    child_attrs = []
-
-    def analyse_expressions(self, env):
-        pass
-
-    def generate_function_definitions(self, env, code):
-        pass
-
-    def generate_execution_code(self, code):
-        code.putln('/* Stop iteration */')
-        code.putln('PyErr_SetNone(PyExc_StopIteration); %s' % code.error_goto(self.pos))
-
 #-------------------------------------------------------------------
 #
 #  Unary operator nodes
index ebb25d140f0c72434e032c07d01333be85fef4f1..8d8551f864b7afe05af1d556579e4d23a5d96fdd 100644 (file)
@@ -1372,6 +1372,9 @@ class FuncDefNode(StatNode, BlockNode):
         # -------------------------
         self.body.generate_execution_code(code)
 
+        if self.is_generator:
+            code.putln('PyErr_SetNone(PyExc_StopIteration); %s' % code.error_goto(self.pos))
+
         # ----- Default return value
         code.putln("")
         if self.return_type.is_pyobject:
index 0c137df0c493d78cafdab1a5c0b8d59f829acf4d..3c5d1665bcb1538e931bbe4bade7bdaecc84a9b4 100644 (file)
@@ -1407,12 +1407,10 @@ class MarkGeneratorVisitor(CythonTransform):
             error(collector.returns[0].pos, "'return' with argument inside generator")
         elif collector.yields:
             allocator = ClosureTempAllocator()
-            stop_node = ExprNodes.StopIterationNode(node.pos, arg=None)
             # XXX: move allocator inside local scope
             for y in collector.yields:
                 y.temp_allocator = allocator
             node.temp_allocator = allocator
-            node.body.stats.append(stop_node)
             node.is_generator = True
             node.needs_closure = True
             node.yields = collector.yields