Live data from Hacker News

SectorC: A C Compiler in 512 bytes

xorvoid.com

11–20 of 82 posts

Re: SectorC: A C Compiler in 512 bytes

#12
post #6
post #4

Earlier quoted context omitted.

Without structs? Good luck...

LFS already has several "stepping stones" where it walks through a whole set of C compilers from very old ones compiling slightly newer / more capable ones and so on. Perhaps with a few more "layers of compilers" on top you can get a very early GCC going.

>"Perhaps with a few more "layers of compilers" on top you can get a very early GCC going."

Applause. Best comment ;)

Re: SectorC: A C Compiler in 512 bytes

#13
post #2

This reminded me the idea of compilers bootstrapping ( https://news.ycombinator.com/item?id=35714194 ). That is, now you can code in SectorC some slightly more advanced version of C capable of compiling TCC ( https://bellard.org/tcc/ ), and then with TCC you can go forward to GCC and so on.

Did you read about the guix full source bootstrap the other day? They've shrunk the bootstrap seed down to a 357-byte program:

https://guix.gnu.org/blog/2023/the-full-source-bootstrap-bui...

Re: SectorC: A C Compiler in 512 bytes

#15
post #9

something like this could be interesting for deep-space applications where you only have a bare metal environment with hardened processor and limited memory & of course ping time of days (to earth). or alternatively for embedding a C compiler inside a LLM to use the LLM as a form of virtual machine.

A 512 byte memory restriction and deploying an LLM could not be on further opposite sides of the spectrum. :D

LLM currently have fairly tight token restrictions for prompting. That said chatGPT could probably compile some C. Never tried though.

Re: SectorC: A C Compiler in 512 bytes

#16
post #13
post #2

This reminded me the idea of compilers bootstrapping ( https://news.ycombinator.com/item?id=35714194 ). That is, now you can code in SectorC some slightly more advanced version of C capable of compiling TCC ( https://bellard.org/tcc/ ), and then with TCC you can go forward to GCC and so on.

Did you read about the guix full source bootstrap the other day? They've shrunk the bootstrap seed down to a 357-byte program: https://guix.gnu.org/blog/2023/the-full-source-bootstrap-bui...

The bootstrap seed, https://github.com/oriansj/bootstrap-seeds/blob/master/POSIX..., is a tiny interpreter that takes a much larger program written in a special-purpose, bytecode-based language. This proceeds in turn once or twice more--special purpose program generating another interpreter for another special-purpose language--until you end up with a minimal Scheme interpreter, which then can be used to execute a C compiler program.

All of this is incredible work, but a minimal C-subset compiler in under 512 bytes of x86 assembly seems like a unique achievement as it includes non-trivial parsing and linking phases not required for that hex0 interpreter.

Re: SectorC: A C Compiler in 512 bytes

#17
post #13
post #2

This reminded me the idea of compilers bootstrapping ( https://news.ycombinator.com/item?id=35714194 ). That is, now you can code in SectorC some slightly more advanced version of C capable of compiling TCC ( https://bellard.org/tcc/ ), and then with TCC you can go forward to GCC and so on.

Did you read about the guix full source bootstrap the other day? They've shrunk the bootstrap seed down to a 357-byte program: https://guix.gnu.org/blog/2023/the-full-source-bootstrap-bui...

From that article:

> Even more recently (2018), the GNU C Library glibc-2.28 adds Python as a build requirement

I’m surprised they went with Python and not GNU software (e.g. Guile).

Edit: clicking through the link it sounds like this might be intended to replace other accumulated dependencies (Perl?) and stop supporting old versions of Python.

Re: SectorC: A C Compiler in 512 bytes

#18
post #2

This reminded me the idea of compilers bootstrapping ( https://news.ycombinator.com/item?id=35714194 ). That is, now you can code in SectorC some slightly more advanced version of C capable of compiling TCC ( https://bellard.org/tcc/ ), and then with TCC you can go forward to GCC and so on.

The TCC step seems unnecessary. If you've got a SectorC C compiler sufficient to compile TCC, it can probably compile the bootstrap compiler used in GCC's 3 stage build process. The bigger issue is probably getting the ancillary tools up and running (a shell, make, coreutils, ...)

https://gcc.gnu.org/install/build.html

Re: SectorC: A C Compiler in 512 bytes

#19
post #2

This reminded me the idea of compilers bootstrapping ( https://news.ycombinator.com/item?id=35714194 ). That is, now you can code in SectorC some slightly more advanced version of C capable of compiling TCC ( https://bellard.org/tcc/ ), and then with TCC you can go forward to GCC and so on.

Perhaps my favorite thing in all of computing is the authors of Lisp bootstrapping by writing an (academic) interpreter for Lisp in Lisp, and then realizing they could just compile that by hand.
Post reply on HN