"Fossies" - the Fresh Open Source Software Archive

Member "jacl1.4.1/docs/TJC/index.html" (5 Aug 2006, 3990 Bytes) of package /linux/misc/jacl1.4.1.tar.gz:

Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. Alternatively you can here view or download the uninterpreted raw source code. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

TJC Compiler Manual

TJC is a Tcl to Java converter and compiler. TJC accepts Tcl source code and translates proc declarations to Java source code. Generated Java source is then compiled to Java bytecode. The TJC compiler supports two operational modes, batch mode and runtime mode.

Batch Mode:

In batch mode, a user invokes the tjc executable on the command line and passes a .tjc module file name. TJC scans a set of .tcl files looking for proc declarations and then converts the discovered Tcl procs to Java source code that implements the equivalent operations. Generated Java source code is compiled with javac, then both the generated source code and bytecode are stored in a JAR file.

tjc module.tjc ?module.tjc ...?

The TJC compiler loads JDK configuration information from a file named jdk.cfg. This JDK configuration file must be saved in the bin/ directory where tjc executable is installed. See JDK Config File for more info about the contents of a JDK config file.

Processing a module file generates a pair of JAR files. The first JAR file contains compiled Java class files and modified Tcl scripts. The second JAR file contains generated Java source code and unmodified Tcl scripts. For example, a module file xyz.tjc will generate xyzsrc.jar and xyz.jar. A TJC module file indicates which Tcl source files will be read and compiled by tjc. See Module File for more info about the contents of a module file.

A set of Tcl scripts and compiled proc implementations packaged inside a JAR file is known as a tjc package. A tjc package is loaded into Jacl by adding a generated JAR file to the CLASSPATH and then invoking the TJC::package Tcl command to load compiled commands into the shell. See TJC package manual for more info.

Runtime Mode:

The TJC compiler supports a runtime mode that makes it easy to define a Tcl proc in an interpreter and compile directly to Java bytecode. The TJC compiler runs in a second thread, waiting for compile requests from the TJC::compile command. When a Tcl proc has been compiled, the original proc is relaced with the compiled implementation. TJC makes use of the excellent Janino embedded Java compiler to convert generated Java source code to Java bytecode.

In most cases, runtime mode is easier to use since one need not create a module file or modify the CLASSPATH. Batch mode may be preferrable when a large number of Tcl procs need to be compiled, since compiling a lot of Tcl procs can take some time. Users should note that Jacl does not compile Tcl procs into Java bytecode by default, the user must explicitly indicate which procs should be compiled. See the TJC package manual for more info.

Additional Info:

See Simple Example for a step by step walk through of using the TJC executable and TJC package to compile and load a compiled Tcl proc.

See Generated Code Example for examples of Java source generated by the TJC compiler.

See Writing Optimal Code for some general Tcl optimization tips and preferred command usages.

See Future Improvements for a description of  features that could be implemented in a future release.