diff options
author | John R. Lenton <jlenton@gmail.com> | 2014-01-03 02:27:08 +0000 |
---|---|---|
committer | John R. Lenton <jlenton@gmail.com> | 2014-01-03 02:27:08 +0000 |
commit | 4cb80582c4154f59118eab902872ab0c3a496303 (patch) | |
tree | 481f2cfa51c1efaee93118a3fc28bc755af504e0 /py | |
parent | aae7847508e2a9555ad3276c5cd4f42b2e66686c (diff) | |
download | micropython-4cb80582c4154f59118eab902872ab0c3a496303.tar.gz micropython-4cb80582c4154f59118eab902872ab0c3a496303.zip |
Add list addition (fixes: #39)
Diffstat (limited to 'py')
-rw-r--r-- | py/objlist.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/py/objlist.c b/py/objlist.c index ce16ab6fe9..b488a1964e 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -18,6 +18,7 @@ typedef struct _mp_obj_list_t { } mp_obj_list_t; static mp_obj_t mp_obj_new_list_iterator(mp_obj_list_t *list, int cur); +static mp_obj_list_t *list_new(uint n); /******************************************************************************/ /* list */ @@ -43,6 +44,21 @@ static mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { uint index = mp_get_index(o->base.type, o->len, rhs); return o->items[index]; } + case RT_BINARY_OP_ADD: + { + if (!MP_OBJ_IS_TYPE(rhs, &list_type)) { + return NULL; + } + mp_obj_list_t *p = rhs; + mp_obj_list_t *s = list_new(o->len + p->len); + for (int i = 0; i < o->len; i++) { + s->items[i] = o->items[i]; + } + for (int i = 0; i < p->len; i++) { + s->items[i+o->len] = p->items[i]; + } + return s; + } default: // op not supported return NULL; |