News for hackers. Stuff that matters.
Re:A minimal C compiler in x86 assembly by adastra22 on Tuesday May 03, 2022 @12:44AM (#31244723)
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 by pabs3 on Tuesday May 03, 2022 @12:48AM (#31244753)
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 by mypalmike on Tuesday May 03, 2022 @01:19AM (#31244930)
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.
Re:A minimal C compiler in x86 assembly by tralarpa on Tuesday May 03, 2022 @02:36AM (#31245374)
> 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 by rscho on Tuesday May 03, 2022 @04:53AM (#31246147)
Inexperienced C programmer probably doesn't mean inexperienced ASM programmer in this particular case.
Re:A minimal C compiler in x86 assembly by kragen on Tuesday May 03, 2022 @08:03AM (#31247277)
People normally touch-type between 300 and 800 characters per minute (50–130 wpm), so even if all of that was typed by hand we're only talking about five hours or so of typing, but you've forgotten about copy and paste.
Re:A minimal C compiler in x86 assembly by a9h74j on Tuesday May 03, 2022 @01:59AM (#31245162)
Maybe GitHub Copilot is that good already.
Re:A minimal C compiler in x86 assembly by Taniwha on Tuesday May 03, 2022 @02:33AM (#31245360)
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 by adastra22 on Tuesday May 03, 2022 @01:06AM (#31244857)
I mean there are Forths that fit inside a boot sector (<512 bytes). My reading of the goal was a minimal kernel of code from which the larger system can be bootstrapped.

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 by Someone on Tuesday May 03, 2022 @02:46AM (#31245428)
> 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 by arinlen on Tuesday May 03, 2022 @03:19AM (#31245628)
> That’s a weird commit comment (“Implemented C version of cc_knight-native”) for a commit that adds a C compiler.

I read that as "implement a C version of a C compiler for Knight's Landing processors". I might be reading too much into it, though.

Re:A minimal C compiler in x86 assembly by kragen on Tuesday May 03, 2022 @08:04AM (#31247281)
Apparently it's an offbeat minicomputer from the late 01970s made by a defunct company called Knight.
Re:A minimal C compiler in x86 assembly by pabs3 on Tuesday May 03, 2022 @11:49PM (#31256530)
That wasn't my conclusion, I just pasted what the author of the code said.
Re:A minimal C compiler in x86 assembly by ducktective on Tuesday May 03, 2022 @12:53AM (#31244781)
I miss these technical provocative challenges. Nowadays, everyone tries to "not offend" people.
Re:A minimal C compiler in x86 assembly by samhw on Tuesday May 03, 2022 @08:47AM (#31247614)
'Nowadays' as opposed to ... 7 hours ago?
Re:A minimal C compiler in x86 assembly by User23 on Tuesday May 03, 2022 @01:21AM (#31244944)
The link is broken.
Re:A minimal C compiler in x86 assembly by pabs3 on Tuesday May 03, 2022 @01:26AM (#31244966)
Fixed, thanks.