py/objfun: Split viper fun type out to separate mp_type_fun_viper type.

Viper functions are quite different to native functions and benefit from
being a separate type.  For example, viper functions don't have a bytecode-
style prelude, and don't support generators or default arguments.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2024-02-16 16:52:38 +11:00
parent 648a7578da
commit 9400229766
4 changed files with 35 additions and 1 deletions

View File

@@ -427,6 +427,27 @@ MP_DEFINE_CONST_OBJ_TYPE(
#endif // MICROPY_EMIT_NATIVE
/******************************************************************************/
/* viper functions */
#if MICROPY_EMIT_NATIVE
STATIC mp_obj_t fun_viper_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
MP_STACK_CHECK();
mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in);
mp_call_fun_t fun = MICROPY_MAKE_POINTER_CALLABLE((void *)self->bytecode);
return fun(self_in, n_args, n_kw, args);
}
MP_DEFINE_CONST_OBJ_TYPE(
mp_type_fun_viper,
MP_QSTR_function,
MP_TYPE_FLAG_BINDS_SELF,
call, fun_viper_call
);
#endif // MICROPY_EMIT_NATIVE
/******************************************************************************/
/* inline assembler functions */