'Emit a StopIteration at generator end and mark the generator exhausted.'

def return_from_generator(self, lower):

    indexval = Constant.int(self.resume_index_ptr.type.pointee, (-1))
    lower.builder.store(indexval, self.resume_index_ptr)
    self.call_conv.return_stop_iteration(lower.builder)
