diff options
author | Damien George <damien.p.george@gmail.com> | 2014-01-18 23:24:36 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-01-18 23:24:36 +0000 |
commit | 08335004cfe95048ee06134a3e49b9fb75639139 (patch) | |
tree | 7518a854012938fd70c57b3571a630a142b84f28 /unix | |
parent | aefe79880f8c5f66132673ccc9be27d2ca29005b (diff) | |
download | micropython-08335004cfe95048ee06134a3e49b9fb75639139.tar.gz micropython-08335004cfe95048ee06134a3e49b9fb75639139.zip |
Add source file name and line number to error messages.
Byte code has a map from byte-code offset to source-code line number,
used to give better error messages.
Diffstat (limited to 'unix')
-rw-r--r-- | unix/main.c | 14 | ||||
-rw-r--r-- | unix/mpconfigport.h | 1 |
2 files changed, 12 insertions, 3 deletions
diff --git a/unix/main.c b/unix/main.c index d89f39da70..c33a439376 100644 --- a/unix/main.c +++ b/unix/main.c @@ -49,13 +49,14 @@ static void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind return; } + qstr source_name = mp_lexer_source_name(lex); mp_lexer_free(lex); //printf("----------------\n"); - //parse_node_show(pn, 0); + //mp_parse_node_show(pn, 0); //printf("----------------\n"); - mp_obj_t module_fun = mp_compile(pn, is_repl); + mp_obj_t module_fun = mp_compile(pn, source_name, is_repl); if (module_fun == mp_const_none) { // compile error @@ -69,7 +70,14 @@ 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, PRINT_REPR); + mp_obj_t exc = (mp_obj_t)nlr.ret_val; + if (MP_OBJ_IS_TYPE(exc, &exception_type)) { + qstr file; + machine_uint_t line; + mp_obj_exception_get_source_info(exc, &file, &line); + printf("File \"%s\", line %d\n", qstr_str(file), (int)line); + } + mp_obj_print(exc, PRINT_REPR); printf("\n"); } } diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index daa18961c0..b36c171969 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -13,6 +13,7 @@ #define MICROPY_ENABLE_LEXER_UNIX (1) #define MICROPY_ENABLE_FLOAT (1) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG) +#define MICROPY_SHOW_BC (0) // type definitions for the specific machine |