Commit 94c41bb0 authored by Damien George's avatar Damien George
Browse files

py: Use mp_raise_TypeError/mp_raise_ValueError helpers where possible.

Saves 168 bytes on bare-arm.
parent 7b1804c5
...@@ -37,7 +37,7 @@ void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_ar ...@@ -37,7 +37,7 @@ void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_ar
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_arg_error_terse_mismatch(); mp_arg_error_terse_mismatch();
} else { } else {
mp_raise_msg(&mp_type_TypeError, "function does not take keyword arguments"); mp_raise_TypeError("function does not take keyword arguments");
} }
} }
...@@ -115,7 +115,7 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n ...@@ -115,7 +115,7 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
mp_arg_error_terse_mismatch(); mp_arg_error_terse_mismatch();
} else { } else {
// TODO better error message // TODO better error message
mp_raise_msg(&mp_type_TypeError, "extra positional arguments given"); mp_raise_TypeError("extra positional arguments given");
} }
} }
if (kws_found < kws->used) { if (kws_found < kws->used) {
...@@ -123,7 +123,7 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n ...@@ -123,7 +123,7 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
mp_arg_error_terse_mismatch(); mp_arg_error_terse_mismatch();
} else { } else {
// TODO better error message // TODO better error message
mp_raise_msg(&mp_type_TypeError, "extra keyword arguments given"); mp_raise_TypeError("extra keyword arguments given");
} }
} }
} }
...@@ -136,7 +136,7 @@ void mp_arg_parse_all_kw_array(size_t n_pos, size_t n_kw, const mp_obj_t *args, ...@@ -136,7 +136,7 @@ void mp_arg_parse_all_kw_array(size_t n_pos, size_t n_kw, const mp_obj_t *args,
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE || _MSC_VER #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE || _MSC_VER
NORETURN void mp_arg_error_terse_mismatch(void) { NORETURN void mp_arg_error_terse_mismatch(void) {
mp_raise_msg(&mp_type_TypeError, "argument num/types mismatch"); mp_raise_TypeError("argument num/types mismatch");
} }
#endif #endif
......
...@@ -197,7 +197,7 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw ...@@ -197,7 +197,7 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw
// Didn't find name match with positional args // Didn't find name match with positional args
if ((scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) == 0) { if ((scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) == 0) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "unexpected keyword argument"); mp_raise_TypeError("unexpected keyword argument");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"unexpected keyword argument '%q'", MP_OBJ_QSTR_VALUE(wanted_arg_name))); "unexpected keyword argument '%q'", MP_OBJ_QSTR_VALUE(wanted_arg_name)));
...@@ -250,7 +250,7 @@ continue2:; ...@@ -250,7 +250,7 @@ continue2:;
} else { } else {
// no keyword arguments given // no keyword arguments given
if (n_kwonly_args != 0) { if (n_kwonly_args != 0) {
mp_raise_msg(&mp_type_TypeError, "function missing keyword-only argument"); mp_raise_TypeError("function missing keyword-only argument");
} }
if ((scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) != 0) { if ((scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) != 0) {
*var_pos_kw_args = mp_obj_new_dict(0); *var_pos_kw_args = mp_obj_new_dict(0);
......
...@@ -95,7 +95,7 @@ STATIC mp_obj_t mp_builtin_compile(size_t n_args, const mp_obj_t *args) { ...@@ -95,7 +95,7 @@ STATIC mp_obj_t mp_builtin_compile(size_t n_args, const mp_obj_t *args) {
case MP_QSTR_exec: parse_input_kind = MP_PARSE_FILE_INPUT; break; case MP_QSTR_exec: parse_input_kind = MP_PARSE_FILE_INPUT; break;
case MP_QSTR_eval: parse_input_kind = MP_PARSE_EVAL_INPUT; break; case MP_QSTR_eval: parse_input_kind = MP_PARSE_EVAL_INPUT; break;
default: default:
mp_raise_msg(&mp_type_ValueError, "bad compile mode"); mp_raise_ValueError("bad compile mode");
} }
mp_obj_code_t *code = m_new_obj(mp_obj_code_t); mp_obj_code_t *code = m_new_obj(mp_obj_code_t);
......
...@@ -341,7 +341,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) { ...@@ -341,7 +341,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
qstr new_mod_q = qstr_from_strn(new_mod, new_mod_l); qstr new_mod_q = qstr_from_strn(new_mod, new_mod_l);
DEBUG_printf("Resolved base name for relative import: '%s'\n", qstr_str(new_mod_q)); DEBUG_printf("Resolved base name for relative import: '%s'\n", qstr_str(new_mod_q));
if (new_mod_q == MP_QSTR_) { if (new_mod_q == MP_QSTR_) {
mp_raise_msg(&mp_type_ValueError, "cannot perform relative import"); mp_raise_ValueError("cannot perform relative import");
} }
module_name = MP_OBJ_NEW_QSTR(new_mod_q); module_name = MP_OBJ_NEW_QSTR(new_mod_q);
mod_str = new_mod; mod_str = new_mod;
......
...@@ -180,7 +180,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) { ...@@ -180,7 +180,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
str[3] = (c & 0x3F) | 0x80; str[3] = (c & 0x3F) | 0x80;
len = 4; len = 4;
} else { } else {
mp_raise_msg(&mp_type_ValueError, "chr() arg not in range(0x110000)"); mp_raise_ValueError("chr() arg not in range(0x110000)");
} }
return mp_obj_new_str(str, len, true); return mp_obj_new_str(str, len, true);
#else #else
...@@ -189,7 +189,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) { ...@@ -189,7 +189,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
char str[1] = {ord}; char str[1] = {ord};
return mp_obj_new_str(str, 1, true); return mp_obj_new_str(str, 1, true);
} else { } else {
mp_raise_msg(&mp_type_ValueError, "chr() arg not in range(256)"); mp_raise_ValueError("chr() arg not in range(256)");
} }
#endif #endif
} }
...@@ -289,7 +289,7 @@ STATIC mp_obj_t mp_builtin_min_max(size_t n_args, const mp_obj_t *args, mp_map_t ...@@ -289,7 +289,7 @@ STATIC mp_obj_t mp_builtin_min_max(size_t n_args, const mp_obj_t *args, mp_map_t
if (default_elem != NULL) { if (default_elem != NULL) {
best_obj = default_elem->value; best_obj = default_elem->value;
} else { } else {
mp_raise_msg(&mp_type_ValueError, "arg is an empty sequence"); mp_raise_ValueError("arg is an empty sequence");
} }
} }
return best_obj; return best_obj;
...@@ -504,7 +504,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_sum_obj, 1, 2, mp_builtin_sum); ...@@ -504,7 +504,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_sum_obj, 1, 2, mp_builtin_sum);
STATIC mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { STATIC mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
if (n_args > 1) { if (n_args > 1) {
mp_raise_msg(&mp_type_TypeError, "must use keyword argument for key function"); mp_raise_TypeError("must use keyword argument for key function");
} }
mp_obj_t self = mp_type_list.make_new(&mp_type_list, 1, 0, args); mp_obj_t self = mp_type_list.make_new(&mp_type_list, 1, 0, args);
mp_obj_list_sort(1, &self, kwargs); mp_obj_list_sort(1, &self, kwargs);
......
...@@ -227,7 +227,7 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args) ...@@ -227,7 +227,7 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args)
} else { } else {
// positional and keyword arguments // positional and keyword arguments
if (mp_obj_get_type(args[2]) != &mp_type_dict) { if (mp_obj_get_type(args[2]) != &mp_type_dict) {
mp_raise_msg(&mp_type_TypeError, "expecting a dict for keyword args"); mp_raise_TypeError("expecting a dict for keyword args");
} }
mp_map_t *map = &((mp_obj_dict_t*)MP_OBJ_TO_PTR(args[2]))->map; mp_map_t *map = &((mp_obj_dict_t*)MP_OBJ_TO_PTR(args[2]))->map;
th_args = m_new_obj_var(thread_entry_args_t, mp_obj_t, pos_args_len + 2 * map->used); th_args = m_new_obj_var(thread_entry_args_t, mp_obj_t, pos_args_len + 2 * map->used);
......
...@@ -229,7 +229,7 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) { ...@@ -229,7 +229,7 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
return mp_obj_int_get_checked(arg); return mp_obj_int_get_checked(arg);
} else { } else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "can't convert to int"); mp_raise_TypeError("can't convert to int");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"can't convert %s to int", mp_obj_get_type_str(arg))); "can't convert %s to int", mp_obj_get_type_str(arg)));
...@@ -279,7 +279,7 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) { ...@@ -279,7 +279,7 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
return mp_obj_float_get(arg); return mp_obj_float_get(arg);
} else { } else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "can't convert to float"); mp_raise_TypeError("can't convert to float");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"can't convert %s to float", mp_obj_get_type_str(arg))); "can't convert %s to float", mp_obj_get_type_str(arg)));
...@@ -310,7 +310,7 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) { ...@@ -310,7 +310,7 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
mp_obj_complex_get(arg, real, imag); mp_obj_complex_get(arg, real, imag);
} else { } else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "can't convert to complex"); mp_raise_TypeError("can't convert to complex");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"can't convert %s to complex", mp_obj_get_type_str(arg))); "can't convert %s to complex", mp_obj_get_type_str(arg)));
...@@ -328,7 +328,7 @@ void mp_obj_get_array(mp_obj_t o, mp_uint_t *len, mp_obj_t **items) { ...@@ -328,7 +328,7 @@ void mp_obj_get_array(mp_obj_t o, mp_uint_t *len, mp_obj_t **items) {
mp_obj_list_get(o, len, items); mp_obj_list_get(o, len, items);
} else { } else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "expected tuple/list"); mp_raise_TypeError("expected tuple/list");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"object '%s' is not a tuple or list", mp_obj_get_type_str(o))); "object '%s' is not a tuple or list", mp_obj_get_type_str(o)));
...@@ -342,7 +342,7 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items) { ...@@ -342,7 +342,7 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items) {
mp_obj_get_array(o, &seq_len, items); mp_obj_get_array(o, &seq_len, items);
if (seq_len != len) { if (seq_len != len) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_ValueError, "tuple/list has wrong length"); mp_raise_ValueError("tuple/list has wrong length");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"requested length %d but object has length %d", (int)len, (int)seq_len)); "requested length %d but object has length %d", (int)len, (int)seq_len));
...@@ -357,7 +357,7 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool ...@@ -357,7 +357,7 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool
i = MP_OBJ_SMALL_INT_VALUE(index); i = MP_OBJ_SMALL_INT_VALUE(index);
} else if (!mp_obj_get_int_maybe(index, &i)) { } else if (!mp_obj_get_int_maybe(index, &i)) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "indices must be integers"); mp_raise_TypeError("indices must be integers");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"%q indices must be integers, not %s", "%q indices must be integers, not %s",
...@@ -412,7 +412,7 @@ mp_obj_t mp_obj_len(mp_obj_t o_in) { ...@@ -412,7 +412,7 @@ mp_obj_t mp_obj_len(mp_obj_t o_in) {
mp_obj_t len = mp_obj_len_maybe(o_in); mp_obj_t len = mp_obj_len_maybe(o_in);
if (len == MP_OBJ_NULL) { if (len == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "object has no len"); mp_raise_TypeError("object has no len");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"object of type '%s' has no len()", mp_obj_get_type_str(o_in))); "object of type '%s' has no len()", mp_obj_get_type_str(o_in)));
...@@ -453,7 +453,7 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) { ...@@ -453,7 +453,7 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
} }
if (value == MP_OBJ_NULL) { if (value == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "object does not support item deletion"); mp_raise_TypeError("object does not support item deletion");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object does not support item deletion", mp_obj_get_type_str(base))); "'%s' object does not support item deletion", mp_obj_get_type_str(base)));
...@@ -468,7 +468,7 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) { ...@@ -468,7 +468,7 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
} }
} else { } else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "object does not support item assignment"); mp_raise_TypeError("object does not support item assignment");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object does not support item assignment", mp_obj_get_type_str(base))); "'%s' object does not support item assignment", mp_obj_get_type_str(base)));
...@@ -502,7 +502,7 @@ bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) { ...@@ -502,7 +502,7 @@ bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) { void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
if (!mp_get_buffer(obj, bufinfo, flags)) { if (!mp_get_buffer(obj, bufinfo, flags)) {
mp_raise_msg(&mp_type_TypeError, "object with buffer protocol required"); mp_raise_TypeError("object with buffer protocol required");
} }
} }
......
...@@ -391,7 +391,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value ...@@ -391,7 +391,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
mp_obj_array_t *src_slice = MP_OBJ_TO_PTR(value); mp_obj_array_t *src_slice = MP_OBJ_TO_PTR(value);
if (item_sz != mp_binary_get_size('@', src_slice->typecode & TYPECODE_MASK, NULL)) { if (item_sz != mp_binary_get_size('@', src_slice->typecode & TYPECODE_MASK, NULL)) {
compat_error: compat_error:
mp_raise_msg(&mp_type_ValueError, "lhs and rhs should be compatible"); mp_raise_ValueError("lhs and rhs should be compatible");
} }
src_len = src_slice->len; src_len = src_slice->len;
src_items = src_slice->items; src_items = src_slice->items;
......
...@@ -386,7 +386,7 @@ STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwarg ...@@ -386,7 +386,7 @@ STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwarg
if (key == MP_OBJ_STOP_ITERATION if (key == MP_OBJ_STOP_ITERATION
|| value == MP_OBJ_STOP_ITERATION || value == MP_OBJ_STOP_ITERATION
|| stop != MP_OBJ_STOP_ITERATION) { || stop != MP_OBJ_STOP_ITERATION) {
mp_raise_msg(&mp_type_ValueError, "dictionary update sequence has the wrong length"); mp_raise_ValueError("dictionary update sequence has the wrong length");
} else { } else {
mp_map_lookup(&self->map, key, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value; mp_map_lookup(&self->map, key, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value;
} }
......
...@@ -105,7 +105,7 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_ ...@@ -105,7 +105,7 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_
} }
if (self->code_state.sp == self->code_state.state - 1) { if (self->code_state.sp == self->code_state.state - 1) {
if (send_value != mp_const_none) { if (send_value != mp_const_none) {
mp_raise_msg(&mp_type_TypeError, "can't send non-None value to a just-started generator"); mp_raise_TypeError("can't send non-None value to a just-started generator");
} }
} else { } else {
*self->code_state.sp = send_value; *self->code_state.sp = send_value;
......
...@@ -277,7 +277,7 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { ...@@ -277,7 +277,7 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
case MP_BINARY_OP_INPLACE_RSHIFT: { case MP_BINARY_OP_INPLACE_RSHIFT: {
mp_int_t irhs = mp_obj_int_get_checked(rhs_in); mp_int_t irhs = mp_obj_int_get_checked(rhs_in);
if (irhs < 0) { if (irhs < 0) {
mp_raise_msg(&mp_type_ValueError, "negative shift count"); mp_raise_ValueError("negative shift count");
} }
if (op == MP_BINARY_OP_LSHIFT || op == MP_BINARY_OP_INPLACE_LSHIFT) { if (op == MP_BINARY_OP_LSHIFT || op == MP_BINARY_OP_INPLACE_LSHIFT) {
mpz_shl_inpl(&res->mpz, zlhs, irhs); mpz_shl_inpl(&res->mpz, zlhs, irhs);
......
...@@ -50,7 +50,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___init___obj, object___init__); ...@@ -50,7 +50,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___init___obj, object___init__);
STATIC mp_obj_t object___new__(mp_obj_t cls) { STATIC mp_obj_t object___new__(mp_obj_t cls) {
if (!MP_OBJ_IS_TYPE(cls, &mp_type_type) || !mp_obj_is_instance_type((mp_obj_type_t*)MP_OBJ_TO_PTR(cls))) { if (!MP_OBJ_IS_TYPE(cls, &mp_type_type) || !mp_obj_is_instance_type((mp_obj_type_t*)MP_OBJ_TO_PTR(cls))) {
mp_raise_msg(&mp_type_TypeError, "__new__ arg must be a user-type"); mp_raise_TypeError("__new__ arg must be a user-type");
} }
mp_obj_t o = MP_OBJ_SENTINEL; mp_obj_t o = MP_OBJ_SENTINEL;
mp_obj_t res = mp_obj_instance_make_new(MP_OBJ_TO_PTR(cls), 1, 0, &o); mp_obj_t res = mp_obj_instance_make_new(MP_OBJ_TO_PTR(cls), 1, 0, &o);
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#if MICROPY_CPYTHON_COMPAT #if MICROPY_CPYTHON_COMPAT
STATIC void check_stringio_is_open(const mp_obj_stringio_t *o) { STATIC void check_stringio_is_open(const mp_obj_stringio_t *o) {
if (o->vstr == NULL) { if (o->vstr == NULL) {
mp_raise_msg(&mp_type_ValueError, "I/O operation on closed file"); mp_raise_ValueError("I/O operation on closed file");
} }
} }
#else #else
......
...@@ -311,7 +311,7 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size ...@@ -311,7 +311,7 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size
} }
if (init_ret != mp_const_none) { if (init_ret != mp_const_none) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "__init__() should return None"); mp_raise_TypeError("__init__() should return None");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret))); "__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret)));
...@@ -744,7 +744,7 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons ...@@ -744,7 +744,7 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons
mp_obj_t call = mp_obj_instance_get_call(self_in, member); mp_obj_t call = mp_obj_instance_get_call(self_in, member);
if (call == MP_OBJ_NULL) { if (call == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "object not callable"); mp_raise_TypeError("object not callable");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object is not callable", mp_obj_get_type_str(self_in))); "'%s' object is not callable", mp_obj_get_type_str(self_in)));
...@@ -826,7 +826,7 @@ STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_ ...@@ -826,7 +826,7 @@ STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_
return mp_obj_new_type(mp_obj_str_get_qstr(args[0]), args[1], args[2]); return mp_obj_new_type(mp_obj_str_get_qstr(args[0]), args[1], args[2]);
default: default:
mp_raise_msg(&mp_type_TypeError, "type takes 1 or 3 arguments"); mp_raise_TypeError("type takes 1 or 3 arguments");
} }
} }
...@@ -837,7 +837,7 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp ...@@ -837,7 +837,7 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp
if (self->make_new == NULL) { if (self->make_new == NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "cannot create instance"); mp_raise_TypeError("cannot create instance");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"cannot create '%q' instances", self->name)); "cannot create '%q' instances", self->name));
...@@ -925,7 +925,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) ...@@ -925,7 +925,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
// TODO: Verify with CPy, tested on function type // TODO: Verify with CPy, tested on function type
if (t->make_new == NULL) { if (t->make_new == NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "type is not an acceptable base type"); mp_raise_TypeError("type is not an acceptable base type");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"type '%q' is not an acceptable base type", t->name)); "type '%q' is not an acceptable base type", t->name));
...@@ -959,7 +959,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) ...@@ -959,7 +959,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
const mp_obj_type_t *native_base; const mp_obj_type_t *native_base;
size_t num_native_bases = instance_count_native_bases(o, &native_base); size_t num_native_bases = instance_count_native_bases(o, &native_base);
if (num_native_bases > 1) { if (num_native_bases > 1) {
mp_raise_msg(&mp_type_TypeError, "multiple bases have instance lay-out conflict"); mp_raise_TypeError("multiple bases have instance lay-out conflict");
} }
mp_map_t *locals_map = &o->locals_dict->map; mp_map_t *locals_map = &o->locals_dict->map;
...@@ -1106,7 +1106,7 @@ STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) { ...@@ -1106,7 +1106,7 @@ STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) {
} else if (MP_OBJ_IS_TYPE(classinfo, &mp_type_tuple)) { } else if (MP_OBJ_IS_TYPE(classinfo, &mp_type_tuple)) {
mp_obj_tuple_get(classinfo, &len, &items); mp_obj_tuple_get(classinfo, &len, &items);
} else { } else {
mp_raise_msg(&mp_type_TypeError, "issubclass() arg 2 must be a class or a tuple of classes"); mp_raise_TypeError("issubclass() arg 2 must be a class or a tuple of classes");
} }
for (size_t i = 0; i < len; i++) { for (size_t i = 0; i < len; i++) {
...@@ -1120,7 +1120,7 @@ STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) { ...@@ -1120,7 +1120,7 @@ STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) {
STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) { STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) {
if (!MP_OBJ_IS_TYPE(object, &mp_type_type)) { if (!MP_OBJ_IS_TYPE(object, &mp_type_type)) {
mp_raise_msg(&mp_type_TypeError, "issubclass() arg 1 must be a class"); mp_raise_TypeError("issubclass() arg 1 must be a class");
} }
return mp_obj_is_subclass(object, classinfo); return mp_obj_is_subclass(object, classinfo);
} }
......
...@@ -55,7 +55,7 @@ mp_obj_t mp_parse_num_integer(const char *restrict str_, size_t len, int base, m ...@@ -55,7 +55,7 @@ mp_obj_t mp_parse_num_integer(const char *restrict str_, size_t len, int base, m
// check radix base // check radix base
if ((base != 0 && base < 2) || base > 36) { if ((base != 0 && base < 2) || base > 36) {
// this won't be reached if lex!=NULL // this won't be reached if lex!=NULL
mp_raise_msg(&mp_type_ValueError, "int() arg 2 must be >= 2 and <= 36"); mp_raise_ValueError("int() arg 2 must be >= 2 and <= 36");
} }
// skip leading space // skip leading space
......
...@@ -252,7 +252,7 @@ mp_obj_t mp_unary_op(mp_uint_t op, mp_obj_t arg) { ...@@ -252,7 +252,7 @@ mp_obj_t mp_unary_op(mp_uint_t op, mp_obj_t arg) {
} }
} }
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "unsupported type for operator"); mp_raise_TypeError("unsupported type for operator");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"unsupported type for %q: '%s'", "unsupported type for %q: '%s'",
...@@ -344,7 +344,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { ...@@ -344,7 +344,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
case MP_BINARY_OP_INPLACE_LSHIFT: { case MP_BINARY_OP_INPLACE_LSHIFT: {
if (rhs_val < 0) { if (rhs_val < 0) {
// negative shift not allowed // negative shift not allowed
mp_raise_msg(&mp_type_ValueError, "negative shift count"); mp_raise_ValueError("negative shift count");
} else if (rhs_val >= (mp_int_t)BITS_PER_WORD || lhs_val > (MP_SMALL_INT_MAX >> rhs_val) || lhs_val < (MP_SMALL_INT_MIN >> rhs_val)) { } else if (rhs_val >= (mp_int_t)BITS_PER_WORD || lhs_val > (MP_SMALL_INT_MAX >> rhs_val) || lhs_val < (MP_SMALL_INT_MIN >> rhs_val)) {
// left-shift will overflow, so use higher precision integer // left-shift will overflow, so use higher precision integer
lhs = mp_obj_new_int_from_ll(lhs_val); lhs = mp_obj_new_int_from_ll(lhs_val);
...@@ -359,7 +359,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { ...@@ -359,7 +359,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
case MP_BINARY_OP_INPLACE_RSHIFT: case MP_BINARY_OP_INPLACE_RSHIFT:
if (rhs_val < 0) { if (rhs_val < 0) {
// negative shift not allowed // negative shift not allowed
mp_raise_msg(&mp_type_ValueError, "negative shift count"); mp_raise_ValueError("negative shift count");
} else { } else {
// standard precision is enough for right-shift // standard precision is enough for right-shift
if (rhs_val >= (mp_int_t)BITS_PER_WORD) { if (rhs_val >= (mp_int_t)BITS_PER_WORD) {
...@@ -435,7 +435,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { ...@@ -435,7 +435,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
lhs = mp_obj_new_float(lhs_val); lhs = mp_obj_new_float(lhs_val);
goto generic_binary_op; goto generic_binary_op;
#else #else
mp_raise_msg(&mp_type_ValueError, "negative power with no float support"); mp_raise_ValueError("negative power with no float support");
#endif #endif
} else { } else {
mp_int_t ans = 1; mp_int_t ans = 1;
...@@ -537,7 +537,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { ...@@ -537,7 +537,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
} }
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "object not iterable"); mp_raise_TypeError("object not iterable");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"'%s' object is not iterable", mp_obj_get_type_str(rhs))); "'%s' object is not iterable", mp_obj_get_type_str(rhs)));
...@@ -559,7 +559,7 @@ generic_binary_op: ...@@ -559,7 +559,7 @@ generic_binary_op:
unsupported_op: unsupported_op:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_msg(&mp_type_TypeError, "unsupported type for operator"); mp_raise_TypeError("unsupported type for operator");
} else { } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
"unsupported types for %q: '%s', '%s'", "unsupported types for %q: '%s', '%s'",
...@@ -601,7 +601,7 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, size_t n_args, size_t n_kw, cons ...@@ -601,7 +601,7 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, size_t n_args, size_t n_kw, cons
}