diff --git a/py/obj.h b/py/obj.h index bd0df3fd68..f686fa44ca 100644 --- a/py/obj.h +++ b/py/obj.h @@ -833,6 +833,8 @@ extern const mp_obj_type_t mp_type_fun_builtin_2; extern const mp_obj_type_t mp_type_fun_builtin_3; extern const mp_obj_type_t mp_type_fun_builtin_var; extern const mp_obj_type_t mp_type_fun_bc; +extern const mp_obj_type_t mp_type_fun_native; +extern const mp_obj_type_t mp_type_fun_asm; extern const mp_obj_type_t mp_type_module; extern const mp_obj_type_t mp_type_staticmethod; extern const mp_obj_type_t mp_type_classmethod; diff --git a/py/objfun.c b/py/objfun.c index 930d0ccdf4..ba0ba37068 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -137,10 +137,6 @@ STATIC qstr mp_obj_code_get_name(const mp_obj_fun_bc_t *fun, const byte *code_in return name; } -#if MICROPY_EMIT_NATIVE -STATIC const mp_obj_type_t mp_type_fun_native; -#endif - qstr mp_obj_fun_get_name(mp_const_obj_t fun_in) { const mp_obj_fun_bc_t *fun = MP_OBJ_TO_PTR(fun_in); #if MICROPY_EMIT_NATIVE @@ -420,7 +416,7 @@ STATIC mp_obj_t fun_native_call(mp_obj_t self_in, size_t n_args, size_t n_kw, co #define FUN_BC_TYPE_ATTR #endif -STATIC MP_DEFINE_CONST_OBJ_TYPE( +MP_DEFINE_CONST_OBJ_TYPE( mp_type_fun_native, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF, @@ -429,12 +425,6 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( call, fun_native_call ); -mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) { - mp_obj_fun_bc_t *o = MP_OBJ_TO_PTR(mp_obj_new_fun_bc(def_args, (const byte *)fun_data, mc, child_table)); - o->base.type = &mp_type_fun_native; - return MP_OBJ_FROM_PTR(o); -} - #endif // MICROPY_EMIT_NATIVE /******************************************************************************/ @@ -442,13 +432,6 @@ mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, c #if MICROPY_EMIT_INLINE_ASM -typedef struct _mp_obj_fun_asm_t { - mp_obj_base_t base; - size_t n_args; - const void *fun_data; // GC must be able to trace this pointer - mp_uint_t type_sig; -} mp_obj_fun_asm_t; - typedef mp_uint_t (*inline_asm_fun_0_t)(void); typedef mp_uint_t (*inline_asm_fun_1_t)(mp_uint_t); typedef mp_uint_t (*inline_asm_fun_2_t)(mp_uint_t, mp_uint_t); @@ -529,19 +512,11 @@ STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const return mp_native_to_obj(ret, self->type_sig); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +MP_DEFINE_CONST_OBJ_TYPE( mp_type_fun_asm, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF, call, fun_asm_call ); -mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig) { - mp_obj_fun_asm_t *o = mp_obj_malloc(mp_obj_fun_asm_t, &mp_type_fun_asm); - o->n_args = n_args; - o->fun_data = fun_data; - o->type_sig = type_sig; - return MP_OBJ_FROM_PTR(o); -} - #endif // MICROPY_EMIT_INLINE_ASM diff --git a/py/objfun.h b/py/objfun.h index 9de15b8841..b6350d7b67 100644 --- a/py/objfun.h +++ b/py/objfun.h @@ -43,9 +43,32 @@ typedef struct _mp_obj_fun_bc_t { mp_obj_t extra_args[]; } mp_obj_fun_bc_t; +typedef struct _mp_obj_fun_asm_t { + mp_obj_base_t base; + size_t n_args; + const void *fun_data; // GC must be able to trace this pointer + mp_uint_t type_sig; +} mp_obj_fun_asm_t; + mp_obj_t mp_obj_new_fun_bc(const mp_obj_t *def_args, const byte *code, const mp_module_context_t *cm, struct _mp_raw_code_t *const *raw_code_table); -mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *cm, struct _mp_raw_code_t *const *raw_code_table); -mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig); void mp_obj_fun_bc_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest); +#if MICROPY_EMIT_NATIVE +static inline mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) { + mp_obj_fun_bc_t *o = MP_OBJ_TO_PTR(mp_obj_new_fun_bc(def_args, (const byte *)fun_data, mc, child_table)); + o->base.type = &mp_type_fun_native; + return MP_OBJ_FROM_PTR(o); +} +#endif + +#if MICROPY_EMIT_INLINE_ASM +static inline mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig) { + mp_obj_fun_asm_t *o = mp_obj_malloc(mp_obj_fun_asm_t, &mp_type_fun_asm); + o->n_args = n_args; + o->fun_data = fun_data; + o->type_sig = type_sig; + return MP_OBJ_FROM_PTR(o); +} +#endif + #endif // MICROPY_INCLUDED_PY_OBJFUN_H