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
3
u/someOfThisStuff Jun 08 '26
Huh, I didn't know python and swift weren't self-hosted, I imagined large languages like this all were. My language targets C (specifically GNU11) so any output is readily compilable to pretty much everything. As it is, the brunt of the work of making my compiler is all the error checking and type coherency, as there will be no optimization passes (that's GCC's problem).
I like to think that while the languages themselves are not translatable 1:1, the concepts expressed in them are. Because of this, I'm not afraid of performance loss during transcompilation, as any decent C optimizer should be able to produce the same (or equivalent) assembly.