For the past few weeks I've been working on a C compiler for Lua. It's now in a sufficient state to run non-trivial programs and benchmarks, although it's by no means finished. http://gate.cowlark.com/~dg/clue-0.1pre1.tar.bz2 (This will move to a real URL soon.) Clue uses Sparse to emit Lua 5.1.3 bytecode by emitting Lua source and running it through a modified version of luac to patch in goto instructions. Currently most ANSI C C89 programs and some C99 programs will compile, although there are big holes in the coverage (varargs, switch, for example). There's a libc, but I've only implemented enough to make the sample benchmark programs work. The code it generates isn't particularly great because I had to learn how sparse worked as I went along and needed to make stuff up more or less on the fly; the register allocator and code generator needs throwing away and rewriting, for example. This makes the benchmarks rather poor. But at least at this point they can only improve. It turns out that there's quite a lot of scope for improvement... Whetstone benchmark (gcc): 820 (clue with LuaJIT): 7.2 (clue with Lua): 3.6 It's all currently deeply experimental, buggy, half-finished and potentially useless, but I hope it's at least interesting. In addition, it should provide a reasonable example of how to write a compiler using sparse. -- ┌─── dg@cowlark.com ───── http://www.cowlark.com ───── │ "I have always wished for my computer to be as easy to use as my │ telephone; my wish has come true because I can no longer figure out │ how to use my telephone." --- Bjarne Stroustrup
Attachment:
signature.asc
Description: OpenPGP digital signature