summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/objfun.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/py/objfun.c b/py/objfun.c
index d828b6d084..1c3208aca1 100644
--- a/py/objfun.c
+++ b/py/objfun.c
@@ -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,
};