def iternext_zip(context, builder, sig, args, result): [zip_type] = sig.args [zipobj] = args zipobj = context.make_helper(builder, zip_type, value=zipobj) if len(zipobj) == 0: # zip() is an empty iterator result.set_exhausted() return p_ret_tup = cgutils.alloca_once(builder, context.get_value_type(zip_type.yield_type)) p_is_valid = cgutils.alloca_once_value(builder, value=cgutils.true_bit) for i, (iterobj, srcty) in enumerate(zip(zipobj, zip_type.source_types)): is_valid = builder.load(p_is_valid) # Avoid calling the remaining iternext if a iterator has been exhausted with builder.if_then(is_valid): srcres = call_iternext(context, builder, srcty, iterobj) is_valid = builder.and_(is_valid, srcres.is_valid()) builder.store(is_valid, p_is_valid) val = srcres.yielded_value() ptr = cgutils.gep_inbounds(builder, p_ret_tup, 0, i) builder.store(val, ptr) is_valid = builder.load(p_is_valid) result.set_valid(is_valid) with builder.if_then(is_valid): result.yield_(builder.load(p_ret_tup))
def iternext_enumerate(context, builder, sig, args, result): [enumty] = sig.args [enum] = args enum = context.make_helper(builder, enumty, value=enum) count = builder.load(enum.count) ncount = builder.add(count, context.get_constant(types.intp, 1)) builder.store(ncount, enum.count) srcres = call_iternext(context, builder, enumty.source_type, enum.iter) is_valid = srcres.is_valid() result.set_valid(is_valid) with builder.if_then(is_valid): srcval = srcres.yielded_value() result.yield_(context.make_tuple(builder, enumty.yield_type, [count, srcval]))
def iternext_enumerate(context, builder, sig, args, result): [enumty] = sig.args [enum] = args enumcls = make_enumerate_cls(enumty) enum = enumcls(context, builder, value=enum) count = builder.load(enum.count) ncount = builder.add(count, context.get_constant(types.intp, 1)) builder.store(ncount, enum.count) srcres = call_iternext(context, builder, enumty.source_type, enum.iter) is_valid = srcres.is_valid() result.set_valid(is_valid) with builder.if_then(is_valid): srcval = srcres.yielded_value() result.yield_(cgutils.make_anonymous_struct(builder, [count, srcval]))
def iternext_enumerate(context, builder, sig, args, result): [enumty] = sig.args [enum] = args enumcls = make_enumerate_cls(enumty) enum = enumcls(context, builder, value=enum) count = builder.load(enum.count) ncount = builder.add(count, context.get_constant(types.intp, 1)) builder.store(ncount, enum.count) srcres = call_iternext(context, builder, enumty.source_type, enum.iter) is_valid = srcres.is_valid() result.set_valid(is_valid) with cgutils.ifthen(builder, is_valid): srcval = srcres.yielded_value() result.yield_(cgutils.make_anonymous_struct(builder, [count, srcval]))
def iternext_enumerate(context, builder, sig, args, result): [enumty] = sig.args [enum] = args enum = context.make_helper(builder, enumty, value=enum) count = builder.load(enum.count) ncount = builder.add(count, context.get_constant(types.intp, 1)) builder.store(ncount, enum.count) srcres = call_iternext(context, builder, enumty.source_type, enum.iter) is_valid = srcres.is_valid() result.set_valid(is_valid) with builder.if_then(is_valid): srcval = srcres.yielded_value() # As a iternext_impl function, this will incref the yieled value. # We need to release the new reference from call_iternext. if context.enable_nrt: context.nrt.decref(builder, enumty.yield_type[1], srcval) result.yield_( context.make_tuple(builder, enumty.yield_type, [count, srcval]))
def iternext_zip(context, builder, sig, args, result): [zip_type] = sig.args [zipobj] = args zipobj = context.make_helper(builder, zip_type, value=zipobj) if len(zipobj) == 0: # zip() is an empty iterator result.set_exhausted() return is_valid = context.get_constant(types.boolean, True) values = [] for iterobj, srcty in zip(zipobj, zip_type.source_types): srcres = call_iternext(context, builder, srcty, iterobj) is_valid = builder.and_(is_valid, srcres.is_valid()) values.append(srcres.yielded_value()) result.set_valid(is_valid) with builder.if_then(is_valid): result.yield_(context.make_tuple(builder, zip_type.yield_type, values))
def iternext_enumerate(context, builder, sig, args, result): [enumty] = sig.args [enum] = args enum = context.make_helper(builder, enumty, value=enum) count = builder.load(enum.count) ncount = builder.add(count, context.get_constant(types.intp, 1)) builder.store(ncount, enum.count) srcres = call_iternext(context, builder, enumty.source_type, enum.iter) is_valid = srcres.is_valid() result.set_valid(is_valid) with builder.if_then(is_valid): srcval = srcres.yielded_value() # As a iternext_impl function, this will incref the yieled value. # We need to release the new reference from call_iternext. if context.enable_nrt: context.nrt.decref(builder, enumty.yield_type[1], srcval) result.yield_(context.make_tuple(builder, enumty.yield_type, [count, srcval]))
def iternext_zip(context, builder, sig, args, result): [zip_type] = sig.args [zipobj] = args zipcls = make_zip_cls(zip_type) zipobj = zipcls(context, builder, value=zipobj) if len(zipobj) == 0: # zip() is an empty iterator result.set_exhausted() return is_valid = context.get_constant(types.boolean, True) values = [] for iterobj, srcty in zip(zipobj, zip_type.source_types): srcres = call_iternext(context, builder, srcty, iterobj) is_valid = builder.and_(is_valid, srcres.is_valid()) values.append(srcres.yielded_value()) result.set_valid(is_valid) with builder.if_then(is_valid): result.yield_(cgutils.make_anonymous_struct(builder, values))
def iternext_zip(context, builder, sig, args, result): [zip_type] = sig.args [zipobj] = args zipcls = make_zip_cls(zip_type) zipobj = zipcls(context, builder, value=zipobj) if len(zipobj) == 0: # zip() is an empty iterator result.set_exhausted() return is_valid = context.get_constant(types.boolean, True) values = [] for iterobj, srcty in zip(zipobj, zip_type.source_types): srcres = call_iternext(context, builder, srcty, iterobj) is_valid = builder.and_(is_valid, srcres.is_valid()) values.append(srcres.yielded_value()) result.set_valid(is_valid) with cgutils.ifthen(builder, is_valid): result.yield_(cgutils.make_anonymous_struct(builder, values))