itcl in Javascript Paper Chapter 2

How it started

When looking for a frontend/client for ATWF and Reporting Tools with Tcl I did spend some time checking all the available stuff. For a Tcl client it was easy there I decided to use a Tclkit/Starkit, but in a browser, the only existing possibility is the Tcl/Tk plugin, but there I knew that there were some problems and it was not much updated in the past.

So I was thinking about generating HTML code on the server side with Tcl. At that time I was also checking what of the existing javascript based libraries could be used especially jQuery and YUI. Both had a lot of interesting features. I also found Tcl in Javascript and was thinking about using that as an interface for making either jQuery or YUI functionality available with a Tcl wrapper.

When looking closer at that and playing with it I did like it a lot, but was soon missing Tcl functionality I wanted to use.

That was the start of the incr Tcl in Javascript project. At the beginning I was only adding some (from my point of view) functionality, which I was missing most.

The general idea already used/implemented by Stéphane Arnold was to have TclObjects (TclObj) implemented as javascript Objects (TclObject js Object), which hold a Tcl value that can be converted into the different types needed like:

  • string
  • integer
  • real
  • boolean
  • list

I have added to these types:

  • dict
  • stmt
  • word
  • syllable

The „dict“ type holds - as in the Tcl C-implementation - the internal representation of a Tcl dictionary.

I started with implementing namespaces. This was done by having a javascript Object TclNamespace js Object that did have properties for the relevant information and was used in a similar way as the TclNamespace struct in the C implementation. It contains references to the parent namespace and a list of the child namespace references. There was some basic implementation of a callframe available, I modified that to use a TclCallframe js Object, which had additional properties like the currently executed statement for introspection, the used namespace for that callframe etc.

For namespaces also the Tcl parser ( TclParser js Object) had to be extended to understand the namespace syntax for command and variable names.

The TclNamespace js Object was designed to allow different types of namespace:

For the itcl namespace types there was designed a resolve_commands reference for allowing implementation of namespace command resolvers.

This Object includes method for registering class commands and for registering subcommands, which is used for implementing namespace ensembles. A list of superclasses is provided here as well as entries for a class constructor and a class destructor.

Later on there was added support for namespace variables which are handled with a reimplementation in javascript of the equivalent C-functions lookupVariableEx, lookupSimpleVariable, GetNamespaceForQualName and FindNamespaceVar.

(Part of itcl in Javascript Paper)