From eb6e9b56626b8ae2e3c71844f31a2f571e7220ec Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 11 Dec 2010 03:15:46 +0100 Subject: [PATCH] eliminate StopIterationNode --- Cython/Compiler/ExprNodes.py | 14 -------------- Cython/Compiler/Nodes.py | 3 +++ Cython/Compiler/ParseTreeTransforms.py | 2 -- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 544a04b4..74eff016 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -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 diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index ebb25d14..8d8551f8 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -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: diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index 0c137df0..3c5d1665 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -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 -- 2.26.2