diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-17 22:10:53 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-17 22:10:53 +0100 |
commit | 729f7b42d65c016c9d5f27fb8a8122869f06c129 (patch) | |
tree | 8d8d8c2a89ff9011b06650c256a2d5f2458c930c /py/objlist.c | |
parent | de7c425139c92745280b62f7ebb756def96d072a (diff) |
py: Merge BINARY_OP_SUBSCR and store_subscr (w/ delete) into subscr.
mp_obj_t->subscr now does load/store/delete.
Diffstat (limited to 'py/objlist.c')
-rw-r--r-- | py/objlist.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/py/objlist.c b/py/objlist.c index fa7d2bc1c..28011dc83 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -88,24 +88,7 @@ STATIC mp_obj_t list_unary_op(int op, mp_obj_t self_in) { STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { mp_obj_list_t *o = lhs; switch (op) { - case MP_BINARY_OP_SUBSCR: - { -#if MICROPY_ENABLE_SLICE - if (MP_OBJ_IS_TYPE(rhs, &mp_type_slice)) { - machine_uint_t start, stop; - if (!m_seq_get_fast_slice_indexes(o->len, rhs, &start, &stop)) { - assert(0); - } - mp_obj_list_t *res = list_new(stop - start); - m_seq_copy(res->items, o->items + start, res->len, mp_obj_t); - return res; - } -#endif - uint index = mp_get_index(o->base.type, o->len, rhs, false); - return o->items[index]; - } - case MP_BINARY_OP_ADD: - { + case MP_BINARY_OP_ADD: { if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) { return NULL; } @@ -114,8 +97,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { m_seq_cat(s->items, o->items, o->len, p->items, p->len, mp_obj_t); return s; } - case MP_BINARY_OP_INPLACE_ADD: - { + case MP_BINARY_OP_INPLACE_ADD: { if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) { return NULL; } @@ -144,14 +126,32 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { } } -STATIC bool list_store_item(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { if (value == MP_OBJ_NULL) { + // delete mp_obj_t args[2] = {self_in, index}; list_pop(2, args); + return mp_const_none; + } else if (value == MP_OBJ_SENTINEL) { + // load + mp_obj_list_t *self = self_in; +#if MICROPY_ENABLE_SLICE + if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) { + machine_uint_t start, stop; + if (!m_seq_get_fast_slice_indexes(self->len, index, &start, &stop)) { + assert(0); + } + mp_obj_list_t *res = list_new(stop - start); + m_seq_copy(res->items, self->items + start, res->len, mp_obj_t); + return res; + } +#endif + uint index_val = mp_get_index(self->base.type, self->len, index, false); + return self->items[index_val]; } else { mp_obj_list_store(self_in, index, value); + return mp_const_none; } - return true; } STATIC mp_obj_t list_getiter(mp_obj_t o_in) { @@ -360,7 +360,7 @@ const mp_obj_type_t mp_type_list = { .make_new = list_make_new, .unary_op = list_unary_op, .binary_op = list_binary_op, - .store_item = list_store_item, + .subscr = list_subscr, .getiter = list_getiter, .locals_dict = (mp_obj_t)&list_locals_dict, }; |