diff options
author | Damien George <damien.p.george@gmail.com> | 2014-01-27 23:15:32 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-01-27 23:15:32 +0000 |
commit | 4e8dc8c41b6f68269571fe218f7292fc86cf3ddb (patch) | |
tree | 535eb325a69877eae7caba92d30fd0da5640fff7 /py/objlist.c | |
parent | addf60b2e6176d8cce23c5608dee10ce196db94b (diff) | |
download | micropython-4e8dc8c41b6f68269571fe218f7292fc86cf3ddb.tar.gz micropython-4e8dc8c41b6f68269571fe218f7292fc86cf3ddb.zip |
py: Add unary op not for NoneType, bool, tuple, list, dict; fix for int.
Diffstat (limited to 'py/objlist.c')
-rw-r--r-- | py/objlist.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/py/objlist.c b/py/objlist.c index 2e9a8705ff..1e8930eeea 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -119,6 +119,14 @@ static bool list_cmp_helper(int op, mp_obj_t self_in, mp_obj_t another_in) { return true; } +static mp_obj_t list_unary_op(int op, mp_obj_t self_in) { + mp_obj_list_t *self = self_in; + switch (op) { + case RT_UNARY_OP_NOT: if (self->len == 0) { return mp_const_true; } else { return mp_const_false; } + default: return MP_OBJ_NULL; // op not supported for None + } +} + static mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { mp_obj_list_t *o = lhs; switch (op) { @@ -395,6 +403,7 @@ const mp_obj_type_t list_type = { "list", .print = list_print, .make_new = list_make_new, + .unary_op = list_unary_op, .binary_op = list_binary_op, .getiter = list_getiter, .methods = list_type_methods, |