udem-dlteam / pnut

🥜 A Self-Compiling C Transpiler Targeting Human-Readable POSIX Shell
https://pnut.sh
BSD 2-Clause "Simplified" License
424 stars 14 forks source link

Improve printf and simplify runtime #72

Closed laurenthuberdeau closed 2 months ago

laurenthuberdeau commented 3 months ago

Context

The printf function from the runtime library was an incomplete and unmaintainable mess and pulled a lot of code with it. It also took an important part of sh-runtime.c which inflated the bootstrap times even when printf was not used as the runtime library function generating it needed to be compiled.

This PR rewrites the printf function so it supports most of the C format specifiers (including flags, width and precision options) and reuse existing functions when possible. It does so both in the runtime (in _printf) and in the printf unrolling optimization that is done on printf calls with literal format string.

The end result is: