Hi, we will have about 6000 lines of python code ported from another project, which we would like to move to the micro-controller. It will run out of RAM memory during compilation. We could write it as C libraries, but then we would have no benefit of Python. What is the best approach to pre-compile python (any micro python variant of compiled code will do) and put it into ROM (I mean flash, but not the file system /flash as I don't believe it supports Execute In Place?)
1. How do we get pre-compiled python? (Can we trick the board to emit compiled bytes on to the serial port? Can the unix version emit such code?)
2. How do we put it in ROM? (Should we make an assembler-file with just databytes out of it and link as the C-libraries)
3. How do we get micro python to find it for our real .py files when they use import?
4. Can this be done for immutable datastructures as well?
Is there a high level description of the compile/emit/import stages of micropython? The parser is described here in the link below, and the article ends with an "next is compiler and code emitters.." but I can't see that those articles were written?!? https://www.kickstarter.com/projects/21 ... sts/669549
Thanks for any help to put me in the right direction /Anders H.
Python objects in ROM?
Re: Python objects in ROM?
Currently, it isn't possible to store the python bytecodes in ROM.andershedberg wrote:Hi, we will have about 6000 lines of python code ported from another project, which we would like to move to the micro-controller. It will run out of RAM memory during compilation. We could write it as C libraries, but then we would have no benefit of Python. What is the best approach to pre-compile python (any micro python variant of compiled code will do) and put it into ROM (I mean flash, but not the file system /flash as I don't believe it supports Execute In Place?)
1. How do we get pre-compiled python? (Can we trick the board to emit compiled bytes on to the serial port? Can the unix version emit such code?)
https://github.com/micropython/micropython/issues/222
It is possible to put many python data structures in ROM, but currently these are coded in C. To make this work today, I think you'd need to write a python script which converts the python data structure into some C code and compie that.andershedberg wrote: 2. How do we put it in ROM? (Should we make an assembler-file with just databytes out of it and link as the C-libraries)
3. How do we get micro python to find it for our real .py files when they use import?
4. Can this be done for immutable datastructures as well?
I don't believe that there is. import is handled by looking in an dict of already loaded modules, and if a given module is found there it's used, otherwise sys.path is searched for module.pyandershedberg wrote: Is there a high level description of the compile/emit/import stages of micropython? The parser is described here in the link below, and the article ends with an "next is compiler and code emitters.." but I can't see that those articles were written?!? https://www.kickstarter.com/projects/21 ... sts/669549
Thanks for any help to put me in the right direction /Anders H.
-
- Posts: 2
- Joined: Sun Oct 05, 2014 12:03 pm
Re: Python objects in ROM?
Thanks for the answer, I'll look into how to make C programs, as https://github.com/micropython/micropython/issues/222 was a bit over my head.dhylands wrote:It is possible to put many python data structures in ROM, but currently these are coded in C. To make this work today, I think you'd need to write a python script which converts the python data structure into some C code and compie that.andershedberg wrote: 2. How do we put it in ROM? (Should we make an assembler-file with just databytes out of it and link as the C-libraries)
3. How do we get micro python to find it for our real .py files when they use import?
4. Can this be done for immutable datastructures as well?
Re: Python objects in ROM?
You'll probably want to start looking at this thread: http://forum.micropython.org/viewtopic.php?f=3&t=153