Hacker News new | past | comments | ask | show | jobs | submit login
A compiler for Crisp, a Lisp-inspired language, in Haskell with LLVM (github.com/talw)
61 points by yosy on March 31, 2015 | hide | past | favorite | 2 comments



The LLVM project has a tutorial for building an expression language[0]. The tutorial was ported to Haskell by Stephen Diehl[1]. The person who built Crisp is also following that tutorial (I recognize snippets).

I can recommend anyone interested in building a language to try this tutorial, either the original one or the Haskell one. It's easy to follow, and you can just copy and paste as you go along and in the end you will have not just your own little toy language that you fully understand and can modify to your liking, but one that actually is compiled with a world-class optimizer, getting you sweet performance.

I am currently attempting the build a C compiler in Haskell with the tutorial as a basis. (It's nowhere near even compiling Hello World, which requires more C features than you'd think ;), so I won't link it)

    [0] http://llvm.org/docs/tutorial/
    [1] http://www.stephendiehl.com/llvm/


Indeed, I have used Stephen Diel's excellent tutorial as a starting point to get off the ground by taking snippets as they are, albeit with slight modifications. Stephen's wrapper of the LLVM bindings to create an LLVM DSL in Haskell is wonderful. Although the more interesting aspects (at least for me) such as lambdas/closures and data structures such as lists or arrays, are not covered in that tutorial, it's actually for the better as it gives you enough of a push in the beginning for working with LLVM, without overwhelming you.

Overall, it has been an enjoyable and educational (Haskell/compilers/dynamic languages/Scheme/LLVM - wise) experience. Quite noticably, my troubleshooting time was largely spent fixing compiling errors, with only a fraction of the time, relatively speaking, spent fixing runtime errors. Adding new features (barring those that necessitated making an overhaul to the design itself, as it emerged without much foreplanning) was a breeze.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: