mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
py/dynruntime: Add mp_obj_exception_init function to create C exception.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -90,6 +90,7 @@ static inline void *m_realloc_dyn(void *ptr, size_t new_num_bytes) {
|
||||
#define mp_type_bytes (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_bytes)))
|
||||
#define mp_type_tuple (*((mp_obj_base_t *)mp_const_empty_tuple)->type)
|
||||
#define mp_type_list (*mp_fun_table.type_list)
|
||||
#define mp_type_Exception (*mp_fun_table.type_Exception)
|
||||
#define mp_type_EOFError (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_EOFError)))
|
||||
#define mp_type_IndexError (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_IndexError)))
|
||||
#define mp_type_KeyError (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_KeyError)))
|
||||
@@ -236,6 +237,10 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type
|
||||
/******************************************************************************/
|
||||
// Exceptions
|
||||
|
||||
#define mp_obj_exception_make_new (MP_OBJ_TYPE_GET_SLOT(&mp_type_Exception, make_new))
|
||||
#define mp_obj_exception_print (MP_OBJ_TYPE_GET_SLOT(&mp_type_Exception, print))
|
||||
#define mp_obj_exception_attr (MP_OBJ_TYPE_GET_SLOT(&mp_type_Exception, attr))
|
||||
|
||||
#define mp_obj_new_exception(o) ((mp_obj_t)(o)) // Assumes returned object will be raised, will create instance then
|
||||
#define mp_obj_new_exception_arg1(e_type, arg) (mp_obj_new_exception_arg1_dyn((e_type), (arg)))
|
||||
|
||||
@@ -263,6 +268,16 @@ static inline void mp_raise_OSError_dyn(int er) {
|
||||
nlr_raise(mp_call_function_n_kw(mp_load_global(MP_QSTR_OSError), 1, 0, &args[0]));
|
||||
}
|
||||
|
||||
static inline void mp_obj_exception_init(mp_obj_full_type_t *exc, qstr name, const mp_obj_type_t *base) {
|
||||
exc->base.type = &mp_type_type;
|
||||
exc->flags = MP_TYPE_FLAG_NONE;
|
||||
exc->name = name;
|
||||
MP_OBJ_TYPE_SET_SLOT(exc, make_new, mp_obj_exception_make_new, 0);
|
||||
MP_OBJ_TYPE_SET_SLOT(exc, print, mp_obj_exception_print, 1);
|
||||
MP_OBJ_TYPE_SET_SLOT(exc, attr, mp_obj_exception_attr, 2);
|
||||
MP_OBJ_TYPE_SET_SLOT(exc, parent, base, 3);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// Floating point
|
||||
|
||||
|
||||
Reference in New Issue
Block a user