Commit graph

2 commits

Author SHA1 Message Date
ce6de427be
Fix munging of __version__ 2024-01-11 09:06:55 -06:00
5de7f0538a
Add advanced source transformations to reduce type checking overhead
The new 'munge' module performs transformations on the source code.
It uses the AST (abstract syntax tree) representation of Python code
to recognize some idioms such as `if STATIC_TYPING:` and transforms
them into alternatives that have zero overhead in mpy-compiled files
(e.g., `if STATIC_TYPING:` is transformed into `if 0:`, which is eliminated
at compile time due to mpy-cross constant-propagation and dead branch
elimination)

The code assumes the input file is black-formatted. In particular, it
would malfunction if an if-statement and its body are on the same line:
`if STATIC_TYPING: print("boo")` would be incorrectly munged.
2024-01-02 10:24:50 -06:00