4 ms·
Just for the lulz I'm writing a C compiler in Rust as a hobby, and it is humorously called "Small C Compiler", a call back to "Tiny C Compiler" because Rust is
by stevefan1999 2y ago
Just for the lulz I'm writing a C compiler in Rust as a hobby, and it is humorously called "Small C Compiler", a call back to "Tiny C Compiler" because Rust is obviously more heavyweight than C.
It uses Cranelift as a back end, but the whole compiler architecture is pluggable and hackable with lots of traits throwing around. I do not intend to open source it unless it works on a somewhat functional stage to be able to handle printf("%s", "Hello World!"), so until then, it will never see the light of day.
I've not been able to make too much progress, but I've tried to implement the preprocessor and parser, and I have been involved on rust-peg and HimeCC because of the infamous typedef problem. I know that in the industry we just use a symbol table to keep the typedef context, but that had a limitation of not able to read types below. I wonder what is the academic solution to that as well, and I can only think of transactional memory.
Anything that helps would eventually make me open source it!
- a_e_k 2y agoFWIW, (i.e., for some historical fun) Dr. Dobbs Journal published a program called "Small C Compiler" by Ron Cain back in 1980. [1] Later, it was expanded by James Hendrix into a full book with a more complete implementation. [2] (As a kid, coming across this book in the bargain bin at CompUSA was what led to me learning C. I still have my copy!) [1] https://archive.org/details/dr_dobbs_journal_vol_05_201803/page/n189/mode/2up https://archive.org/details/dr_dobbs_journal_vol_05_201803/p... [2] https://www.amazon.com/Small-Compiler-Language-Theory-Design/dp/0934375887 https://www.amazon.com/Small-Compiler-Language-Theory-Design...
- FullyFunctional 2y agoThat was my first introduction to C and I hacked a lot on that code. A very enjoyable time was had. My only regret with Rust is that a “Small Rust Compiler” will be an order of magnitude larger.
- dmvdoug 2y agoHope you name it not “SCC” but “SmaCC”.