aboutsummaryrefslogtreecommitdiff
path: root/py/bc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-03-01 14:03:10 +1100
committerDamien George <damien.p.george@gmail.com>2019-03-05 16:27:34 +1100
commit992a6e1deab06aba07ab09687402d39a0c028a73 (patch)
treed1b94a56f39b0fa04cfe3e82aafaf65a243d4ab8 /py/bc.c
parent5996eeb48fa6ce773003eacbc7e0b52ad5cc4d31 (diff)
py/persistentcode: Pack qstrs directly in bytecode to reduce mpy size.
Instead of emitting two bytes in the bytecode for where the linked qstr should be written to, it is now replaced by the actual qstr data, or a reference into the qstr window. Reduces mpy file size by about 10%.
Diffstat (limited to 'py/bc.c')
-rw-r--r--py/bc.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/py/bc.c b/py/bc.c
index 4a29f439e..b178e7c20 100644
--- a/py/bc.c
+++ b/py/bc.c
@@ -382,7 +382,7 @@ STATIC const byte opcode_format_table[64] = {
#undef V
#undef O
-uint mp_opcode_format(const byte *ip, size_t *opcode_size) {
+uint mp_opcode_format(const byte *ip, size_t *opcode_size, bool count_var_uint) {
uint f = (opcode_format_table[*ip >> 2] >> (2 * (*ip & 3))) & 3;
const byte *ip_start = ip;
if (f == MP_OPCODE_QSTR) {
@@ -403,7 +403,9 @@ uint mp_opcode_format(const byte *ip, size_t *opcode_size) {
);
ip += 1;
if (f == MP_OPCODE_VAR_UINT) {
- while ((*ip++ & 0x80) != 0) {
+ if (count_var_uint) {
+ while ((*ip++ & 0x80) != 0) {
+ }
}
} else if (f == MP_OPCODE_OFFSET) {
ip += 2;