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.
This commit is contained in:
14
py/bc.c
14
py/bc.c
@@ -269,19 +269,25 @@ continue2:;
|
||||
}
|
||||
}
|
||||
|
||||
// get the ip and skip argument names
|
||||
// read the size part of the prelude
|
||||
const byte *ip = code_state->ip;
|
||||
MP_BC_PRELUDE_SIZE_DECODE(ip);
|
||||
|
||||
// jump over code info (source file and line-number mapping)
|
||||
ip += mp_decode_uint_value(ip);
|
||||
ip += n_info;
|
||||
|
||||
// bytecode prelude: initialise closed over variables
|
||||
size_t local_num;
|
||||
while ((local_num = *ip++) != 255) {
|
||||
for (; n_cell; --n_cell) {
|
||||
size_t local_num = *ip++;
|
||||
code_state->state[n_state - 1 - local_num] =
|
||||
mp_obj_new_cell(code_state->state[n_state - 1 - local_num]);
|
||||
}
|
||||
|
||||
#if !MICROPY_PERSISTENT_CODE
|
||||
// so bytecode is aligned
|
||||
ip = MP_ALIGN(ip, sizeof(mp_uint_t));
|
||||
#endif
|
||||
|
||||
// now that we skipped over the prelude, set the ip for the VM
|
||||
code_state->ip = ip;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user