[Haskell-cafe] I want to write a compiler

Loup Vaillant loup.vaillant at gmail.com
Sun Mar 8 18:41:19 EDT 2009

Thanks to the courage you all gave me, I found the strength to go on.

Template instantiation seems to be the easiest path, so I decided to
follow it. I think I solved the problem about primitives and FFI I
though it had. Namely, how the hell do I compile primitive calls with
an arbitrary number of arguments.

Starting from the Tutorial of Peyton Jones and Lester, I added a new
node type to help guide the order of evaluation. Basically, this "Seq"
node takes the address of two other nodes. It pushes them both on the
stack, like an application node would. (That is because I don't want a
dump, but I could as well create a new stack and and push the previous
one on the dump.)

Note the nodes which are evaluated this way must not have a functional
head normal form (primitive or supercombinator). That would leak past
the beginning of the stack.

When the node is finally evaluated (e.g. points to a HNF, like a boxed
integer), the topmost and second topmost pointers on the stack are
swapped. (or the topmost pointer of the stack and the topmost pointer
of the topmost stack on the dump are swapped).

With a suitable compilation scheme, that should guarantee that
primitives have their arguments already evaluated. (And avoid infinite

Now, I just have to implement it. :-)


More information about the Haskell-Cafe mailing list