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

@@ -199,13 +199,15 @@ mp_obj_t mp_make_function_from_proto_fun(mp_proto_fun_t proto_fun, const mp_modu
switch (rc->kind) {
#if MICROPY_EMIT_NATIVE
case MP_CODE_NATIVE_PY:
case MP_CODE_NATIVE_VIPER:
fun = mp_obj_new_fun_native(def_args, rc->fun_data, context, rc->children);
// Check for a generator function, and if so change the type of the object
if (rc->is_generator) {
((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_native_gen_wrap;
}
break;
case MP_CODE_NATIVE_VIPER:
fun = mp_obj_new_fun_viper(rc->fun_data, context, rc->children);
break;
#endif
#if MICROPY_EMIT_INLINE_ASM
case MP_CODE_NATIVE_ASM: