summaryrefslogtreecommitdiff
path: root/py/objfun.h
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-02-16 16:52:38 +1100
committerDamien George <damien@micropython.org>2024-02-20 10:56:24 +1100
commit9400229766624e80db6a6f95af287a5542dc1b43 (patch)
tree58d10d8a89679faa09f19da993712127017b1870 /py/objfun.h
parent648a7578da21cc7ddb4046fc59891144e797b983 (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.h')
-rw-r--r--py/objfun.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/py/objfun.h b/py/objfun.h
index b6350d7b6..ddb148dd1 100644
--- a/py/objfun.h
+++ b/py/objfun.h
@@ -54,11 +54,21 @@ mp_obj_t mp_obj_new_fun_bc(const mp_obj_t *def_args, const byte *code, const mp_
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);
}
+
+static inline mp_obj_t mp_obj_new_fun_viper(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_malloc(mp_obj_fun_bc_t, &mp_type_fun_viper);
+ o->bytecode = fun_data;
+ o->context = mc;
+ o->child_table = child_table;
+ return MP_OBJ_FROM_PTR(o);
+}
+
#endif
#if MICROPY_EMIT_INLINE_ASM