py: Add MP_OBJ_STOP_ITERATION and make good use of it.

Also make consistent use of MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL.
This helps a lot in debugging and understanding of function API.
This commit is contained in:
Damien George
2014-04-17 23:19:36 +01:00
parent 1e935d8689
commit ea8d06c39d
28 changed files with 130 additions and 121 deletions

View File

@@ -52,7 +52,7 @@ mp_obj_t mp_obj_tuple_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
mp_obj_t iterable = mp_getiter(args[0]);
mp_obj_t item;
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
if (len >= alloc) {
items = m_renew(mp_obj_t, items, alloc, alloc * 2);
alloc *= 2;
@@ -88,7 +88,7 @@ mp_obj_t tuple_unary_op(int op, mp_obj_t self_in) {
switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(self->len != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len);
default: return MP_OBJ_NULL; // op not supported for None
default: return MP_OBJ_NOT_SUPPORTED;
}
}
@@ -249,7 +249,7 @@ STATIC mp_obj_t tuple_it_iternext(mp_obj_t self_in) {
self->cur += 1;
return o_out;
} else {
return MP_OBJ_NULL;
return MP_OBJ_STOP_ITERATION;
}
}