Skip to content

Commit 418aca9

Browse files
committed
objclosure, objcell: Print detailed representation if was requested.
Well, it is bound to "detailed error reporting", but that's closest what we have now without creating new entities.
1 parent 8f472ad commit 418aca9

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

py/obj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ typedef struct _mp_obj_fun_native_t { // need this so we can define const object
511511

512512
bool mp_obj_fun_prepare_simple_args(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args,
513513
uint *out_args1_len, const mp_obj_t **out_args1, uint *out_args2_len, const mp_obj_t **out_args2);
514+
const char *mp_obj_fun_get_name(mp_obj_t fun);
514515
const char *mp_obj_code_get_name(const byte *code_info);
515516

516517
mp_obj_t mp_identity(mp_obj_t self);

py/objcell.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj) {
2020
self->obj = obj;
2121
}
2222

23-
#if 0
23+
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
2424
STATIC void cell_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
2525
mp_obj_cell_t *o = o_in;
26-
print(env, "<cell ");
26+
print(env, "<cell %p ", o->obj);
2727
if (o->obj == MP_OBJ_NULL) {
2828
print(env, "(nil)");
2929
} else {
30-
//print(env, "%p", o->obj);
3130
mp_obj_print_helper(print, env, o->obj, PRINT_REPR);
3231
}
3332
print(env, ">");
@@ -36,8 +35,10 @@ STATIC void cell_print(void (*print)(void *env, const char *fmt, ...), void *env
3635

3736
const mp_obj_type_t cell_type = {
3837
{ &mp_type_type },
39-
.name = MP_QSTR_, // should never need to print cell type
40-
//.print = cell_print,
38+
.name = MP_QSTR_, // cell representation is just value in < >
39+
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
40+
.print = cell_print,
41+
#endif
4142
};
4243

4344
mp_obj_t mp_obj_new_cell(mp_obj_t obj) {

py/objclosure.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ mp_obj_t closure_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *
3838
}
3939
}
4040

41-
#if 0
41+
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
4242
STATIC void closure_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
4343
mp_obj_closure_t *o = o_in;
44-
print(env, "<closure %p, n_closed=%u ", o, o->n_closed);
44+
print(env, "<closure %s at %p, n_closed=%u ", mp_obj_fun_get_name(o->fun), o, o->n_closed);
4545
for (int i = 0; i < o->n_closed; i++) {
4646
if (o->closed[i] == MP_OBJ_NULL) {
4747
print(env, "(nil)");
@@ -57,7 +57,9 @@ STATIC void closure_print(void (*print)(void *env, const char *fmt, ...), void *
5757
const mp_obj_type_t closure_type = {
5858
{ &mp_type_type },
5959
.name = MP_QSTR_closure,
60-
//.print = closure_print,
60+
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
61+
.print = closure_print,
62+
#endif
6163
.call = closure_call,
6264
};
6365

py/objfun.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ const char *mp_obj_code_get_name(const byte *code_info) {
131131
return qstr_str(block_name);
132132
}
133133

134-
const char *mp_obj_fun_get_name(mp_obj_fun_bc_t *o) {
135-
const byte *code_info = o->bytecode;
134+
const char *mp_obj_fun_get_name(mp_obj_t fun_in) {
135+
mp_obj_fun_bc_t *fun = fun_in;
136+
const byte *code_info = fun->bytecode;
136137
return mp_obj_code_get_name(code_info);
137138
}
138139

0 commit comments

Comments
 (0)