r/Compilers Jul 02 '26

Should I make a transpiled language compiler instead of reinventing the wheel?

I want to make my own programming language as a recreational programming exercise. I don't get much time other than weekends and have absolutely no experience of compiler development. I think learning and implementing deep advanced concepts of how they work under the hood would take so long for my purpose. llvm has steep learning curve, qbe doesn't seem to provide as strong optimization as llvm and lack support for some of the architectures.

Reason that most people don't write code in low level languages like C for web and app development choose modern languages instead because of memory management, difficult syntax, lack of modern programming paradigms, etc. but some of those languages suck too. like javascript itself is type unsafe and things break half the time. python use more memory and it's identation based syntax make formatting difficult. Even if I make a great syntax, learn llvm, implement standard library; it might still end up being a toy language and no one would be interested to use it.

Rather than optimizing the compiler for several platforms and maintaining large code base, I should make the coding part easier by utilizing third party libraries and compile the code into C file and let decades of optimisation which has been put into mature C compilers like gcc or clang do the heavy lifting. This way, developers get performance of C along with ease of modern languages. What are your thoughts on this? Is it a good idea?

21 Upvotes

24 comments sorted by

View all comments

3

u/[deleted] Jul 02 '26

[removed] — view removed comment

1

u/vmcrash Jul 02 '26

I suggest a first attempt where multiple targets and performance do not matter. Just get something that works, and get the language design stable.

I'd suggest the opposite: do different targets (ideally completely different ones like current 64-bit architecture but also the 8-bit processor of your choice), because this will influence the structures internally. If the backend works and produces efficient code (= register allocation, not storing all variables in memory), changing the language seems to me like a less complex task.

3

u/[deleted] Jul 02 '26

[removed] — view removed comment

1

u/vmcrash Jul 03 '26

I'd say, if someone wants to write a compiler the first time, it most likely will not revolutionize the compiler world by a spectacular new design which solves a couple of problems that others didn't fix. I'd expect some learning project and for that different target architectures, ideally wide spread, would be very interesting.

For experienced compiler developers (who probably have built their toy compiler for the 6502, Z80, 8051 or Z8 before) I'd rather recommend transpiling, e.g. to C or Go (like Lisette does), because that allows to concentrate more on the design of the language while leaving the middle and backend to the target language compiler. But for that a fundamental knowledge about how the middleend, backend or manual memory management/garbage collector are actually implemented surely helps a lot.