r/ProgrammingLanguages • u/someOfThisStuff • Jun 07 '26
Steps to a self-hosted compiler?
After having programmed in C for a while, I have finally decided to create my own language, very similar to it, in an attempt to fix it for my personal use.
It is my belief that, with some relatively minor tweaks and changes, C could be transformed into a language I am prepared to sink much time programming for. All of this, of course, is my own opinion; though if you are curious, here is a copy of the current draft for the standard: https://pastebin.com/eq1v7K9t
With the goal being to have a completely self-hosted transpiler (so, written in the language itself), I've been wondering how people usually go about this: do they write a sketchy, barely-working patchwork just to get the language "alive", and then code the true compiler? Or is it more common to do things well the first time, even if it means slower progress?
View all comments
Show parent comment
7
u/Ephemara Jun 07 '26 edited Jun 07 '26
THIS RIGHT HERE. It is insanely easy to want to go on the self hosted path, however from someone who wasted so much time chasing the self hosted dragon - you want to first solidify your bootstrap and see out the vision of why the language was made in the first place. Furthermore not self hosting is also a viable option as well, and honestly makes for rapid iteration and to see if the vision itself garners attention (if that’s your goal). Swift isn’t self hosted, python isn’t etc - there’s also other paths as well like the fusion host, where you build C interop so good in your original bootstrap, that you just start embedding your language into its own bootstrap or the real metal path - the reverse bootstrap. In your bootstrap, create a c importer and simply swallow your bootstrap // translate your language into its own. This would require LLVM codegen however in your bootstrap or some other way to compile it down to an executable.
But if you do decide to go down the rabbit hole. The ultimate goal is, once you write the compiler out in the language itself, you then compile the compiler and compile the compiler once again and close the loop. And if your code is 1:1 from the bootstrap compiler all the way to the compiled compiled compiler, you are now self hosting