Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Why intermediate representation?

Because you'd need not just one, but many of them, in order to keep things simple and manageable - for the philosophical background on this read about the Nanopass approach: http://www.cs.indiana.edu/~dyb/pubs/nano-jfp.pdf

> Build a straightforward AST then convert to LLVM.

It's only possible for the very low level languages without any interesting features.

Firstly, you'd need some type system, even if it's mostly dynamic. Secondly, your frontend may provide quite a bit of syntax sugar that will need further lowering before you can easily turn it into IR.

Even before typing, you'd have to handle the lexical scoping, which may also involve an additional intermediate representation (one distinct IR per each pass is normal).

With this approach you can keep your entire compiler pipeline as a sequence of trivial, fully declarative, pattern-based tree rewrites. With the less fine-grained approaches you'd end up with a barely maintainable mess, where multiple passes functionality is combined into a single bloated, twisted pass.

> Semantics is important.

Of course it's the only thing that is important. Unlike syntax.



> one distinct IR per each pass is normal

Source?


> Source?

1) Personal experience

2) The link I provided above (and all the other relevant Nanopass papers too)




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

Search: