A Partial Evaluator for C
64 points - today at 4:51 AM
SourceComments
looperhacks today at 9:33 AM
I know this has nothing to do with TFA, just want to check my understanding of C. Doesn't the code example have a bug?
miniprintf(char fmt[], int val[])
{
int i = 0;
while( *fmt != '\0' ) {
if( *fmt != '%' )
putchar(*fmt);
else
switch(*++fmt) {
case 'd' : putint(val[i++]); break;
case '%' : putchar('%'); break;
default : prterror(*fmt); break;
}
fmt++;
}
}
If the static string was "%", the else branch would move past the end of the string. Assuming prterror doesn't crash the program, this reads out-of-bounds, right?RossBencina today at 6:48 AM
While unsuccessfully searching for the Tempo source code I found LLPE, a partial evaluator for LLVM bitcode: https://www.llpe.org/
MiroslavPokorny today at 8:58 AM
> The Tempo specializer has been made publicly available under a licence in April 1998. At of March 99, it was being used by about thirty people around the world. The binary version of Tempo has just (July 2000) been made available without any restrictions, and we expect a full unrestricted source release under GPL to follow soon.
rramadass today at 9:03 AM
Partial Evaluation - https://en.wikipedia.org/wiki/Partial_evaluation
Partial Evaluation and Automatic Program Generation by Neil Jones et al. - https://web.archive.org/web/20071012081310/http://www.itu.dk...
dmitrygr today at 8:12 AM
GCC does quite a bit of this nowadays. It is quite impressive to see when you disassemble its output.