[HN Gopher] A tiny hand crafted CPU emulator, C compiler, and Op...
___________________________________________________________________
A tiny hand crafted CPU emulator, C compiler, and Operating System
Author : seansh
Score : 143 points
Date : 2024-01-06 11:30 UTC (11 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| seansh wrote:
| There's a very interesting C interpreter/compiler there [1]. From
| the header:
|
| "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
| speps wrote:
| The parser actually supports #define and #undef as well.
| Paul-Craft wrote:
| You know what I find amusing about the C compiler? It's about
| the same size as the kernel in terms of LOC. I don't know why,
| but that amuses me.
|
| 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.
| peter_d_sherman wrote:
| Agreed!
|
| 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!
| blacksqr wrote:
| I haven't looked closely, but this appears to be the C4
| compiler (or an update to it), which has been around for a
| while and is worthy of attention in itself.
| seansh wrote:
| The C4 compiler is certainly fascinating and worth studying
| but don't believe that swieros's C compiler is based on that
| judging by their code [1][2]. There are similarities of
| course but well they are compiling the same language after
| all using some similar standard techniques like recursive
| descent parser [3].
|
| 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
|
| [2] https://github.com/rswier/c4/blob/master/c4.c
|
| [3] https://en.wikipedia.org/wiki/Recursive_descent_parser
| seansh wrote:
| Oh I completely missed the fact that they're both written
| by the same person.
| nathan_douglas wrote:
| Ooh, this is super cool!
|
| 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
| sitkack wrote:
| See also https://github.com/cksystemsteaching/selfie
___________________________________________________________________
(page generated 2024-01-06 23:00 UTC)