3 ms·
I may be the author.. enjoy! It was an absolute blast making this!
by xorvoid 8mo ago
I may be the author.. enjoy! It was an absolute blast making this!
- veltas 8mo agoThis is very nice. I'm currently writing a minimalist C compiler although my goal isn't fitting in a boot sector, it's more targeted at 8-bit systems with a lot more room than that. This is a great demonstration of how simple the bare bones of C are, which I think is one reason I and many others find it so appealing despite how Spartan it is. C really evolved from B which was a demake of Fortran, if Ken Thompson is to be trusted.
- JamesTRexx 8mo agoWould and how much would it shrink when if, while, and for were replaced by the simple goto routine? (after all, in assembly there is only jmp and no other fancy jump instruction (I assume) ). And PS, it's "chose your own adventure". :-) I love minimalism.
- SAI_Peregrinus 8mo agoWhat fancy jumps are present in assembly depends on the CPU architecture. But there are always conditional jumps, like JNZ that jumps if the Zero flag isn't set.
- direwolf20 8mo agoIt's "choose your own adventure"
- globalnode 8mo agothats the most important thing i noticed about the article, apart from the forth tokenising ideas.
- dzaima 8mo agoIt only does if & while, not for. A goto in a single-pass thing would need separate handling for forwards vs backwards jumps, which involves keeping track of data per name (in a form where you can tell when it's not yet set; whereas if/while data is freely held in recursion stack). And you'd still need to handle at least `if ( expr ) goto foo;` to do any conditionals at all.
- MobiusHorizons 8mo agoThe “fancy jump” is the branch instruction. As far as I know all ISAs have them. Even rv32i which is famously minimal has several branch instructions in addition to two forms of unconditional jump. Branches are typically used to construct if / for / while as well as && and || (because of short circuiting) and ternary (although some architectures may have special instructions for that that may or may not be faster than branches depending on the exact model). Without it you would have to use computed goto with a destination address computed without conditional execution using constant time techniques.
- einpoklum 8mo agoAn interesting use case - for the compiler as-is or for the essentiall idea of barely-C - might be in bootstrapping chains, i.e. starting from tiny platform-specific binaries one could verify the disassembly of, and gradually building more complex tools, interpreters, and compiler, so that eventually you get to something like a version of GCC and can then build an entire OS distribution. Examples: https://github.com/cosinusoidally/mishmashvm/ https://github.com/cosinusoidally/mishmashvm/ and https://github.com/cosinusoidally/tcc_bootstrap_alt/ https://github.com/cosinusoidally/tcc_bootstrap_alt/
- teo_zero 8mo agoIt would be interesting to understand what non-toy programs can be coded in this subset of C. For example, could tcc be rewritten in this dialect?
- tekknolagi 8mo agoYou may enjoy https://github.com/ludocode/onramp https://github.com/ludocode/onramp
- direwolf20 8mo agohttps://bootstrapping.miraheze.org/wiki/Main_Page https://bootstrapping.miraheze.org/wiki/Main_Page (Why does the referenced short story remind me of "There Is No Antimemetics Division"?)
- ahazred8ta 8mo agoRelated: the stage0/stage1 series of hex-to-c compiler bootstrapping tools https://github.com/oriansj/stage0?tab=readme-ov-file https://github.com/oriansj/stage0?tab=readme-ov-file and OTCC https://bellard.org/otcc/ https://bellard.org/otcc/