Tuna Gül

Systems

ppps Archive

A pre-preprocessor for C and C++ on PyPI: Python written inside marked comments in a C file runs before compilation, and its results are written into the output.

Role
Author
Period
Mar 2021
Team
Solo
Stack
Python · C
Impact
On PyPI as ppps

Code ↗PyPI ↗

Illustration of a C pre-preprocessor: on the left a C file with a Python function inside /** **/ marker comments and an /*( seq(5) )*/ expression marker; on the right the output file, where the Python block is gone and the marker has become 0, 1, 2, 3, 4, joined by an amber connector.

What I did

Code generation for C with Python instead of macros. ppps.process_file("src/main.c", "build/ppps/out.c") reads a C file, finds the text between two kinds of marker comments that you choose, runs the first kind as Python statements and the second as expressions, and writes the values of the expressions into the output file. Options decide whether the Python is kept in the output or removed.