summaryrefslogtreecommitdiffstatshomepage
path: root/py/objlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/objlist.c')
-rw-r--r--py/objlist.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/py/objlist.c b/py/objlist.c
index 08c1716179..4432b2447b 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -173,6 +173,26 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
uint index_val = mp_get_index(self->base.type, self->len, index, false);
return self->items[index_val];
} else {
+#if MICROPY_ENABLE_SLICE
+ if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
+ mp_obj_list_t *self = self_in;
+ assert(MP_OBJ_IS_TYPE(value, &mp_type_list));
+ mp_obj_list_t *slice = value;
+ machine_uint_t start, stop;
+ if (!mp_seq_get_fast_slice_indexes(self->len, index, &start, &stop)) {
+ assert(0);
+ }
+ int len_adj = slice->len - (stop - start);
+ //printf("Len adj: %d\n", len_adj);
+ assert(len_adj <= 0);
+ mp_seq_replace_slice_no_grow(self->items, self->len, start, stop, slice->items, slice->len, mp_obj_t);
+ // Clear "freed" elements at the end of list
+ mp_seq_clear(self->items, self->len + len_adj, self->len, sizeof(*self->items));
+ self->len += len_adj;
+ // TODO: apply allocation policy re: alloc_size
+ return mp_const_none;
+ }
+#endif
mp_obj_list_store(self_in, index, value);
return mp_const_none;
}