
Kaleidoscope: Implementing a Language with LLVM - rspivak
http://llvm.org/docs/tutorial/
======
hayd
It's also available as a PDF/mobi:
[https://www.gitbook.com/book/landersbenjamin/llvm-
implementi...](https://www.gitbook.com/book/landersbenjamin/llvm-implementing-
a-language/details)

------
tomcam
Lots of goodies here. Shows how to write a sort of Pythonic little language
with code generation for LLVM--and I love that it's from the LLVM krewe--but
doesn't skimp on things like an AST. It does rely on globals, sadly, but for
those of us who like compiler writing texts in plain language, it's a keeper.

------
amelius
Does it explain how to integrate a garbage collector? Because that is the most
difficult part of implementing a compiler nowadays, especially if it is a
concurrent one, which doesn't stop the world on each collection cycle.

~~~
drmeister
I've implemented Common Lisp using llvm (github.com/drmeister/clasp). I've
integrated the Boehm and Memory Pool system garbage collectors. How? It would
take a long time to explain - but it's doable.

~~~
hayd
Nice!

Have you benchmarked against Julia? Would be interesting how Clasp compares in
their micro perf tests:
[https://github.com/JuliaLang/julia/tree/master/test/perf/mic...](https://github.com/JuliaLang/julia/tree/master/test/perf/micro)

[http://scilua.org/](http://scilua.org/) was added in the tests recently and
does pretty well.

------
bru
Looks good, but... what's the version I'm to read? The first one or the second
one? They seem like different versions of the same document... Since the table
of contents is close to being the same it looks confusing.

Looks like the first one is in C++ and the second one in OCaml . Second one it
will be then :)

~~~
webkike
I'm pretty sure the second is C++... At least, I HOPE that is the case, as it
is more reflective of the core llvm libraries, not my language preference

------
lasryaric
Anything specific to know in order to implement the language VBA ?

~~~
webkike
Man, I can't wait to see the comments THIS gets

~~~
nickpsecurity
You ask. I deliver. :)

------
codeshaman
Apart from intellectual entertainment, why would anyone create another general
purpose language ? Isnt there more than enough choice already ?

I really want to, but I struggle to come up with enough features or syntactic
tricks to justify creating a new language.

What would your motivation be?

~~~
Rusky
Perhaps this isn't what you mean, but "isn't there more than enough choice
already" always comes across to me as "isn't there at least one language with
zero flaws for your use case?" I think the answer to that question is
definitely "no"\- this is why people write DSLs for niche use cases, but it
also applies to general purpose languages. If we had just stopped where we
were and were content with existing languages we'd be missing out on a lot of
useful features today.

------
Thiz
I haven't read the tut yet but… could I write a language like python with that
tutorial? If not, what would it be the best tutorial for indented syntax like
python?

~~~
qznc
There is a trick for parsing "indented" syntax which is not covered by this
tutorial: the lexer (not the parser) keeps track of indentation. Lexer inserts
Indent and Descent tokens, which the parser considers like { and } tokens in a
C syntax language.

Now your parser implements a context-free grammar although the language is not
context-free.

~~~
sklogic
There is even a better trick - ditch the lexer altogether.

~~~
qznc
Yes a lexer is primarily a performance optimisation. A good one though.

