Commit 68551a84 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

objfun: Add function name accessor and .print slot method.

parent dddf5bd3
......@@ -126,6 +126,19 @@ mp_obj_t mp_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var
/******************************************************************************/
/* byte code functions */
const char *mp_obj_fun_get_name(mp_obj_fun_bc_t *o) {
const byte *code_info = o->bytecode;
qstr block_name = code_info[8] | (code_info[9] << 8) | (code_info[10] << 16) | (code_info[11] << 24);
return qstr_str(block_name);
}
#if MICROPY_CPYTHON_COMPAT
STATIC void fun_bc_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
mp_obj_fun_bc_t *o = o_in;
print(env, "<function %s at 0x%x>", mp_obj_fun_get_name(o), o);
}
#endif
#if DEBUG_PRINT
STATIC void dump_args(const mp_obj_t *a, int sz) {
DEBUG_printf("%p: ", a);
......@@ -335,6 +348,9 @@ continue2:;
const mp_obj_type_t mp_type_fun_bc = {
{ &mp_type_type },
.name = MP_QSTR_function,
#if MICROPY_CPYTHON_COMPAT
.print = fun_bc_print,
#endif
.call = fun_bc_call,
.binary_op = fun_binary_op,
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment