summaryrefslogtreecommitdiffstatshomepage
path: root/py/objlist.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-02 03:32:55 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-02 03:32:55 +0200
commit13cfabd1b265d974e53e03d1d77eac7dc1d000e5 (patch)
tree61ab58a956a1fd39bd89c1a400dd56d90e11483e /py/objlist.c
parent7364af2d8cd72467bbb3bf135b29fae47105b232 (diff)
downloadmicropython-13cfabd1b265d974e53e03d1d77eac7dc1d000e5.tar.gz
micropython-13cfabd1b265d974e53e03d1d77eac7dc1d000e5.zip
Implement slicing for lists.
Diffstat (limited to 'py/objlist.c')
-rw-r--r--py/objlist.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/py/objlist.c b/py/objlist.c
index b28ca81279..f3db99a637 100644
--- a/py/objlist.c
+++ b/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];
}