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
# -------------------------
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:
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