[Haskell-cafe] I want to write a compiler

Rick R rick.richardson at gmail.com
Sat Mar 7 18:45:04 EST 2009


Not sure if this is exactly what you want, but you could certainly fufill
all of your requirements using this as a baseline. Instead of evaluating the
actual statements in your eval function, you could simply render them to C.

As far as FFI, if you are statically compiling to C, you can leave your
variables unboxed. This would allow you to call C functions directly.

Hope that helps.

On Sat, Mar 7, 2009 at 6:32 PM, Loup Vaillant <loup.vaillant at gmail.com>wrote:

> This is a homework question. I am mainly looking for guidance or
> pointers. Source code, even. (Not GHC's, though, it is too complicated
> for me right now. The AST of STG is fine, but the rest kinda scares
> me.)
> Ideally, I would very much like to compile to C.
> The requirements are easily stated. My language must
> -> be lazy by default,
> -> support algebraic data types and case expressions (unless I can get
> away with encoding them as functions),
> -> have some kind of FFI with C (I suppose it imply some support for
> unboxed values).
> There is also the first class functions thing, but lambda lifting is okay.
> I don't care about any kind of execution efficiency. I just want my
> compiler to be As Simple As Possible. Eventually, I intend to
> bootstrap. Then, I will start dreaming about doing better than the
> Mighty Simons. (I can dream, right?)
> I figured I would start by the back-end. I began to write 15 pathetic
> lines of code to start an STG machine. Needles to say, I am stuck. I
> don't know where to start.
> I am already familiar with some papers. In particular, [1] (on
> template instantiation), [2] and [3]. I once wrote a simple graph
> reducer using template instantiation (about 20 lines at most).
> I have chosen the STG machine because I thought i would be easier to
> get an FFI and case exprs out of it. Maybe I am wrong, and template
> instantiation is really easier. There is also the BRISK machine, and
> GRIN. But the paper I read were less readable to me than the three
> mentioned.
> So, If any of you can give me some pointer or guidance or advice about
> where to start, I would be very grateful.
> Loup
> [1] http://www.cs.otago.ac.nz/cosc459/books/pjlester.pdf
> [2]
> http://research.microsoft.com/~simonpj/Papers/spineless-tagless-gmachine.ps.gz<http://research.microsoft.com/%7Esimonpj/Papers/spineless-tagless-gmachine.ps.gz>
> [3] http://research.microsoft.com/~simonpj/Papers/eval-apply/index.htm<http://research.microsoft.com/%7Esimonpj/Papers/eval-apply/index.htm>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

We can't solve problems by using the same kind of thinking we used when we
created them.
   - A. Einstein
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090307/e18026ee/attachment.htm

More information about the Haskell-Cafe mailing list