Separating compiler and executer from Micropython interpreter #11417
Replies: 3 comments 3 replies
-
This is what
It is already possible to disable the compiler and leave only the VM to execute bytecodes by setting
To run MPY bytecodes directly, this is what we are using in combination with #8381 mp_reader_t reader;
mp_vfs_map_minimal_t data;
mp_vfs_map_minimal_new_reader(&reader, &data, mpy_buffer, mpy_buffer_size);
mp_module_context_t *context = m_new_obj(mp_module_context_t);
context->module.globals = mp_globals_get();
mp_compiled_module_t compiled_module;
compiled_module.context = context;
mp_raw_code_load(&reader, &compiled_module);
mp_obj_t module_fun = mp_make_function_from_raw_code(compiled_module.rc, context, NULL);
// Run the script while letting CTRL-C interrupt it.
mp_hal_set_interrupt_char(CHAR_CTRL_C);
mp_call_function_0(module_fun);
mp_hal_set_interrupt_char(-1); Hopefully that is enough to get you pointed in the right direction. |
Beta Was this translation helpful? Give feedback.
-
This is a really interesting concept. Wish I had the MP internal skills to help. Another way to look at this is to implement the compiler as an application server. The MP device would call the compiler server with the script name (and MP version and device type) and is returned the compiled byte code for execution. Hope you get this running, |
Beta Was this translation helpful? Give feedback.
-
Hello @dlech, Thanks for your support!
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm working on a project where memory and other resources are a bit less. Also, the management requested to implement a feature where a user can write his script outside, compile it and send the bytecode over any communication media (wired or wirelessly) to the device. Hence, the device on the field will receive the byte code and starts executing it.
So, I'm planning to separate the micropython stack into two different parts, one that interprets and compiles the script to generate the byte code. And the other one executes it. I'm attaching a few images in the description to explain in detail.


To run the Python script, we have a simple function:
I tried separating this function into two blocks. So the first one would be the compiler.
But as in the output of the compiled script,
module_fun
is avoid *
, so I don't know the length and type of data it is pointing to. Therefore I don't know how to transfer this data over wired or wireless communication. And then, the other device receives this data and starts executing.The receiver function could be like this:
So if anyone knows how to achieve this or could give me valuable suggestions, it would be highly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions