extmod generator
extmod generator
Recently I was trying to learn how to write my own external modules and found out it was not completely straightforward.
To help me out, I wrote a generator that will analyze a module written in Python3 syntax and generate a module to use with Micropython (to be placed in extmod directory).
Source is available here:
https://github.com/prusnak/micropython-extmod-generator
It has some rough edges, but I think it is already quite usable and helpful.
What do you think? As always, pull requests are welcome!
To help me out, I wrote a generator that will analyze a module written in Python3 syntax and generate a module to use with Micropython (to be placed in extmod directory).
Source is available here:
https://github.com/prusnak/micropython-extmod-generator
It has some rough edges, but I think it is already quite usable and helpful.
What do you think? As always, pull requests are welcome!
Re: extmod generator
Nice idea. I think example.py and example.c should be in readme.
Re: extmod generator
Added links to examples to README.md
-
- Posts: 463
- Joined: Wed Apr 08, 2015 5:19 am
Re: extmod generator
Cool, very useful. Two suggestions:
- I think the convention in Python is generally to use __author__ instead of _author (and __version__, etc.) for module meta data.
- Would be nice to generate the qstr definitions as well (maybe put them in a comment in the .c file).
- I think the convention in Python is generally to use __author__ instead of _author (and __version__, etc.) for module meta data.
- Would be nice to generate the qstr definitions as well (maybe put them in a comment in the .c file).
Re: extmod generator
OK, changed in 409337515c0db6789a8344164102955b7ce0ce96.SpotlightKid wrote: - I think the convention in Python is generally to use __author__ instead of _author (and __version__, etc.) for module meta data.
Aren't they supposed to be generated automagically via makeqstrdata.py during the build?SpotlightKid wrote: - Would be nice to generate the qstr definitions as well (maybe put them in a comment in the .c file).
Re: extmod generator
No makeqstrdata takes the qstrs found in one of the qstrdefs.h files and generates the c structures associated with a qstr.stick wrote:Aren't they supposed to be generated automagically via makeqstrdata.py during the build?
The file you'd need to create would be a file that contained the:
Code: Select all
Q(someString)
Q(someOtherString)
I'd love to see a tool which created the qstrdefs.h file automagically, but it hasn't been written yet. Getting it right is definitely non-trivial.
Re: extmod generator
Ah I see, implemented in 53ff05cd419ea37b128807effe833b480845fbafdhylands wrote:No makeqstrdata takes the qstrs found in one of the qstrdefs.h files and generates the c structures associated with a qstr.
Hm, I think that similar magic to what I used in the commit above could be used to generate all required qstrdefs.dhylands wrote: I'd love to see a tool which created the qstrdefs.h file automagically, but it hasn't been written yet. Getting it right is definitely non-trivial.
Re: extmod generator
The issue I see with generating qstrdefs automtically is figuring out what #ifdefs they belong in. We don't want to include unnecessary qstrs in the image.
Re: extmod generator
qstr generation is something that should definitely be looked into. I believe the point is to not bloat sources with #ifdefs or even better to ban the use of ifdefs except for header file guards
Stick is in much better position while generating qstr definitions since with python reflection the generator know exactly what comes into the output. However, this is not the case with hand written uPy module in C
Stick is in much better position while generating qstr definitions since with python reflection the generator know exactly what comes into the output. However, this is not the case with hand written uPy module in C
braiins - Your partner in embedded world - http://www.braiins.cz
Re: extmod generator
I created a spin-off thread for this topic here: qstrdef-generatordhylands wrote:The issue I see with generating qstrdefs automtically is figuring out what #ifdefs they belong in. We don't want to include unnecessary qstrs in the image.