diff options
| author | Damien George <damien@micropython.org> | 2024-02-16 16:52:38 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-02-20 10:56:24 +1100 |
| commit | 9400229766624e80db6a6f95af287a5542dc1b43 (patch) | |
| tree | 58d10d8a89679faa09f19da993712127017b1870 /py/objfun.c | |
| parent | 648a7578da21cc7ddb4046fc59891144e797b983 (diff) | |
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>
Diffstat (limited to 'py/objfun.c')
| -rw-r--r-- | py/objfun.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/py/objfun.c b/py/objfun.c index ba0ba3706..1bdbb3916 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -428,6 +428,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 */ #if MICROPY_EMIT_INLINE_ASM |
