summaryrefslogtreecommitdiff
path: root/py/vm.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-09-25 15:45:47 +1000
committerDamien George <damien.p.george@gmail.com>2019-10-01 12:26:22 +1000
commitc8c0fd4ca39fbdcf9ca5f2fc99ca4d6b81a28b65 (patch)
tree0fcbf3a263817be928c0b7db847d94293c79cce5 /py/vm.c
parentb5ebfadbd615de42c43851f27a062bacd9147996 (diff)
py: Rework and compress second part of bytecode prelude.
This patch compresses the second part of the bytecode prelude which contains the source file name, function name, source-line-number mapping and cell closure information. This part of the prelude now begins with a single varible length unsigned integer which encodes 2 numbers, being the byte-size of the following 2 sections in the header: the "source info section" and the "closure section". After decoding this variable unsigned integer it's possible to skip over one or both of these sections very easily. This scheme saves about 2 bytes for most functions compared to the original format: one in the case that there are no closure cells, and one because padding was eliminated.
Diffstat (limited to 'py/vm.c')
-rw-r--r--py/vm.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/py/vm.c b/py/vm.c
index 82218fd97..7487ff61b 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -1441,10 +1441,13 @@ unwind_loop:
&& *code_state->ip != MP_BC_RAISE_LAST) {
const byte *ip = code_state->fun_bc->bytecode;
MP_BC_PRELUDE_SIG_DECODE(ip);
- size_t bc = code_state->ip - ip;
- size_t code_info_size = mp_decode_uint_value(ip);
- ip = mp_decode_uint_skip(ip); // skip code_info_size
- bc -= code_info_size;
+ MP_BC_PRELUDE_SIZE_DECODE(ip);
+ const byte *bytecode_start = ip + n_info + n_cell;
+ #if !MICROPY_PERSISTENT_CODE
+ // so bytecode is aligned
+ bytecode_start = MP_ALIGN(bytecode_start, sizeof(mp_uint_t));
+ #endif
+ size_t bc = code_state->ip - bytecode_start;
#if MICROPY_PERSISTENT_CODE
qstr block_name = ip[0] | (ip[1] << 8);
qstr source_file = ip[2] | (ip[3] << 8);