def list_pop(context, builder, sig, args): inst = ListInstance(context, builder, sig.args[0], args[0]) n = inst.size cgutils.guard_zero(context, builder, n, (IndexError, "pop from empty list")) n = builder.sub(n, ir.Constant(n.type, 1)) res = inst.getitem(n) inst.incref_value(res) # incref the pop'ed element inst.clear_value(n) # clear the storage space inst.resize(n) return impl_ret_new_ref(context, builder, sig.return_type, res)
def list_pop(context, builder, sig, args): inst = ListInstance(context, builder, sig.args[0], args[0]) idx = inst.fix_index(args[1]) n = inst.size cgutils.guard_zero(context, builder, n, (IndexError, "pop from empty list")) inst.guard_index(idx, "pop index out of range") res = inst.getitem(idx) one = ir.Constant(n.type, 1) n = builder.sub(n, ir.Constant(n.type, 1)) inst.move(idx, builder.add(idx, one), builder.sub(n, idx)) inst.resize(n) return impl_ret_new_ref(context, builder, sig.return_type, res)