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.
diff --git a/py/compile.c b/py/compile.c
index b24e94a..cf87e01 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -2505,6 +2505,7 @@
}
} else {
mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn;
+ EMIT(set_line_number, pns->source_line);
compile_function_t f = compile_function[MP_PARSE_NODE_STRUCT_KIND(pns)];
if (f == NULL) {
printf("node %u cannot be compiled\n", (uint)MP_PARSE_NODE_STRUCT_KIND(pns));
@@ -3024,7 +3025,7 @@
}
}
-mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) {
+mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, bool is_repl) {
compiler_t *comp = m_new(compiler_t, 1);
comp->is_repl = is_repl;
@@ -3131,7 +3132,7 @@
default:
if (emit_bc == NULL) {
- emit_bc = emit_bc_new(max_num_labels);
+ emit_bc = emit_bc_new(source_file, max_num_labels);
}
comp->emit = emit_bc;
comp->emit_method_table = &emit_bc_method_table;