diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-04 15:08:23 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-04 15:08:23 +0100 |
commit | e8208a7f0246e584b09455e82cc7f27cf7f0fe95 (patch) | |
tree | c1dd95f882e9f187172a4d2a3cfc3ee07020664e /py/objint_longlong.c | |
parent | d7aadcfe1b35a54ea873c3b052abbeeb268a7202 (diff) | |
download | micropython-e8208a7f0246e584b09455e82cc7f27cf7f0fe95.tar.gz micropython-e8208a7f0246e584b09455e82cc7f27cf7f0fe95.zip |
py: Make False and True act like 0 and 1 for integer arithmetic.
Diffstat (limited to 'py/objint_longlong.c')
-rw-r--r-- | py/objint_longlong.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/py/objint_longlong.c b/py/objint_longlong.c index acbd477a9a..f4a65ce1d4 100644 --- a/py/objint_longlong.c +++ b/py/objint_longlong.c @@ -21,7 +21,7 @@ #define SUFFIX "" #endif -void int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { +void mp_obj_int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { if (MP_OBJ_IS_SMALL_INT(self_in)) { print(env, INT_FMT, MP_OBJ_SMALL_INT_VALUE(self_in)); } else { @@ -30,7 +30,7 @@ void int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj } } -mp_obj_t int_unary_op(int op, mp_obj_t o_in) { +mp_obj_t mp_obj_int_unary_op(int op, mp_obj_t o_in) { mp_obj_int_t *o = o_in; switch (op) { case MP_UNARY_OP_BOOL: return MP_BOOL(o->val != 0); @@ -41,7 +41,7 @@ mp_obj_t int_unary_op(int op, mp_obj_t o_in) { } } -mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { long long lhs_val; long long rhs_val; @@ -58,14 +58,8 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { } else if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_int)) { rhs_val = ((mp_obj_int_t*)rhs_in)->val; } else { - if (op == MP_BINARY_OP_MULTIPLY) { - if (MP_OBJ_IS_STR(rhs_in) || MP_OBJ_IS_TYPE(rhs_in, &mp_type_tuple) || MP_OBJ_IS_TYPE(rhs_in, &mp_type_list)) { - // multiply is commutative for these types, so delegate to them - return mp_binary_op(op, rhs_in, lhs_in); - } - } - // unsupported operation/type - return MP_OBJ_NULL; + // delegate to generic function to check for extra cases + return mp_obj_int_binary_op_extra_cases(op, lhs_in, rhs_in); } switch (op) { |