This is a code generator for micropython.
MicroPython has multiple ways of including your code into an application, one of those is so called frozen bytecode. See this for more info.
The problem with frozen bytecode is that if a frozen module is
import'ed all of it is loaded into RAM. When a Project contains
large dictionary's that are accessed very frequently this can quickly
eat up a lot of the RAM available.
This problem does not exist with C-modules, since C modules are normal C code that gets integrated into the MicroPython executable. They don't get loaded into RAM when they are imported in Python.
But writing C modules for micropython dictionary's is very tedious,
and the resulting code is not very readable. This is why this code
generator was created, it allows you to write your dictionary's in
your normal .py files with all the comments and decorations that you
may want to describe your dictionary. This code is then taken by this
code generator and a C module with the exact contents is created that
can then be imported without taking up precious RAM.
This generator does not have any prerequisites apart from a standard Python 3 install.
This generator is currently lacking any code generation options, the C code is just generated in a fixed fashion.
Given the example file test.py:
# comment ignored by the generator
dictionary = {
"HELLO":1,
"WORLD":2
}
# Formattion is ignored too !
dict={"BAD":1,"FORMATTING":"YES"}A C module containing the same 2 dictionary's can be created as follows:
./generator.py --filename test.pyThe generated module will be in the folder test. The module name will be "test" which is taken from the basename of the provided file.
They can also be specified on the commandline using --directory and
--modulename.