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:
parent
a919ce26d3
commit
482292cc66
@ -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
|
||||
|
||||
|
||||
@ -344,6 +344,7 @@ const mp_fun_table_t mp_fun_table = {
|
||||
&mp_type_fun_builtin_2,
|
||||
&mp_type_fun_builtin_3,
|
||||
&mp_type_fun_builtin_var,
|
||||
&mp_type_Exception,
|
||||
&mp_stream_read_obj,
|
||||
&mp_stream_readinto_obj,
|
||||
&mp_stream_unbuffered_readline_obj,
|
||||
|
||||
@ -171,6 +171,7 @@ typedef struct _mp_fun_table_t {
|
||||
const mp_obj_type_t *type_fun_builtin_2;
|
||||
const mp_obj_type_t *type_fun_builtin_3;
|
||||
const mp_obj_type_t *type_fun_builtin_var;
|
||||
const mp_obj_type_t *type_Exception;
|
||||
const mp_obj_fun_builtin_var_t *stream_read_obj;
|
||||
const mp_obj_fun_builtin_var_t *stream_readinto_obj;
|
||||
const mp_obj_fun_builtin_var_t *stream_unbuffered_readline_obj;
|
||||
|
||||
@ -767,6 +767,7 @@ def link_objects(env, native_qstr_vals_len):
|
||||
"mp_type_fun_builtin_2",
|
||||
"mp_type_fun_builtin_3",
|
||||
"mp_type_fun_builtin_var",
|
||||
"mp_type_Exception",
|
||||
"mp_stream_read_obj",
|
||||
"mp_stream_readinto_obj",
|
||||
"mp_stream_unbuffered_readline_obj",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user