[Richard Suchenwirth] 2007-10-09 - tcltcc is a Tcl extension wrapping [tcc] (the tiny [C] compiler), which was modified by [MJ] so it: * can do file I/O via [VFS] * is loadable as a Tcl extension * uses Tcl's ck* memory allocation commands LGPL, download at http://code.google.com/p/tcltcc/ . Like [Odyce], it also comes with a [Critcl] emulation, so hopefully (at least some time in the future) people can just code against [Critcl] and run it with any of the three :^) For one example usage, see [ci - a tiny C interpreter]. [MJ] 2007-10-09 - Tclcc now also builds and works (passes the testsuite) on Linux ---- '''Simple API for building DLLs''' [RS] 2007-10-13: Since a couple of days, tcltcc can also build shared libraries (currently only DLLs for Windows, tested on [Windows 95]). Here's a cute and simple API for that: package require tcc set n [tcc::dll ?name?] Prepares the making of a DLL. Name is generated if not given, and in any case returned. $n ccode string Adds the string (which can be many lines) to the source buffer. Useful for #include directives, static internal functions, etc. $n cproc name argl rtype body Creates code to implement a Tcl command ''name'' with typed arguments ''argl'' of C return type, and appends that to the source buffer. ''rtype'' with the specified C ''body''. $n write ?-name str -dir path -code string? Produces the DLL $path/$name[[info sharedlibextension]] by compiling the source buffer, creating an Init function which registers the commands as specified by ''cproc'' calls, and optionally adding the initialization code in ''string''. Working example (from the test suite): test tcc-10.3 "new DLL interface" { set d [tcc::dll] $d ccode {static int fib(int n) {return n <= 2? 1 : fib(n-1) + fib(n-2);}} $d cproc fiboy {int n} int {return fib(n);} $d cproc hello {} char* {return "world";} $d write -name fiboy -code {Tcl_Eval(interp,"puts {hello Fiboy!}");} load fiboy[info sharedlibextension] list [fiboy 20] [hello] } {6765 world} For [introspection] and debugging, no cleanup takes place yet. You can see the generated code with set tcc::dll::${n}::code Ah, tcc is great fun... :^) - In the [Tcl chatroom], [Gerald Lester] asked for the converse functionality: wrap Tcl code into a C function that relieves the user of explicit [Tcl_Eval]. See [Tcl to C functions] ---- [Category Package]