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:
the following functions were deleted: int_to_char, print_string and pack_string
sh-runtime.c shrinks from 1046 to 918 lines (-128) while printf is much more useful
pnut.sh shrinks from 7360 to 7191 lines (-169)
printf calls with literal format string are compiled directly to the shell's printf in all cases except when %s and %c are used.
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 ofsh-runtime.c
which inflated the bootstrap times even whenprintf
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 theprintf
unrolling optimization that is done onprintf
calls with literal format string.The end result is:
int_to_char
,print_string
andpack_string
sh-runtime.c
shrinks from 1046 to 918 lines (-128) whileprintf
is much more usefulpnut.sh
shrinks from 7360 to 7191 lines (-169)printf
calls with literal format string are compiled directly to the shell'sprintf
in all cases except when%s
and%c
are used.