The Tiny C Compiler
http://fabrice.bellard.free.fr/tcc
Features (from the tcc homepage)
[Larry Smith] Compress it with upx [http://upx.sourceforge.net/] and it drops to 56K. =)
Reinhard Max has tried to Compile Tcl with tcc on SuSE Linux.
LGPL.
CMcC has written a tcc tcl extension - generate dlls and even dynamically compile C into memory.
[Of possible interest to the same readers is this [L1 ] small compiler.]
LES: Are you sure it's for i386 only? What about this? [L2 ]
SDCC can generate code only for Intel 8051, Maxim 80DS390 and Zilog Z80, with Motorola 68HC08 and Microchip PIC16 and PIC18 in the works. Tcl runs on none of these, AFAIK.
See also: Small is beautiful
October 27, 2004 [email protected]
I have a working version for windows, and have written a couple examples using Tcl C API's...Works pretty good... Still needs some work....
CMcC - Excellent. The latest version is supposed to work for windows too, the big question is: can your version create .dll files?
No, what you get is a compiled memory resident code. I use it mainly to quickly test new 'C' code segments or just needed a quick fast function call to perform something (math routine)...
I've compiled the tcc into a DLL and load it into tcl, then load/unload my 'C' scripts...I have put in hooks to call the tcl API so I can create new commands...The main difference is that you use the "main" function the same as the "init" call to initialize the code...
example 'C' script: // sample script to test // performs MD5 checksum on file // this is a local modified tcl header file #include "tcl.h"
typedef unsigned char *POINTER; typedef unsigned short int UINT2; typedef unsigned long int UINT4;
#define _O_TEXT 0x4000 /* file mode is text (translated) */ #define _O_BINARY 0x8000 /* file mode is binary (untranslated) */
unsigned char PADDING64;
..........cut bulk of the code out...................................
// tcl command to envoke static int md5_test(ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv ) {
MD5_CTX context; unsigned char digest[16]; unsigned char buffer[1024]; char tmp[33]; int x = 0; int len = 0; int fp; PADDING[0] = 0x80; for (x = 1; x < 64; ++x) { PADDING[x] = 0; } char buf[256]; if (objc != 2) { Tcl_SetResult(interp,"must provide a file name...", TCL_STATIC); return TCL_ERROR; } fp = _open(objv[1], _O_BINARY); if (fp < 0) { Tcl_SetResult(interp,"Unable to open file...", TCL_STATIC); return TCL_ERROR; } MD5Init (&context); while (len = _read (fp, buffer, 1024)) MD5Update (&context, buffer, len); MD5Final (digest, &context); _close (fp); strcpy(buf, ""); // compile MD5 cksum for (x = 0; x < 16 ; ++x) { sprintf (tmp, "%02x", digest[x]); strcat(buf, tmp); } Tcl_SetResult(interp,buf,TCL_STATIC); return TCL_OK;
}
// main - create tcl commands here int main() {
Tcl_Interp* interp; // get interp from main global interp = (Tcl_Interp*) getInterp(); Tcl_CreateCommand(interp,"md5",(Tcl_CmdProc *)md5_test,(ClientData)NULL,(Tcl_CmdDeleteProc *)NULL); return TCL_OK;
}