Due to running into memory size constraints with on target compilation of scripts I am looking into compiling from py to mpy on an external host and transferring the compiled program to the target.
At first sight it actually seems to work but if I compare an mpy file compiled on the target versus one compiled on the host pc there are a lot of differences between them. One I can decipher in the bytecode is that some names are postfixed with the filename in the host pc version (so eg enter versus enter*main.py), but there are many more.
I figured this maybe had to do with qstrings and i added all the generated qstrings of the target to the qstrdefsport.h file in mpy-cross and recompiled mpy-cross but as far as i can see these have been completely ignored (they do not end up in /mpy-cross/build/genhdr/qstrdefs.generated.h).
I also do not think it has to do with optimization levels as both files have about the same size after compilation (85582 on target versus 86565 on host).
On the host i compile with ./mpy-cross main.py
On the target i compile/save with (with the program loaded into the str variable) :
Code: Select all
qstr src_name = MP_QSTR_; mp_lexer_t *lex = mp_lexer_new_from_str_len( src_name, str, strlen(str), false); mp_parse_tree_t pt = mp_parse(lex, MP_PARSE_FILE_INPUT); mp_raw_code_t *rc = mp_compile_to_raw_code(&pt, src_name, MP_EMIT_OPT_NONE, false); mp_raw_code_save_file(rc, output_file);
Anyone any insight in where the differences might come from (and if I should be worried about them ) ?