8000 py: Fix line number printing for file with 1 line. · pcurry/circuitpython@b427d6a · GitHub 10000
[go: up one dir, main page]

Skip to content

Commit b427d6a

Browse files
committed
py: Fix line number printing for file with 1 line.
With a file with 1 line (and an error on that line), used to show the line as number 0. Now shows it correctly as line number 1. But, when line numbers are disabled, it now prints line number 1 for any line that has an error (instead of 0 as previously). This might end up being confusing, but requires extra RAM and/or hack logic to make it print something special in the case of no line numbers.
1 parent f05b87b commit b427d6a

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

py/emitglue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void
107107

108108
#ifdef WRITE_CODE
109109
FILE *fp_write_code = fopen("out-code", "wb");
110-
fwrite(fun_data, len, 1, fp_write_code);
110+
fwrite(fun_data, fun_len, 1, fp_write_code);
111111
fclose(fp_write_code);
112112
#endif
113113
#endif

py/vm.c

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -925,33 +925,29 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state *code_state, volatile mp_o
925925
mp_uint_t code_info_size = code_info[0] | (code_info[1] << 8) | (code_info[2] << 16) | (code_info[3] << 24);
926926
qstr source_file = code_info[4] | (code_info[5] << 8) | (code_info[6] << 16) | (code_info[7] << 24);
927927
qstr block_name = code_info[8] | (code_info[9] << 8) | (code_info[10] << 16) | (code_info[11] << 24);
928-
mp_uint_t source_line = 0;
929928
mp_uint_t bc = code_state->ip - code_info - code_info_size;
930929
//printf("find %lu %d %d\n", bc, code_info[12], code_info[13]);
931-
const byte* ci = code_info + 12;
932-
if (*ci) {
933-
source_line = 1;
934-
mp_uint_t c;
935-
while ((c = *ci)) {
936-
mp_uint_t b, l;
937-
if ((c & 0x80) == 0) {
938-
// 0b0LLBBBBB encoding
939-
b = c & 0x1f;
940-
l = c >> 5;
941-
ci += 1;
942-
} else {
943-
// 0b1LLLBBBB 0bLLLLLLLL encoding (l's LSB in second byte)
944-
b = c & 0xf;
945-
l = ((c << 4) & 0x700) | ci[1];
946-
ci += 2;
947-
}
948-
if (bc >= b) {
949-
bc -= b;
950-
source_line += l;
951-
} else {
952-
// found source line corresponding to bytecode offset
953-
break;
954-
}
930+
mp_uint_t source_line = 1;
931+
mp_uint_t c;
932+
for (const byte *ci = code_info + 12; (c = *ci);) {
933+
mp_uint_t b, l;
934+
if ((c & 0x80) == 0) {
935+
// 0b0LLBBBBB encoding
936+
b = c & 0x1f;
937+
l = c >> 5;
938+
ci += 1;
939+
} else {
940+
// 0b1LLLBBBB 0bLLLLLLLL encoding (l's LSB in second byte)
941+
b = c & 0xf;
942+
l = ((c << 4) & 0x700) | ci[1];
943+
ci += 2;
944+
}
945+
if (bc >= b) {
946+
bc -= b;
947+
source_line += l;
948+
} else {
949+
// found source line corresponding to bytecode offset
950+
break;
955951
}
956952
}
957953
mp_obj_exception_add_traceback(nlr.ret_val, source_file, source_line, block_name);

0 commit comments

Comments
 (0)
0