py/objfun: Support __name__ on native functions and generators.
This is now easy to support, since the first machine-word of a native function tells how to find the prelude, from which the function name can be extracted in the same way as for bytecode. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -139,14 +139,14 @@ STATIC qstr mp_obj_code_get_name(const mp_obj_fun_bc_t *fun, const byte *code_in
|
||||
|
||||
qstr mp_obj_fun_get_name(mp_const_obj_t fun_in) {
|
||||
const mp_obj_fun_bc_t *fun = MP_OBJ_TO_PTR(fun_in);
|
||||
const byte *bc = fun->bytecode;
|
||||
|
||||
#if MICROPY_EMIT_NATIVE
|
||||
if (fun->base.type == &mp_type_fun_native || fun->base.type == &mp_type_native_gen_wrap) {
|
||||
// TODO native functions don't have name stored
|
||||
return MP_QSTR_;
|
||||
bc = mp_obj_fun_native_get_prelude_ptr(fun);
|
||||
}
|
||||
#endif
|
||||
|
||||
const byte *bc = fun->bytecode;
|
||||
MP_BC_PRELUDE_SIG_DECODE(bc);
|
||||
return mp_obj_code_get_name(fun, bc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user