Richard Suchenwirth 2007-10-09 - Playing with tcltcc and its Critcl emulation, I had the idea of writing a very little C "compiler" which takes a (moderately) well-formed C source file, compiles (to memory) and executes it (by calling its main() function), so more along the lines of a C interpreter.
One problem I encountered is that char** seems not to be supported yet, so for first simplification I made argv a single string. Here's my script (ridiculously simple, indeed):
#!/usr/bin/env tclsh #-- ci.tcl -- a tiny C interpreter built on tcltcc package require critcl set f [open [lindex $argv 0]] set data [read $f] close $f critcl::ccode $data critcl::cproc main {char* argv} int {main(1,argv);} main [lindex $argv 1]
and a tiny C program source to test it with (ci_test.c):
/* demo program for ci.tcl */ #include <stdio.h> int main(int argc, char* argv) { printf("hello, %s\n", argv); return 0; }
which, when run, provides yet another solution for the classic K+R "hello, world" problem:
/Tcl/lib/tcc02> ci.tcl ci_test.c world hello, world