r/Compilers • u/yuehuang • Jul 08 '26
My Compiler Journey (now public)
tl;dr; Publicly showing CFlat (MIT lic.), a C extended programming language and compiler. Release for Windows with MacOS coming soon. Github
I started this project a year ago as a learning the in-and-out of compiler, but the projects just grew and grew. With Claude speeding up development and also feature creep. Here is a short list of my features;
- The "program" type, it is a fully contained type with a single-entry point and its own memory management. Crashes will just crash the app, and the memory management will clean up the heap. No GC and ref counting needed. A neat bonus is
import program "hello.c" as Hello;, thus converting a c program into an embedded program. - Grammar based Templates. The compiler uses two passes, both are 100% antlr4 grammar. No complex look ahead logic, but I did break one small feature from C, comment if you could find it.
- "vectorize" keyword used in loops
vectorize for (int i = 0; i < n; i++)will error out if the loop fails to vectorize. The feature stamps in the debug symbols and validates after optimization pass. No more guessing. See HPC section for other features.
Let me know if you have questions, I will try to answer as much as I could.
22
Upvotes
4
u/JeffD000 Jul 09 '26 edited Jul 09 '26
At first glance, this is really cool. I will have to stare at the sources for a while before I am willing to compile it on my machine, because I am very security conscious.
Is LLVM the only back end? You say the language is self contained, that it links native executables without an external toolchain, but the LLVM back end seems to contradict that. What am I missing?
3
u/Inconstant_Moo Jul 09 '26
Wouldn't Cā just be B, though?
2
u/JeffD000 Jul 09 '26
I'm assuming the feature you broke is the comma operator between expressions?
1
u/JeffD000 Jul 10 '26 edited Jul 10 '26
This is a really cool project on many levels. Thanks for sharing. I gave your project a star on github, because it was well deserved. Even the documentation goes above and beyond expectations.
To other people here, I really recommend you take a look. Just the libraries in the cflat/core directory make it worth the look. This should be a canonical example of how a small-compiler release can exceed expectations.
1
u/JeffD000 Jul 18 '26 edited Jul 18 '26
How deeply do you keep track of literal constants? The reason I ask is because I would like to pass a literal constant argument to a "top level" function, and then have it still be treated as a literal constant through four levels of function call below that "top level" function, so that in that lowest level, I can use the "if const" construct on the propagated argument value. I am OK with the assumption that all functions in the function call chain would need to be defined in the same source code file.
In some sense, this is a function specialization mechanism used when it is found that an argument passed to a function call is a literal constant. This could create a combinatoric mess within the compiler's front-end data structures, but the compiler will do dead code elimination as a final step of the front-end, pruning all the unused specialization paths before code generation.
0
u/antonation Jul 08 '26
I have also used Claude to speed up my own development, what difficulties or things did you find when using Claude to co-develop? What was your prompting like?
2
u/[deleted] Jul 09 '26
[removed] ā view removed comment