diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-10 20:08:11 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-10 20:08:11 +0100 |
commit | ae491055fae927dbdfabeea69ffee166a9720a68 (patch) | |
tree | 796b4d02b8ce077697bfd7bf3b4613d53b5189ec /py/runtime.c | |
parent | f31b6ff33428d813511845bc6604fae42073676e (diff) | |
download | micropython-ae491055fae927dbdfabeea69ffee166a9720a68.tar.gz micropython-ae491055fae927dbdfabeea69ffee166a9720a68.zip |
py: Fix float/complex binop returning NULL; implement complex power.
Diffstat (limited to 'py/runtime.c')
-rw-r--r-- | py/runtime.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/py/runtime.c b/py/runtime.c index ef07e39bff..499905a0fa 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -386,9 +386,19 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { } #if MICROPY_ENABLE_FLOAT } else if (MP_OBJ_IS_TYPE(rhs, &mp_type_float)) { - return mp_obj_float_binary_op(op, lhs_val, rhs); + mp_obj_t res = mp_obj_float_binary_op(op, lhs_val, rhs); + if (res == MP_OBJ_NULL) { + goto unsupported_op; + } else { + return res; + } } else if (MP_OBJ_IS_TYPE(rhs, &mp_type_complex)) { - return mp_obj_complex_binary_op(op, lhs_val, 0, rhs); + mp_obj_t res = mp_obj_complex_binary_op(op, lhs_val, 0, rhs); + if (res == MP_OBJ_NULL) { + goto unsupported_op; + } else { + return res; + } #endif } } @@ -438,6 +448,7 @@ generic_binary_op: // TODO implement dispatch for reverse binary ops // TODO specify in error message what the operator is +unsupported_op: nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "unsupported operand types for binary operator: '%s', '%s'", mp_obj_get_type_str(lhs), mp_obj_get_type_str(rhs))); |