Tock

Tock (translator from occam to C from Kent) is a Haskell-based compiler for occam and related languages.

Current frontends:

occam2.1

Rain

Current backends:

C99 using the CCSP runtime

C++ using the C++CSP runtime

It's written in Haskell, making use of the Parsec parser combinator library and generic tree transformation passes. It aims to provide C-like performance for straightline code.

For more details on Tock, see the "Publications" section below.

Tock is currently experimental and under development; if you're after a stable occam-pi implementation then please see ​KRoC or ​the Transterpreter.

Getting Tock

The source code is currently managed using ​the Darcs distributed revision control system. You can browse it with a web browser here:

To download a copy of the source to play with, install Darcs, then do darcs get --partial http://offog.org/darcs/tock/ ; this will give you a tock directory containing the source code.

Compiling Tock

Tock itself needs GHC version 6.12 or later and Alex. If you're on Debian, then you can do the following to install all the packages required for Tock:

apt-get install ghc6 ghc6-prof \ libghc6-mtl-dev libghc6-hunit-dev libghc6-fgl-dev libghc6-quickcheck2-dev \ libghc6-haxml-dev libghc6-parsec-dev libghc6-regex-base-dev \ libghc6-regex-compat-dev \ alex haddock drift \ darcs gcc g++ autoconf automake pkg-config

haddock is only necessary if you want to build the documentation. libghc6-haxml-dev and drift are only necessary if you want to experiment with the XML AST.

Once you have the sources in a directory, you will need to execute these commands:

autoreconf -i ./configure make

You can also run the command make check to run the supplied unit tests.

Tock's C backend needs GCC 3 or later, and the latest Subversion version of the CCSP library from KRoC (which currently only supports IA32). Tock's C++ backend needs GCC 3, and C++CSP v2.0.2 or later.

Running Tock

To compile a program to a binary using Tock, use a command of the form:

/path/to/tock --output=testprog testprog.occ

For more exciting output, add the -v flag. The command ./tock --output=testcases/commstime-mini testcases/commstime-mini.occ will compile one of the testcases. By default, Tock uses the occam frontend and the C/CCSP backend. To change this, use --frontend=rain and/or --backend=cppcsp respectively. However, both the Rain frontend and C++CSP backend are currently unfinished.

Publications

The best overview of what we're doing is probably this paper, describing the overall structure of Tock, and our work on making Scrap Your Boilerplate and Uniplate fast enough for use in nanopasses:

Here are the slides Adam presented at Fun in the Afternoon that are a dramatically cut-down version of the paper above, just talking about our Uniplate work in context:

This paper describes some of the performance problems we had with SYB that lead to the work above:

This paper describes the pattern-matching system that we developed for use in Tock:

There's also the very first presentation Adam gave when he first started working on what later became Tock, which describes some of the sillier approaches he tried before finding something that worked:

Working on Tock

Tock is designed to make it straightforward to experiment with modifications to the compiler -- for example, adding new backends, or testing out new language features or optimisations. If you're interested in working on (or using) Tock yourself, then please join the tock-discuss mailing list:

You can use Darcs to work on and commit ("record") changes in your own copy, and then submit them to Adam when you're happy for them to be merged using darcs send . Provided your changes don't break Tock for other users, we're interested in getting them into the trunk as soon as possible so that they're available to everybody.

The code is documented inline using Haddock syntax; install Haddock and type make haddock to create HTML documentation in the doc directory.

Resources for people working on the Tock code:

Keeping Track of Tock Development

There is an RSS feed for the Tock repository that shows all "commits" to the repository:

There is also a Trac database used for tracking bugs/feature plans, etc. It is publicly viewable here:

And you can subscribe to a useful RSS feed for Trac at the foot of this page: