diff --git a/py/objtype.c b/py/objtype.c index 46e892a12..53408a07e 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -323,7 +323,7 @@ mp_obj_t instance_make_new(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, c return o; } -STATIC const qstr unary_op_method_name[] = { +const qstr mp_unary_op_method_name[] = { [MP_UNARY_OP_BOOL] = MP_QSTR___bool__, [MP_UNARY_OP_LEN] = MP_QSTR___len__, //[MP_UNARY_OP_POSITIVE, @@ -334,7 +334,7 @@ STATIC const qstr unary_op_method_name[] = { STATIC mp_obj_t instance_unary_op(mp_uint_t op, mp_obj_t self_in) { mp_obj_instance_t *self = self_in; - qstr op_name = unary_op_method_name[op]; + qstr op_name = mp_unary_op_method_name[op]; /* Still try to lookup native slot if (op_name == 0) { return MP_OBJ_NULL; diff --git a/py/runtime.c b/py/runtime.c index 3597f5654..fc8d128e7 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -242,10 +242,9 @@ mp_obj_t mp_unary_op(mp_uint_t op, mp_obj_t arg) { nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "unsupported type for operator")); } else { - // TODO specify in error message what the operator is nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, - "bad operand type for unary operator: '%s'", - mp_obj_get_type_str(arg))); + "unsupported type for %s: '%s'", + qstr_str(mp_unary_op_method_name[op]), mp_obj_get_type_str(arg))); } } } @@ -537,10 +536,9 @@ unsupported_op: nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "unsupported type for operator")); } else { - // TODO specify in error message what the operator is 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))); + "unsupported types for %s: '%s', '%s'", + qstr_str(mp_binary_op_method_name[op]), mp_obj_get_type_str(lhs), mp_obj_get_type_str(rhs))); } zero_division: diff --git a/py/runtime.h b/py/runtime.h index 1216462b2..a4386b4bb 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -56,6 +56,10 @@ typedef struct _mp_arg_t { mp_arg_val_t defval; } mp_arg_t; +// defined in objtype.c +extern const qstr mp_unary_op_method_name[]; +extern const qstr mp_binary_op_method_name[]; + void mp_init(void); void mp_deinit(void); diff --git a/py/showbc.c b/py/showbc.c index abff93aec..1bdb96aaa 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -30,8 +30,6 @@ #include "py/bc0.h" #include "py/bc.h" -extern const qstr mp_binary_op_method_name[]; - #if MICROPY_DEBUG_PRINTERS #define DECODE_UINT { \