mp-cross and precompiled but not frozen scripts
Posted: Thu Mar 01, 2018 1:42 pm
Hi,
I have a scenario where i would like to precompile a .py script on a host machine, send it over to a target and then execute the precompiled script.
Initially I was under the impression that this would be trivial but after reading the forums I found the following discussion
https://github.com/micropython/micropython/issues/2709
and now i am not so sure anymore
This discussion has the additional requirement though that the mpy script should be able to run from flash, if i understand it correctly it becomes easier if the mpy code can stay in ram ?
I probably do not understand the full extend of this discussion though, to start i have a few additional (probably noob, sorry) questions.
[0] Is this 'simpler' scenario already possible with 1.9.3 ? Or I am I going to run into the same problems as mentioned in the thread. For one I see QSTR's being mentioned, do i need to do something special for strings in the mpy or is this taken care of when calling mp_make_function_from_raw_code ?
[1] Looking at the mp_make_function_from_raw_code function, there are several kinds of 'precompiled code':
typedef enum {
MP_CODE_UNUSED,
MP_CODE_RESERVED,
MP_CODE_BYTECODE,
MP_CODE_NATIVE_PY,
MP_CODE_NATIVE_VIPER,
MP_CODE_NATIVE_ASM,
} mp_raw_code_kind_t;
What is native py ?
[2] How do the mp-cross options map to these types ?
Implementation specific options:
emit={bytecode,native,viper} -- set the default code emitter
[3] I tried precompiling a script with mp-cross using
./mpy-cross -X emit=bytecode frozentest.py
./mpy-cross -X emit=native frozentest.py
and I get 2 times the same output. How is that possible? Am i using the emit option wrong ?
[4] I was surprised there is even a native option. How does mpy-cross cross know what the native target format is ? It is build using "make -C mpy-cross" and you cannot supply the target's architecture via the command line. Am i misunderstanding what native means ( = opcodes directly executable by the target's mcu bypassing the VM ?)?
I have a scenario where i would like to precompile a .py script on a host machine, send it over to a target and then execute the precompiled script.
Initially I was under the impression that this would be trivial but after reading the forums I found the following discussion
https://github.com/micropython/micropython/issues/2709
and now i am not so sure anymore
This discussion has the additional requirement though that the mpy script should be able to run from flash, if i understand it correctly it becomes easier if the mpy code can stay in ram ?
I probably do not understand the full extend of this discussion though, to start i have a few additional (probably noob, sorry) questions.
[0] Is this 'simpler' scenario already possible with 1.9.3 ? Or I am I going to run into the same problems as mentioned in the thread. For one I see QSTR's being mentioned, do i need to do something special for strings in the mpy or is this taken care of when calling mp_make_function_from_raw_code ?
[1] Looking at the mp_make_function_from_raw_code function, there are several kinds of 'precompiled code':
typedef enum {
MP_CODE_UNUSED,
MP_CODE_RESERVED,
MP_CODE_BYTECODE,
MP_CODE_NATIVE_PY,
MP_CODE_NATIVE_VIPER,
MP_CODE_NATIVE_ASM,
} mp_raw_code_kind_t;
What is native py ?
[2] How do the mp-cross options map to these types ?
Implementation specific options:
emit={bytecode,native,viper} -- set the default code emitter
[3] I tried precompiling a script with mp-cross using
./mpy-cross -X emit=bytecode frozentest.py
./mpy-cross -X emit=native frozentest.py
and I get 2 times the same output. How is that possible? Am i using the emit option wrong ?
[4] I was surprised there is even a native option. How does mpy-cross cross know what the native target format is ? It is build using "make -C mpy-cross" and you cannot supply the target's architecture via the command line. Am i misunderstanding what native means ( = opcodes directly executable by the target's mcu bypassing the VM ?)?