diff options
author | Damien George <damien.p.george@gmail.com> | 2014-01-10 15:17:17 -0800 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-01-10 15:17:17 -0800 |
commit | 46c9e9713208b3d7bda1db400f3af595ae3d64e9 (patch) | |
tree | 69134fc07c440212738a2e60b5abd3173f73d02c /py | |
parent | 745ce4c2ad710251fd3a0bc944cfc783928587e3 (diff) | |
parent | 074d3b5f869a2bad646ba6c2626b05d405e21f41 (diff) | |
download | micropython-46c9e9713208b3d7bda1db400f3af595ae3d64e9.tar.gz micropython-46c9e9713208b3d7bda1db400f3af595ae3d64e9.zip |
Merge pull request #134 from pfalcon/list-mul
list: Implement list multiplication.
Diffstat (limited to 'py')
-rw-r--r-- | py/objlist.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/py/objlist.c b/py/objlist.c index 9d8caee339..ce55aa5100 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -81,6 +81,21 @@ static mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { memcpy(s->items + o->len, p->items, sizeof(mp_obj_t) * p->len); return s; } + case RT_BINARY_OP_MULTIPLY: + { + if (!MP_OBJ_IS_SMALL_INT(rhs)) { + return NULL; + } + int n = MP_OBJ_SMALL_INT_VALUE(rhs); + int len = o->len; + mp_obj_list_t *s = list_new(len * n); + mp_obj_t *dest = s->items; + for (int i = 0; i < n; i++) { + memcpy(dest, o->items, sizeof(mp_obj_t) * len); + dest += len; + } + return s; + } default: // op not supported return NULL; |