[tcljava-dev] A new Tcl to Java compiler for Xmas
Brought to you by:
mdejong
From: Mo D. <md...@un...> - 2005-12-21 19:45:01
|
Ho Ho Ho! Tis the season for giving and because Jacl users have been very good this year, the gift of a shiny new compiler is now available via the tcljava CVS. The compiler is named TJC, which stands for Tcl to Java Compiler. The TJC compiler accepts Tcl source code as input and compiles Tcl procs into executable Java code stored in a Jar file. The compiler is accessed via a startup script named tjc. The TJC compiler is ready for evaluation by early adopters looking for significant performance improvements for Jacl scripts. Currently, scripts can be compiled ahead of time but there is no support for compilation of Tcl procs at runtime. A simple example showing how to use the TJC compiler is appended to this email. Many thanks got to AMD, New Iron Systems, and One Moon Scientific for funding this project. cheers Mo DeJong SIMPLE TJC EXAMPLE: In the following example, a TJC module containing a single Tcl script file and a single compiled proc will be created and loaded into the Jacl shell. This example makes use of the tjc executable and the TJC::package command. In this example, the Tcl source file used as input to the TJC compiler is defined as follows: $ cat simple.tcl proc simple {} { return "SIMPLE" } The user will now need to create a TJC module file for the TJC package. The name of the module file will be simple.tjc. The name of the Java package will also be "simple", this is the same package name that will later be passed to the TJC::package command. The SOURCE and INIT_SOURCE declarations will list only the simple.tcl file. $ cat simple.tjc PACKAGE simple SOURCE simple.tcl INIT_SOURCE simple.tcl OPTIONS Assuming that the tjc executable is already on the PATH, the TJC compiler is invoke via: $ tjc simple.tjc If no error is generated, then nothing is printed and the files simple.jar and simplesrc.jar are created in the current directory. Note that simple.jar contains both the compiled version of the proc simple and the script simple.tcl. This TJC package can be loaded into a Jacl shell by adding simple.jar to the CLASSPATH and invoking Jacl. $ export CLASSPATH=${CLASSPATH}:`pwd`/simple.jar $ java tcl.lang.Shell At the Jacl shell prompt the following Tcl commands would be entered to load the TJC package and init the simple package. % package require TJC 1.0 % TJC::package simple % simple SIMPLE The example above shows how a compiled version of the Tcl proc named "simple" is loaded into the Jacl shell and executed. The results returned by the compiled "simple" command are the same as would be returned by the Tcl version of the command. |