Commit 76d982ef authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

type->print(): Distinguish str() and repr() variety by passing extra param.

parent 24224d7c
......@@ -436,7 +436,7 @@ void do_repl(void) {
}
} else {
// uncaught exception
mp_obj_print((mp_obj_t)nlr.ret_val);
mp_obj_print((mp_obj_t)nlr.ret_val, PRINT_REPR);
printf("\n");
}
}
......@@ -474,7 +474,7 @@ bool do_file(const char *filename) {
return true;
} else {
// uncaught exception
mp_obj_print((mp_obj_t)nlr.ret_val);
mp_obj_print((mp_obj_t)nlr.ret_val, PRINT_REPR);
printf("\n");
return false;
}
......@@ -656,7 +656,7 @@ typedef struct _pyb_file_obj_t {
FIL fp;
} pyb_file_obj_t;
void file_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) {
void file_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
printf("<file %p>", self_in);
}
......@@ -1097,13 +1097,13 @@ soft_reset:
if (nlr_push(&nlr) == 0) {
mp_obj_t ret = rt_call_function_0(module_fun);
printf("done! got: ");
mp_obj_print(ret);
mp_obj_print(ret, PRINT_REPR);
printf("\n");
nlr_pop();
} else {
// uncaught exception
printf("exception: ");
mp_obj_print((mp_obj_t)nlr.ret_val);
mp_obj_print((mp_obj_t)nlr.ret_val, PRINT_REPR);
printf("\n");
}
......
......@@ -89,7 +89,7 @@ void timer_interrupt(void) {
} else {
// uncaught exception
printf("exception in timer interrupt\n");
mp_obj_print((mp_obj_t)nlr.ret_val);
mp_obj_print((mp_obj_t)nlr.ret_val, PRINT_REPR);
printf("\n");
}
}
......
# TODO: requires repr()
#a = IndexError(1, "test", [100, 200])
#print(repr(a))
print(repr(IndexError()))
print(str(IndexError()))
print(repr(IndexError("foo")))
print(str(IndexError("foo")))
a = IndexError(1, "test", [100, 200])
print(str(a))
print(repr(a))
......@@ -15,7 +15,7 @@ typedef struct _mp_obj_fdfile_t {
int fd;
} mp_obj_fdfile_t;
static void fdfile_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) {
static void fdfile_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
mp_obj_fdfile_t *self = self_in;
print(env, "<io.FileIO %d>", self->fd);
}
......
......@@ -63,7 +63,7 @@ static void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind
nlr_pop();
} else {
// uncaught exception
mp_obj_print((mp_obj_t)nlr.ret_val);
mp_obj_print((mp_obj_t)nlr.ret_val, PRINT_REPR);
printf("\n");
}
}
......@@ -159,7 +159,7 @@ typedef struct _test_obj_t {
int value;
} test_obj_t;
static void test_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) {
static void test_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
test_obj_t *self = self_in;
print(env, "<test %d>", self->value);
}
......
Supports Markdown
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