summaryrefslogtreecommitdiff
path: root/py/emitbc.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/emitbc.c')
-rw-r--r--py/emitbc.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/py/emitbc.c b/py/emitbc.c
index 365ec458a..161e8c7f6 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -115,12 +115,24 @@ STATIC void emit_write_code_info_qstr(emit_t* emit, qstr qstr) {
#if MICROPY_ENABLE_SOURCE_LINE
STATIC void emit_write_code_info_bytes_lines(emit_t* emit, uint bytes_to_skip, uint lines_to_skip) {
assert(bytes_to_skip > 0 || lines_to_skip > 0);
+ //printf(" %d %d\n", bytes_to_skip, lines_to_skip);
while (bytes_to_skip > 0 || lines_to_skip > 0) {
- uint b = MIN(bytes_to_skip, 31);
- uint l = MIN(lines_to_skip, 7);
+ mp_uint_t b, l;
+ if (lines_to_skip <= 6) {
+ // use 0b0LLBBBBB encoding
+ b = MIN(bytes_to_skip, 0x1f);
+ l = MIN(lines_to_skip, 0x3);
+ *emit_get_cur_to_write_code_info(emit, 1) = b | (l << 5);
+ } else {
+ // use 0b1LLLBBBB 0bLLLLLLLL encoding (l's LSB in second byte)
+ b = MIN(bytes_to_skip, 0xf);
+ l = MIN(lines_to_skip, 0x7ff);
+ byte *ci = emit_get_cur_to_write_code_info(emit, 2);
+ ci[0] = 0x80 | b | ((l >> 4) & 0x70);
+ ci[1] = l;
+ }
bytes_to_skip -= b;
lines_to_skip -= l;
- *emit_get_cur_to_write_code_info(emit, 1) = b | (l << 5);
}
}
#endif
@@ -363,7 +375,6 @@ STATIC void emit_bc_set_source_line(emit_t *emit, int source_line) {
uint bytes_to_skip = emit->bytecode_offset - emit->last_source_line_offset;
uint lines_to_skip = source_line - emit->last_source_line;
emit_write_code_info_bytes_lines(emit, bytes_to_skip, lines_to_skip);
- //printf(" %d %d\n", bytes_to_skip, lines_to_skip);
emit->last_source_line_offset = emit->bytecode_offset;
emit->last_source_line = source_line;
}