diff options
author | Damien George <damien.p.george@gmail.com> | 2014-11-06 17:36:16 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-11-06 17:36:16 +0000 |
commit | 1e9a92f84fb58db610e20b766052292edc28d25b (patch) | |
tree | 0005072b03a413c4b01df72f61066e0aaeca23f3 /py/builtin.c | |
parent | b6b34cd3f6585eed455473bc149e9db758a45d9c (diff) | |
download | micropython-1e9a92f84fb58db610e20b766052292edc28d25b.tar.gz micropython-1e9a92f84fb58db610e20b766052292edc28d25b.zip |
py: Use shorter, static error msgs when ERROR_REPORTING_TERSE enabled.
Going from MICROPY_ERROR_REPORTING_NORMAL to
MICROPY_ERROR_REPORTING_TERSE now saves 2020 bytes ROM for ARM Thumb2,
and 2200 bytes ROM for 32-bit x86.
This is about a 2.5% code size reduction for bare-arm.
Diffstat (limited to 'py/builtin.c')
-rw-r--r-- | py/builtin.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/py/builtin.c b/py/builtin.c index 77b58575ae..b337af3c59 100644 --- a/py/builtin.c +++ b/py/builtin.c @@ -272,7 +272,14 @@ STATIC mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) { return mp_obj_new_tuple(2, tuple); #endif } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "unsupported operand type(s) for divmod(): '%s' and '%s'", mp_obj_get_type_str(o1_in), mp_obj_get_type_str(o2_in))); + if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { + nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, + "unsupported operand type(s) for divmod()")); + } else { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, + "unsupported operand type(s) for divmod(): '%s' and '%s'", + mp_obj_get_type_str(o1_in), mp_obj_get_type_str(o2_in))); + } } } MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_divmod_obj, mp_builtin_divmod); @@ -357,8 +364,8 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) { mp_uint_t len; const char *str = mp_obj_str_get_data(o_in, &len); #if MICROPY_PY_BUILTINS_STR_UNICODE - mp_uint_t charlen = unichar_charlen(str, len); - if (charlen == 1) { + len = unichar_charlen(str, len); + if (len == 1) { if (MP_OBJ_IS_STR(o_in) && UTF8_IS_NONASCII(*str)) { mp_int_t ord = *str++ & 0x7F; for (mp_int_t mask = 0x40; ord & mask; mask >>= 1) { @@ -371,17 +378,21 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) { } else { return mp_obj_new_int(((const byte*)str)[0]); } - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "ord() expected a character, but string of length %d found", charlen)); } #else if (len == 1) { // don't sign extend when converting to ord return mp_obj_new_int(((const byte*)str)[0]); - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "ord() expected a character, but string of length %d found", len)); } #endif + + if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, + "ord expects a character")); + } else { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, + "ord() expected a character, but string of length %d found", len)); + } } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord); |