A tiny hand crafted CPU emulator, C compiler, and Operating System
github.com
github.com
I love this sort of miniaturization in virtualization. In college, I did an independent study where I created a stack-based VM in C -- designed the ISA, wrote an assembler, etc. It wasn't very good, but I was able to write simple programs and run them. It felt like magic to me. I wrote a Sudoku solver in MIPS assembly [1] a while before that, and I wanted to port it over but I was missing some features. And now that's gone. #LikeTearsInRain
I haven't really revisited virtualization. Sad thing about my career is that I don't really get to spend half my time working on indendependent study.[2] All of my side projects tend to just be spurts of inspiration that fizzle out quickly.
Anyway, I'm gonna dig into this. It looks awesome!
[1] https://github.com/ndouglas/MIPS-Sudoku-Solver/blob/main/mip...
[2] "I've been in the private sector. They expect results." – Dr. Raymond Stantz
"c is the c compiler. It takes a single source file and creates an executable file or else executes the compiled code immediately. The compiler does not reach full standards compliance, so some programs need minor adjustment.
There is no preprocessor, although the #include keyword is allowed supporting a single level of file inclusion."
[1] https://github.com/rswier/swieros/blob/master/root/bin/c.c
This whole project just really makes me happy. I think it's because it's obviously a labor of love, it's very UNIX-y, yet at the same time, utterly comprehensible. I think this is a nicer environment for just general screwing around than a PDP-11 emulator running real V6. The core looks to be all here, without having to bear the weight of complexity implied by a real implementation.
10/10 will clone and study.
This C compiler, at ~2297 LOC (this number includes empty lines, actual LOC is less) -- is certainly worthy of being included in the group of small C compilers for study!
9.5/10 for me (could still be smaller and could still be better documented -- as could all other small OS'es/compilers -- so not a criticism -- a global group observation!)... but that being said, kudos to the author for what was no doubt a lot of hard work!
Well done!
Anyways, C4 is also very cool and focused on minimalism. Swieros's compiler seems much more extensive and even includes #define as the other comment mentioned and va_args.
[1] https://github.com/rswier/swieros/blob/master/root/bin/c.c