Implement __bool__ and __len__ via unary_op virtual method for all types.

__bool__() and __len__() are just the same as __neg__() or __invert__(),
and require efficient dispatching implementation (not requiring search/lookup).
type->unary_op() is just the right choice for this short of adding
standalone virtual method(s) to already big mp_obj_type_t structure.
This commit is contained in:
Paul Sokolovsky
2014-01-30 04:37:19 +02:00
parent cdd2c62e07
commit c1d9bbc345
13 changed files with 52 additions and 16 deletions

View File

@@ -18,7 +18,7 @@ static void none_print(void (*print)(void *env, const char *fmt, ...), void *env
static mp_obj_t none_unary_op(int op, mp_obj_t o_in) {
switch (op) {
case RT_UNARY_OP_NOT: return mp_const_true;
case RT_UNARY_OP_BOOL: return mp_const_false;
default: return MP_OBJ_NULL; // op not supported for None
}
}