diff options
Diffstat (limited to 'py/objfun.h')
-rw-r--r-- | py/objfun.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/py/objfun.h b/py/objfun.h index ddb148dd1..af7c33485 100644 --- a/py/objfun.h +++ b/py/objfun.h @@ -69,6 +69,34 @@ static inline mp_obj_t mp_obj_new_fun_viper(const void *fun_data, const mp_modul return MP_OBJ_FROM_PTR(o); } +static inline const uint8_t *mp_obj_fun_native_get_prelude_ptr(const mp_obj_fun_bc_t *fun_native) { + // Obtain a pointer to the start of the function prelude, based on prelude_ptr_index. + uintptr_t prelude_ptr_index = ((uintptr_t *)fun_native->bytecode)[0]; + const uint8_t *prelude_ptr; + if (prelude_ptr_index == 0) { + prelude_ptr = (const uint8_t *)fun_native->child_table; + } else { + prelude_ptr = (const uint8_t *)fun_native->child_table[prelude_ptr_index]; + } + return prelude_ptr; +} + +static inline void *mp_obj_fun_native_get_function_start(const mp_obj_fun_bc_t *fun_native) { + // Obtain a pointer to the start of the function executable machine code. + return MICROPY_MAKE_POINTER_CALLABLE((void *)(fun_native->bytecode + sizeof(uintptr_t))); +} + +static inline void *mp_obj_fun_native_get_generator_start(const mp_obj_fun_bc_t *fun_native) { + // Obtain a pointer to the start of the generator executable machine code. + uintptr_t start_offset = ((uintptr_t *)fun_native->bytecode)[1]; + return MICROPY_MAKE_POINTER_CALLABLE((void *)(fun_native->bytecode + start_offset)); +} + +static inline void *mp_obj_fun_native_get_generator_resume(const mp_obj_fun_bc_t *fun_native) { + // Obtain a pointer to the resume location of the generator executable machine code. + return MICROPY_MAKE_POINTER_CALLABLE((void *)&((uintptr_t *)fun_native->bytecode)[2]); +} + #endif #if MICROPY_EMIT_INLINE_ASM |