py: Add tentative scheme for error messages configuration.
This commit is contained in:
parent
68551a8428
commit
1f85d6255d
|
@ -94,6 +94,17 @@ typedef long long mp_longint_impl_t;
|
||||||
#define MICROPY_ENABLE_DOC_STRING (0)
|
#define MICROPY_ENABLE_DOC_STRING (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Exception messages are short static strings (TODO)
|
||||||
|
#define MICROPY_ERROR_REPORTING_TERSE (1)
|
||||||
|
// Exception messages provide basic error details
|
||||||
|
#define MICROPY_ERROR_REPORTING_NORMAL (2)
|
||||||
|
// Exception messages provide full info, e.g. object names
|
||||||
|
#define MICROPY_ERROR_REPORTING_DETAILED (3)
|
||||||
|
|
||||||
|
#ifndef MICROPY_ERROR_REPORTING
|
||||||
|
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
|
||||||
|
#endif
|
||||||
|
|
||||||
// Float and complex implementation
|
// Float and complex implementation
|
||||||
#define MICROPY_FLOAT_IMPL_NONE (0)
|
#define MICROPY_FLOAT_IMPL_NONE (0)
|
||||||
#define MICROPY_FLOAT_IMPL_FLOAT (1)
|
#define MICROPY_FLOAT_IMPL_FLOAT (1)
|
||||||
|
|
10
py/objfun.c
10
py/objfun.c
|
@ -152,8 +152,18 @@ STATIC void dump_args(const mp_obj_t *a, int sz) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, uint expected, uint given) {
|
STATIC NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, uint expected, uint given) {
|
||||||
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||||
|
// Generic message, to be reused for other argument issues
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
||||||
|
"argument num/types mismatch"));
|
||||||
|
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"function takes %d positional arguments but %d were given", expected, given));
|
"function takes %d positional arguments but %d were given", expected, given));
|
||||||
|
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
||||||
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
|
"%s() takes %d positional arguments but %d were given",
|
||||||
|
mp_obj_fun_get_name(f), expected, given));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's possible to call a function without allocating new argument array,
|
// If it's possible to call a function without allocating new argument array,
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
#define MICROPY_USE_COMPUTED_GOTO (1)
|
#define MICROPY_USE_COMPUTED_GOTO (1)
|
||||||
#define MICROPY_MOD_SYS_STDFILES (1)
|
#define MICROPY_MOD_SYS_STDFILES (1)
|
||||||
#define MICROPY_ENABLE_MOD_CMATH (1)
|
#define MICROPY_ENABLE_MOD_CMATH (1)
|
||||||
|
// Define to MICROPY_ERROR_REPORTING_DETAILED to get function, etc.
|
||||||
|
// names in exception messages (may require more RAM).
|
||||||
|
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
|
||||||
|
|
||||||
extern const struct _mp_obj_module_t mp_module_time;
|
extern const struct _mp_obj_module_t mp_module_time;
|
||||||
extern const struct _mp_obj_module_t mp_module_socket;
|
extern const struct _mp_obj_module_t mp_module_socket;
|
||||||
|
|
Loading…
Reference in New Issue