Live data from Hacker News

A minimal C compiler in x86 assembly

github.com

11–20 of 79 posts

Re: A minimal C compiler in x86 assembly

#11
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/…

The link is broken.

Re: A minimal C compiler in x86 assembly

#12
post #11
post #6

Earlier quoted context omitted.

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/…

The link is broken.

Fixed, thanks.

Re: A minimal C compiler in x86 assembly

#13
post #6

Earlier quoted context omitted.

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.

Maybe GitHub Copilot is that good already.

Re: A minimal C compiler in x86 assembly

#15
post #6

Earlier quoted context omitted.

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.

I think they are talking about the later stages of boot strapping 'stage2' where they are writing a more functional, but still small, C compiler in a C subset that can be compiled by this one

Re: A minimal C compiler in x86 assembly

#16
post #6

Earlier quoted context omitted.

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.

> typing non-stop for 24 hours at something like 100 characters per minute

Not only that. It would be typing at that speed without testing anything. In assembly. Haha. In reality what would happen is that you would type 24 hours (not in one day, I assume) and then spend the next days finding the places where you wrote R5 instead of R4.

And, of course, without losing any time on refactoring already written code (changing order of parameters, finding a better name for a function, etc.)

Re: A minimal C compiler in x86 assembly

#17
While everyone asks about lisp or forth for this task, I have to wonder what one has to leave out of C to make it "minimal" enough for this task. The subset of features left out might teach us something about the language.

Re: A minimal C compiler in x86 assembly

#18
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/…

> 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.

That’s a weird commit comment (“Implemented C version of cc_knight-native”) for a commit that adds a C compiler.

Also, how do you conclude from that that it took less than 24 hours to write that commit (or any)?

Re: A minimal C compiler in x86 assembly

#19
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.

5kloc isn't really all that much code, especially in assembly.

Re: A minimal C compiler in x86 assembly

#20

I'm surprised they wrote a minimal C compiler in assembly rather than any LISP dialects, then make a C compiler in LISP

> I'm surprised they wrote a minimal C compiler in assembly rather than any LISP dialects, then make a C compiler in LISP

I recommend you check out the author's GitHub page. It includes Forth and Lisp projects, explains why C was a success while those projects failed, and challenges any Forth and Lisp fan to actually substantiate their baseless claims with actual work instead of pushing beliefs that don't have any bearing on reality.

Post reply on HN