34 comments

[ 2.6 ms ] story [ 41.8 ms ] thread
The way hashing is used for tokens and for making a pseudo symbol table is such an elegant idea.
I actually "shipped" a parser using the symbols' hash(as the only identifier) for a test tool once. Hopefully, the users never used enough symbols to collide 32-bits.
I've had the idea before. Was never quite brave enough to do it. It's elegant until it isn't....
I may be the author.. enjoy! It was an absolute blast making this!
> I wrote a fairly straight-forward and minimalist lexer and it took >150 lines of C code

was it supposed to be "<150"?

Oh, it looks like my X86-16 boot sector C compiler that I made recently [1]. Writing boot sector games has a nostalgic magic to it, when programming was actually fun and showed off your skills. It's a shame that the AI era has terribly devalued these projects.

[1] https://github.com/Mati365/ts-c-compiler

> when programming was actually fun and showed off your skills

Oh no. Now more people are able to do what I do. I'm not special anymore.

Er, what? The article describes a compiler for a not-quite-C programming language which fits entirely in 512B. Your project, if I see this correctly, can optionally produce code meant to execute as boot sector.

Both interesting projects, but other than the words 'boot sector', 'C' and 'compiler', I don't see a similarity.

Compare that to the C compiler in 100,000 lines written by Claude in two weeks for $20,000 (I think was posted on HN just yesterday)
Lacking support for structs, I think this is too minimalistic to be called "a C compiler".
Weren't structs a fairly late addition to C?

And anyway, isn't that kind of missing the point. 512 bytes isn't much. Your comment is nearly a 5th of that budget.

If this implementation had existed in the 1980s, the C standard would have a rule that different tokens hashing to the same 16-bit value invoke undefined behavior, and optimizing compilers in the 2000s would simply optimize such tokens away to a no-op. ;)
"you don't have -wTokenHashCollision enabled! it's your own foolish ignorance that triggered UB; the spec is perfectly clear!"
C-subset, to be precise; but microcomputer C compilers were in the tens of KB range, for one that can actually compile real C.
There seems to be a good amount of interest for a boot sector compiler!!

If you're running on Linux, adjust the qemu call to use alsa rather than coreaudio.

I generated a pull request for this on Github. If the author is happy enough with my verbose shell scripting style :-) it might get included.

Nice, now you can dd it to your boot sector and ... Wait, it is 2026, there are 1000 ways of booting and memory mapping on so-called unified ARM architecture @,@
For me is not interesting because it fits in 512 bytes, it's interesting because it's very simple. I think it would be a great introduction to learning about compilers.
> Big Insight #2 is that atoi() behaves as a (bad) hash function on ordinary text. It consumes characters and updates a 16-bit integer.

I could have sworn I remembered atoi() being defined to return 0 for invalid input (i.e. text not representing an integer in base ten).

This is the kind of project that reminds you how far removed modern development is from the actual machine. We pile abstractions on abstractions until "Hello World" needs 200MB of node_modules, and then someone fits a C compiler in 512 bytes.

Not saying we should all write boot sector code, but reading through projects like this is genuinely humbling. Great educational resource too.

(comment deleted)
Great read. It would be neat to see a mini operating system under 1 kb of code.
This is really beautiful (I feel like this sort of project is outsider art), thank you for sharing.
Brilliant! I love the stealing of Forth ideas to power this. Forth’s minimalism is highly underrated.