Clue 0.5

An ANSI C compiler targeting high level languages.
Clue is an ANSI C compiler targeting high level languages.

What?

Clue is an ANSI C compiler (C89, some C99) that targets high-level languages such as Lua, Javascript or Perl. It supports the entire C language, including pointer arithmetic, and can be used to run arbitrary pure-C programs.

Clue currently supports the following targets:

 * Lua 5.1.3
 * Javascript
 * Perl 5

Why?

What do you mean, 'why'?

Apart from pure hack value (I'm hoping at some point to produce a back end that will emit sh script --- just because), Clue is mainly an experiment into the use of dynamic VMs to run static code. Modern JITs can do an astonishing job of producing machine code from dynamic languages, gathering all the necessary type information just from watching the program run. It therefore seems instructive to try taking a statically typed language like C, discarding all the type information, and letting the JIT have a go.

In terms of actual practical value, it may be useful to allow the use of code written for one system to run on another, much more restricted system. For example, using clue you could use off-the-shelf encryption systems like gpg to work inside a web browser.

How well does it work? Well, let's have some numbers. (All these were calculated during a single benchmarking run on my machine. The gcc score is included for reference. The gcc version of the benchmark uses the same source code as the Clue versions.)

Backend Interpreter Whetstone score
(gcc) 760
lua LuaJIT 1.1.4 140
lua Lua 5.1.3 33
js SpiderMonkey 1.8.1.13 10
js Rhino 1.6 9.0
perl5 Perl 5 1.7

Yes, code compiled through Clue, run on Mike Pall's LuaJIT, really does run at about a fifth the speed of native! Unfortunately, the Javascript versions seem to be much slower. When I manage to get hold of Tamarin, I'll give that a try. And to nobody's great surprise, Perl does not win any speed awards.

How?

Clue is based on the sparse C compiler frontend. This is plugged into a custom register allocator and code generator, which emits the code.

sparse and Clue are written in gcc-dialect C. It should run on most systems, although it has been developed on Linux, and makes fairly major assumptions about living in a Unix environment --- Windows users will want to use Cygwin and even then you're on your own.

Documentation is provided; currently it's a bit patchy, but reasonably complete. If you have any problems, please join the mailing list.

Why not?


Clue is experimental software. It's sole purpose is to be interesting, and not necessarily useful. The resulting code takes between 10 and 100 times longer to run as it would if you just compiled the program with gcc (and that's when using the Lua backend with LuaJIT, possibly the fastest dynamic language around; any other target will be slower).

In addition, while Clue supports the ANSI standard, most programmers don't; non-ANSI behaviour such as casting a pointer to an integer and vice versa is very common. This will not work. So stock code is unlikely to run on Clue unless the authors have been particularly disciplined. (However, this can also be seen as an advantage: if your code works with gcc and with Clue, it's probably going to work elsewhere.)

And I haven't even mentioned the bugs.

last updated on:
December 15th, 2008, 12:16 GMT
price:
FREE!
homepage:
cluecc.sourceforge.net
license type:
BSD License 
developed by:
David Given
category:
ROOT \ Programming \ Compilers
Clue
Download Button

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Rate it!
What's New in This Release:
  • This version includes a Java backend.
read full changelog

918 DOWNLOADS

Add your review!

SUBMIT