Version 49 of Critcl builds C extensions on-the-fly

Updated 2004-05-30 12:19:41 by CMCc

Source code is now at http://www.equi4.com/critlib/ - JCW

  • Version 0.18 now runs on Linux and Windows (MinGW)
  • As of 0.22, you can store the binaries generated in a specific directory with a more meaningful name
  • source is now up to 0.28 (2001-Nov-21)

(See also Richard Suchenwirth's C code generators page.)


The C Runtime In Tcl is a self-contained package to build C code into an extension on the fly. It is somewhat inspired by Brian Ingerson's Inline for Perl, but Critcl is considerably more lightweight. [While Python also has an Inline [L1 ], it apparently has no direct genetic connection to Critcl.]

The idea is to wrap C code into something that will compile into a Tcl extension, and then also fire up the compiler. Compiled chunks will be cached in your ~/.critcl/ directory, so subsequent use will be instant.


Critcl Wiki Resources: Critcl FAQ

Critcl Discussion

Critcl Code

Critcl Examples


Using Critcl:

The main definition is "critcl::cproc", which lets you define a (surprise) C proc, with C code as body. Args and return values must be typed. There are no default args or ways to pass more sophisticated data items than int/long/float/double/char* for now.

There is also a "critcl::ccode" call, to inject C code as is, and a "ccommand" call, which ties code to the Tcl_CreateObjCommand without further wrapping.

The use of Tcl stubs, and the fact that this extension has all include files it needs to make compilation self-contained, means that this is a pure Tcl package, which should work with any (8.1 and up) installation of Tcl. Most importantly, Critcl does not care a bit where Tcl was installed, nor even whether it was built as a static or as a dynamic executable.

This is a working demo, but it is still young. It will for now blindly use "gcc" to do the compile and has somewhat rudimentary error handling. Critcl has been verified to work on Linux and Win NT4 (MinGW) so far.

Oh, one more thing: this code assumes the md5 command is available.

There's a new CritLib package with several extensions (blowfish, hexdump, ihash, lazy, lzrw1, md5c, mvector, noop, rchan, zlib) - see http://www.equi4.com/critlib/

More news on newer rev's of Critcl, or rather the "CritLib" where it is included:

  • There's a critcl::config to specify things like: outdir - putting all compiled extensions in a fixed dir, using a normal (non-MD5-ized name), and keepsrc - do not delete the generated intermediate C source code
  • There's a critbind script which takes one or more Critcl packages, and turns them into a single deliverable: either a loadable extension, or a static lib (for linking later), or an application. The latter is usually called a "custom tclsh", it can be built either as small main linked to Tcl dynamically, or as bigger exe with all of Tcl linked in statically

JCW


Critcl Articles: Sep 2002 - Conference paper by Steve Landers and Jean-Claude Wippler is now at [L2 ], with slides from JCW's presentation at [L3 ].

A dated article [L4 ] has background information on interpreted C.


AK: Larry Virden provided this pointer:

http://www.purl.org/NET/Tcl-FAQ/part4.html

 What: Embedded C (EC)
 Where: ftp://ftp.reed.edu/pub/users/greaber/ec-0.1.tar.gz 
 Description: Allows you to include C code in your Tcl scripts, compiling
        and dynamically loading it on the fly.  The code will also be
        cached so the next time you run the program, you don't wait for
        it to compile.  Known to work on DEC OSF/1 V3.2 and SunOS 5.5.
        Not yet ported to Macintosh or Windows.
 Updated: 09/1996
 Contact: mailto:[email protected]  (Grant Reaber)

[ Category Package | Category Critcl ]