summaryrefslogtreecommitdiff
path: root/py/objtuple.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-27 23:15:32 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-27 23:15:32 +0000
commit4e8dc8c41b6f68269571fe218f7292fc86cf3ddb (patch)
tree535eb325a69877eae7caba92d30fd0da5640fff7 /py/objtuple.c
parentaddf60b2e6176d8cce23c5608dee10ce196db94b (diff)
py: Add unary op not for NoneType, bool, tuple, list, dict; fix for int.
Diffstat (limited to 'py/objtuple.c')
-rw-r--r--py/objtuple.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/py/objtuple.c b/py/objtuple.c
index ec35ef855..754fe4b66 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -73,6 +73,14 @@ static mp_obj_t tuple_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
}
}
+static mp_obj_t tuple_unary_op(int op, mp_obj_t self_in) {
+ mp_obj_tuple_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 tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
mp_obj_tuple_t *o = lhs;
switch (op) {
@@ -97,6 +105,7 @@ const mp_obj_type_t tuple_type = {
"tuple",
.print = tuple_print,
.make_new = tuple_make_new,
+ .unary_op = tuple_unary_op,
.binary_op = tuple_binary_op,
.getiter = tuple_getiter,
};