aboutsummaryrefslogtreecommitdiff
path: root/py/emitbc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-02-10 11:58:10 +1100
committerDamien George <damien.p.george@gmail.com>2017-02-10 11:58:10 +1100
commitcc2dbdd1fe4a5131a40b2ab73195786451314bf8 (patch)
treef7b348766618548b8c39847eb67c811069d5a585 /py/emitbc.c
parent8f1c6d952ac695bc41afe8965aa79fbabcc6bcc1 (diff)
py/emitbc: Produce correct line number info for large bytecode chunks.
Previous to this patch, for large chunks of bytecode that originated from a single source-code line, the bytecode-line mapping would generate something like (for 42 bytecode bytes and 1 line): BC_SKIP=31 LINE_SKIP=1 BC_SKIP=11 LINE_SKIP=0 This would mean that any errors in the last 11 bytecode bytes would be reported on the following line. This patch fixes it to generate instead: BC_SKIP=31 LINE_SKIP=0 BC_SKIP=11 LINE_SKIP=1
Diffstat (limited to 'py/emitbc.c')
-rw-r--r--py/emitbc.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/py/emitbc.c b/py/emitbc.c
index e11c9ae94..e3a047f27 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -144,10 +144,15 @@ STATIC void emit_write_code_info_bytes_lines(emit_t *emit, mp_uint_t bytes_to_sk
//printf(" %d %d\n", bytes_to_skip, lines_to_skip);
while (bytes_to_skip > 0 || lines_to_skip > 0) {
mp_uint_t b, l;
- if (lines_to_skip <= 6) {
+ if (lines_to_skip <= 6 || bytes_to_skip > 0xf) {
// use 0b0LLBBBBB encoding
b = MIN(bytes_to_skip, 0x1f);
- l = MIN(lines_to_skip, 0x3);
+ if (b < bytes_to_skip) {
+ // we can't skip any lines until we skip all the bytes
+ l = 0;
+ } else {
+ 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)