@contextmanager
def for_range_slice_generic(builder, start, stop, step):
 intp = start.type
 is_pos_step = builder.icmp_signed('>=', step, ir.Constant(intp, 0))
 pos_for_range = for_range_slice(builder, start, stop, step, intp, inc=True)
 neg_for_range = for_range_slice(builder, start, stop, step, intp, inc=False)
 @contextmanager
 def cm_cond(cond, inner_cm):
  with cond:
   with inner_cm as value:
    (yield value)
 with builder.if_else(is_pos_step, likely=True) as (then, otherwise):
  (yield (cm_cond(then, pos_for_range), cm_cond(otherwise, neg_for_range)))

@ contextmanager def for_range_slice_generic ( builder , start , stop , step ) : intp = start . type is_pos_step = builder . icmp_signed ( '>=' , step , ir . Constant ( intp , 0 ) ) pos_for_range = for_range_slice ( builder , start , stop , step , intp , inc = True ) neg_for_range = for_range_slice ( builder , start , stop , step , intp , inc = False ) @ contextmanager def cm_cond ( cond , inner_cm ) : with cond : with inner_cm as value : ( yield value ) with builder . if_else ( is_pos_step , likely = True ) as ( then , otherwise ) : ( yield ( cm_cond ( then , pos_for_range ) , cm_cond ( otherwise , neg_for_range ) ) )
a helper wrapper for for_range_slice() .