Compilation to JavaScript
To make our λanguage more efficient, instead of evaluating (interpreting)
the AST we should transform it into a program in our target language
(JavaScript). Then we can run it with eval
or new
Function
(or load it with a <script>
tag) and I promise you
that the speed improvement will be dramatic. I've split this work in
three parts:
It might seem weird that I'm starting with what should be, intuitively, the “last phase” (code generation). I do that because it's fun and easy, and it will help us implement and debug the latter phases. We will only need minor modifications in the code generator after the latter stages.