r/ProgrammingLanguages • • 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?

11 Upvotes

23 comments sorted by

View all comments

Show parent comment

1

u/someOfThisStuff Jun 08 '26

Hi, thanks for reading through xD.

Regarding lace files: I've always liked headers and the way they provide an "API" for external linkage. What appears in the lace is what's shared with the rest of the world, while the source file contains the implementation. This way, I hope to also include documentation in the lace file so that it is what is consulted when working with libraries and the likes.

For the $ symbol: 'inner' functions are actually simply scope-limited, and in C are unraveled to global scope. Accessing outer functions actually passes them through a function call, so this is to remind you of that fact. To be honest inner functions is something I struggled with in design, as in C I often use the preprocessor to handle simple, repeated computation, but the CPP is clunky and LAC does not have a quick-and-cheap equivalent. I'm all ears for suggestions though.

And for break, continue, etc.: I've been told this a few times. I don't know why, but I have a dislike for named loops like this. I convince myself by saying that this way, it will force me to not write spaghetti logic, and instead only use the multi break / continue when it is a good choice. Although, of nothing is set in stone of course.

1

u/koflerdavid Jun 13 '26

I've always liked headers and the way they provide an "API" for external linkage. What appears in the lace is what's shared with the rest of the world, while the source file contains the implementation. This way, I hope to also include documentation in the lace file so that it is what is consulted when working with libraries and the likes.

You can have all of these things without header files. They just complicate everything. For example, they have to be reparsed for every source file that includes them, which led people to come up with precompiled header files. Instead you can make the compiler emit the interface in a machine-readable format, which can serve as input for other compiler calls, linker, IDEs, and documentation processors.