Repository navigation
Changes
The C that ppy emit c and ppy emit cpp write reads like hand-written C in every form, library included, and ppy build --library gives C callers a library they can link and errors they can handle.
Structured C
- Every function is written with
while,if/else,break,continue, andreturn. Loops with several exits, shared raise and clean-up paths, generator resumes, and regex matchers no longer fall back to labels andgoto; a failed check returns where it happens instead of jumping tofallback:. - Tests that share a target are written as one condition (
if (!seen || x > best)), and anifthat returns has noelse. - No function in
examples/falls back to labels in any form (library,--standalone,--unsafe, and C++). On 0.7.1, 27 of the 183 emitted files did.
Libraries
ppy build --librarystops withE1807when an exported function did not lower, naming the function and the reason, instead of leaving it out of the header.- The library links libm, so a C consumer needs only
pkg-config --libs <name>. - An export whose Python code raises returns 0, and
ppy_last_error()gives CPython's last line for the exception (IndexError: list index out of range), instead of killing the caller withSIGILL.ppy emit cexports print that line before they abort.
Fixed
- The safe C form no longer writes string constants that no function reads, which
-Wunused-variableflagged on Python 3.12 and 3.13.
Install or upgrade with pip install --upgrade "ppy-lang[llvm]==0.7.2".
The full repository gate passed on Python 3.12, 3.13, and 3.14, with the emitted C of the new tests run under AddressSanitizer and UndefinedBehaviorSanitizer.