Re:SectorC: A C Compiler in 512 bytes
by vitiral on Wednesday May 24, 2023 @08:11PM
(#36065621)
Without structs? Good luck...
[ Parent
| on HN ]
Re:SectorC: A C Compiler in 512 bytes
by DesiLurker on Wednesday May 24, 2023 @08:14PM
(#36065639)
wonder how many extra bytes for structs?
In my experience, probably at least a 200-400 lines of C (another 512 bytes minimum? I don't know the conversion).
The problem is not just declaring structs but accessing them, referencing them, accessing/referencing fields and subfields, etc. That has to all be in the syntax. For such a minimal project you can ignore initialization.
I did all this while adding maybe 500 lines of C to GitHub.com/vitiral/fngi. Never tried for this level of minimalism though.
Once upon a time, when += was spelled =+, struct members in C were global names whose "values" were the offsets from the beginning of the struct[1]; a.b is simply a[ptrtab[b]] and a->b is a[0][ptrtab[b]].
[1]: This is why all of the names of struct members in unix are "needlessly" prefixed; i.e. struct stat.st_mode is not struct stat.mode because that could conflict with struct foo.mode until the early 1980s.
Re:SectorC: A C Compiler in 512 bytes
by DesiLurker on Friday May 26, 2023 @11:54AM
(#36085823)
Ah that explains it, I wondered about those old struct defs.
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.