Live data from Hacker News

A minimal C compiler in x86 assembly

github.com

1–10 of 79 posts

Re: A minimal C compiler in x86 assembly

#2
"Minimal" being almost 5KLOC, sheesh. Actually, I'm surprised that a C compiler fits in that space.

Also:

---

Goal

This is a set of manually created hex programs in a Cthulhu Path to madness fashion. Which only have the goal of creating a bootstrapping path to a C compiler capable of compiling GCC, with only the explicit requirement of a single 1 KByte binary or less.

Re: A minimal C compiler in x86 assembly

#4
post #2

"Minimal" being almost 5KLOC, sheesh. Actually, I'm surprised that a C compiler fits in that space. Also: --- Goal This is a set of manually created hex programs in a Cthulhu Path to madness fashion. Which only have the goal of creating a bootstrapping path to a C compiler capable of compiling GCC, with only the explicit requirement of a single 1 KByte binary or less.

I would think that making a minimal forth or lisp would be the better path towards that goal, then use that to bootstrap a c compiler.

Re: A minimal C compiler in x86 assembly

#6
post #2

"Minimal" being almost 5KLOC, sheesh. Actually, I'm surprised that a C compiler fits in that space. Also: --- Goal This is a set of manually created hex programs in a Cthulhu Path to madness fashion. Which only have the goal of creating a bootstrapping path to a C compiler capable of compiling GCC, with only the explicit requirement of a single 1 KByte binary or less.

I would think that making a minimal forth or lisp would be the better path towards that goal, then use that to bootstrap a c compiler.

A recent comment from LWN on that note:

https://lwn.net/Articles/893608/

I asked about this on their IRC channel and got this response from oriansj:

Well we did bootstrap a FORTH from hex: https://github.com/oriansj/stage0/blob/master/stage2/forth.s

and we did bootstrap a garbage collecting Lisp from hex: https://github.com/oriansj/stage0/blob/master/stage2/lisp.s

but if you notice: https://github.com/oriansj/stage0/blob/master/stage2/cc_x86....

writing a C compiler in assembly that supports structs, unions, arrays, inline assembly and a bunch more was done in less than 24 hours by an inexperienced C programmer. Who then after started doing bootstrapping speed runs to demonstrate how trivial of a problem it is to implement that level of functionality in a C compiler.

In the decades for which Lisp and FORTH existed, why didn't they solve such a trivial problem?

Or better yet, now that you can see how it is done. Could anyone actually produce a C compiler with the same level of functionality in Lisp or FORTH in the same amount of time (or less?).

It is easy to talk a big game and words are cheap, we have the entire cc_* family of C compilers written in assembly for multiple architectures and in even cross-platform arrangements. If your language was any good at bootstrapping you'd be able to beat that. Then show your language written in less lines of assembly than cc_x86 to prove the point.

Please prove me wrong with working code.

Assembly and C have working code good enough to bootstrap GCC+Guile+Linux for more than a year now. https://github.com/fosslinux/live-bootstrap https://github.com/oriansj/stage0-posix

It is time for Lisp and FORTH to either deliver or learn to stop talking about something they never were good at in the first place and learn to admit Assembly and C won not because "worse is better" but because objectively they are better languages for bootstrapping new and better tools.

Re: A minimal C compiler in x86 assembly

#7
post #6

Earlier quoted context omitted.

I would think that making a minimal forth or lisp would be the better path towards that goal, then use that to bootstrap a c compiler.

A recent comment from LWN on that note: https://lwn.net/Articles/893608/ I asked about this on their IRC channel and got this response from oriansj: Well we did bootstrap a FORTH from hex: https://github.com/oriansj/stage0/blob/master/stage2/forth.s and we did bootstrap a garbage collecting Lisp from hex: https://github.com/oriansj/stage0/blob/master/stage2/lisp.s but if you notice: https://github.com/oriansj/stage0/…

I miss these technical provocative challenges. Nowadays, everyone tries to "not offend" people.

Re: A minimal C compiler in x86 assembly

#8
post #2

"Minimal" being almost 5KLOC, sheesh. Actually, I'm surprised that a C compiler fits in that space. Also: --- Goal This is a set of manually created hex programs in a Cthulhu Path to madness fashion. Which only have the goal of creating a bootstrapping path to a C compiler capable of compiling GCC, with only the explicit requirement of a single 1 KByte binary or less.

> "Minimal" being almost 5KLOC, sheesh.

5kloc of assembly code, which roughly correspond to opcodes. That's quite small.

It's actually 4399 loc, including blank lines and a significant number of comment lines.

Quite impressive.

There are JSON parsers that require way more code just to handle the basics of parsing.

Re: A minimal C compiler in x86 assembly

#9
post #6

Earlier quoted context omitted.

I would think that making a minimal forth or lisp would be the better path towards that goal, then use that to bootstrap a c compiler.

A recent comment from LWN on that note: https://lwn.net/Articles/893608/ I asked about this on their IRC channel and got this response from oriansj: Well we did bootstrap a FORTH from hex: https://github.com/oriansj/stage0/blob/master/stage2/forth.s and we did bootstrap a garbage collecting Lisp from hex: https://github.com/oriansj/stage0/blob/master/stage2/lisp.s but if you notice: https://github.com/oriansj/stage0/…

I mean there are Forths that fit inside a boot sector (Here’s a C minimal compiler in forth for the next stage: https://groups.google.com/g/comp.lang.forth/c/lBYFfVJ1qhc/m/...

Re: A minimal C compiler in x86 assembly

#10
post #6

Earlier quoted context omitted.

I would think that making a minimal forth or lisp would be the better path towards that goal, then use that to bootstrap a c compiler.

A recent comment from LWN on that note: https://lwn.net/Articles/893608/ I asked about this on their IRC channel and got this response from oriansj: Well we did bootstrap a FORTH from hex: https://github.com/oriansj/stage0/blob/master/stage2/forth.s and we did bootstrap a garbage collecting Lisp from hex: https://github.com/oriansj/stage0/blob/master/stage2/lisp.s but if you notice: https://github.com/oriansj/stage0/…

That an inexperienced C programmer wrote what appears to be 5000 lines of assembly in 24 hours implementing a fully working C compiler seems... a rather extraordinary claim. The file size of around 130K would indicate typing non-stop for 24 hours at something like 100 characters per minute.
Post reply on HN