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.
This commit is contained in:
parent
8f472ad577
commit
418aca976c
1
py/obj.h
1
py/obj.h
@ -511,6 +511,7 @@ typedef struct _mp_obj_fun_native_t { // need this so we can define const object
|
|||||||
|
|
||||||
bool mp_obj_fun_prepare_simple_args(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args,
|
bool mp_obj_fun_prepare_simple_args(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args,
|
||||||
uint *out_args1_len, const mp_obj_t **out_args1, uint *out_args2_len, const mp_obj_t **out_args2);
|
uint *out_args1_len, const mp_obj_t **out_args1, uint *out_args2_len, const mp_obj_t **out_args2);
|
||||||
|
const char *mp_obj_fun_get_name(mp_obj_t fun);
|
||||||
const char *mp_obj_code_get_name(const byte *code_info);
|
const char *mp_obj_code_get_name(const byte *code_info);
|
||||||
|
|
||||||
mp_obj_t mp_identity(mp_obj_t self);
|
mp_obj_t mp_identity(mp_obj_t self);
|
||||||
|
11
py/objcell.c
11
py/objcell.c
@ -20,14 +20,13 @@ void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj) {
|
|||||||
self->obj = obj;
|
self->obj = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
||||||
STATIC void cell_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
|
STATIC void cell_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
|
||||||
mp_obj_cell_t *o = o_in;
|
mp_obj_cell_t *o = o_in;
|
||||||
print(env, "<cell ");
|
print(env, "<cell %p ", o->obj);
|
||||||
if (o->obj == MP_OBJ_NULL) {
|
if (o->obj == MP_OBJ_NULL) {
|
||||||
print(env, "(nil)");
|
print(env, "(nil)");
|
||||||
} else {
|
} else {
|
||||||
//print(env, "%p", o->obj);
|
|
||||||
mp_obj_print_helper(print, env, o->obj, PRINT_REPR);
|
mp_obj_print_helper(print, env, o->obj, PRINT_REPR);
|
||||||
}
|
}
|
||||||
print(env, ">");
|
print(env, ">");
|
||||||
@ -36,8 +35,10 @@ STATIC void cell_print(void (*print)(void *env, const char *fmt, ...), void *env
|
|||||||
|
|
||||||
const mp_obj_type_t cell_type = {
|
const mp_obj_type_t cell_type = {
|
||||||
{ &mp_type_type },
|
{ &mp_type_type },
|
||||||
.name = MP_QSTR_, // should never need to print cell type
|
.name = MP_QSTR_, // cell representation is just value in < >
|
||||||
//.print = cell_print,
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
||||||
|
.print = cell_print,
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
mp_obj_t mp_obj_new_cell(mp_obj_t obj) {
|
mp_obj_t mp_obj_new_cell(mp_obj_t obj) {
|
||||||
|
@ -38,10 +38,10 @@ mp_obj_t closure_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
||||||
STATIC void closure_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
|
STATIC void closure_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
|
||||||
mp_obj_closure_t *o = o_in;
|
mp_obj_closure_t *o = o_in;
|
||||||
print(env, "<closure %p, n_closed=%u ", o, o->n_closed);
|
print(env, "<closure %s at %p, n_closed=%u ", mp_obj_fun_get_name(o->fun), o, o->n_closed);
|
||||||
for (int i = 0; i < o->n_closed; i++) {
|
for (int i = 0; i < o->n_closed; i++) {
|
||||||
if (o->closed[i] == MP_OBJ_NULL) {
|
if (o->closed[i] == MP_OBJ_NULL) {
|
||||||
print(env, "(nil)");
|
print(env, "(nil)");
|
||||||
@ -57,7 +57,9 @@ STATIC void closure_print(void (*print)(void *env, const char *fmt, ...), void *
|
|||||||
const mp_obj_type_t closure_type = {
|
const mp_obj_type_t closure_type = {
|
||||||
{ &mp_type_type },
|
{ &mp_type_type },
|
||||||
.name = MP_QSTR_closure,
|
.name = MP_QSTR_closure,
|
||||||
//.print = closure_print,
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
||||||
|
.print = closure_print,
|
||||||
|
#endif
|
||||||
.call = closure_call,
|
.call = closure_call,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -131,8 +131,9 @@ const char *mp_obj_code_get_name(const byte *code_info) {
|
|||||||
return qstr_str(block_name);
|
return qstr_str(block_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *mp_obj_fun_get_name(mp_obj_fun_bc_t *o) {
|
const char *mp_obj_fun_get_name(mp_obj_t fun_in) {
|
||||||
const byte *code_info = o->bytecode;
|
mp_obj_fun_bc_t *fun = fun_in;
|
||||||
|
const byte *code_info = fun->bytecode;
|
||||||
return mp_obj_code_get_name(code_info);
|
return mp_obj_code_get_name(code_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user