mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 11:10:14 +01:00
Implement slicing for lists.
This commit is contained in:
10
py/objlist.c
10
py/objlist.c
@@ -136,7 +136,15 @@ static mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
|
||||
switch (op) {
|
||||
case RT_BINARY_OP_SUBSCR:
|
||||
{
|
||||
// list load
|
||||
#if MICROPY_ENABLE_SLICE
|
||||
if (MP_OBJ_IS_TYPE(rhs, &slice_type)) {
|
||||
machine_uint_t start, stop;
|
||||
assert(m_seq_get_fast_slice_indexes(o->len, rhs, &start, &stop));
|
||||
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);
|
||||
return o->items[index];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user