![]() I chose to primarily write my compiler in OCaml. There’s no silver bullet: each compiler design inherently has its tradeoffs. Firstly, how fast is the compiled Bolt code? Secondly, how fast is the compiler (how long does it take to compile the Bolt code)? There’s a tradeoff - to get faster compiled code, you need to include more optimisation steps in your compiler, making the compiler slower. Tooling - does our language have libraries we can use for our compiler? There’s a balance between learning by doing and unnecessarily reinventing the wheel. Does our language help us keep track of this?ĭata representation - how do we represent and manipulate Bolt expressions in the compiler? I’m not hating on JavaScript (I use it in this very site), it just doesn’t suit our goal.Ĭoverage - we need to consider all possible Bolt expressions and make sure we handle all cases - it’s no good if our compiler crashes on Bolt programs we forgot to consider. But would I write a compiler in it? Frankly, no. JavaScript is a great language for web apps and easy to pick up for beginners. Choosing the correct language is like learning to touch-type: sure it will be slower to start with, but just think of how much faster you’ll be once you’ve got to grips with it! It might seem easier initially to write a compiler using a language you know, as it’s one less thing to learn, but this is only a short-term gain. “Write a compiler using language Y” (insert your favourite language) tutorials are a dime a dozen. ![]() ![]() If you’re reading this and you work on an industrial compiler for a more mature language, please reach out on Twitter! I’d love to hear about the design decisions you took! Use the right language for the job, not just the language you know best With Bolt, I’d like to highlight a larger compiler and the design decisions I’ve made. ![]() Writing a compiler is like any other software engineering project in that it involves a lot of key design decisions: what language do you use, how do you organise your files in the repo, which tools should you be using? Most compiler tutorials focus on a toy example and choose to ignore these practical concerns. Part 11: Adding Inheritance and Method Overriding to Our Language ![]()
0 Comments
Leave a Reply. |