3 ms·
Nice tiny little project, but the headline is a bit clickbait. I wouldn't really call it a C compiler, all it does is read a file, look for 3 or 4 hardcoded str
by Galanwe 10y ago
Nice tiny little project, but the headline is a bit clickbait.
I wouldn't really call it a C compiler, all it does is read a file, look for 3 or 4 hardcoded strings like "int" or "char*" or "return" and generate some really simple labels/movs in consequence.
- userbinator 10y agoNo kidding, it's barely got a parser. C4[1] on the other hand, is still tiny enough to comprehend, does have a pretty complete parser, and probably wouldn't be too difficult to modify to generate code for this VM. [1] https://news.ycombinator.com/item?id=8558822 https://news.ycombinator.com/item?id=8558822
- taneq 10y agoWow, calling yourself "C in 4 functions" when those functions are effectively minimized and with not a whole bunch of whitespace is a bit cheeky. Might as well strip out all but four newlines and call it "C in 4 lines". :P Still looks well worth a read, though.
- vidarh 10y agoThey're not minimized. They use slightly short variable names, but there's few of them and they make sense very quickly. It does use a few unnecessarily clever tricks, like the opcode selection as indexes into a string, but other than that, as is pointed out in that thread: if you've read a Wirth-style compiler before (or Wirths books on compile construction, which will have you read a Wirth-style compiler...) it becomes fairly simple to understand.