Live data from Hacker News

Dennis Ritchie's first C compiler on Github

github.com

11–20 of 88 posts

Re: Dennis Ritchie's first C compiler on Github

#12
post #2

Is this written in C? If so, what compiled this? Sorry for the noob question, I'm just a little lost.

From the link on GitHub: http://cm.bell-labs.com/cm/cs/who/dmr/primevalC.html Which led me to here: http://cm.bell-labs.com/cm/cs/who/dmr/chist.html Where, if you take the time, you will find a wonderful story, upon completing, you will probably know more about the early embryonic history of C then 95% of your peers. (Spoiler - We start with BCPL, then Move to B - it's left as an exercise to determine how we original…

coupled with user:rmrfrmrf's pseudo-religious post praising the code, I read the second url as "christ" :P

Oh how our minds play tricks on us!

Re: Dennis Ritchie's first C compiler on Github

#13
post #2

Is this written in C? If so, what compiled this? Sorry for the noob question, I'm just a little lost.

One might write a compiler from language X to language Y first in assembly, then when that works, write a new compiler from language X to language Y in language X itself and use the previous compiler to compile it. Presumably they already had a C compiler that they used to get this one compiled, then it can compile itself afterwards.

Re: Dennis Ritchie's first C compiler on Github

#14
post #2

Is this written in C? If so, what compiled this? Sorry for the noob question, I'm just a little lost.

A compiler has to do a lot more than parse a source file and translate it to target code: error checking and reporting, optimization, etc.

To compile a C compiler, you don't need a full-blown C compiler. For instance, I bet floats and doubles are not used. Therefore, you can write a barebones proto-C compiler in whatever language you have available and use it to bootstrap your compiler. Rinse and repeat.

Re: Dennis Ritchie's first C compiler on Github

#16
post #4

Earlier quoted context omitted.

Looks like a very early dialect. C assumes everything is an int unless specified otherwise. You can declare parameter types after the function name. So: init(s, t) char s[]; { would be equivalent to: int init(char s[], int t) { This still works with modern compilers. I'd be interested if anyone has any more info about this: waste() /* waste space */ { waste(waste(waste),waste(waste),waste(waste)); waste(waste(waste),…

From the linked description ( http://www.cs.bell-labs.com/who/dmr/primevalC.html ): A second, less noticeable, but astonishing peculiarity is the space allocation: temporary storage is allocated that deliberately overwrites the beginning of the program, smashing its initialization code to save space. The two compilers differ in the details in how they cope with this. In the earlier one, the start is found by naming a…

Doh, I completely glossed over the readme and went straight to the code. That makes sense -- Thanks!

Cool to think that that waste function can still compile with todays compilers. A quick disassembly it seems to take up 751 bytes compiled on x64 using clang on O0.

Re: Dennis Ritchie's first C compiler on Github

#17
post #4
post #2

Is this written in C? If so, what compiled this? Sorry for the noob question, I'm just a little lost.

Looks like a very early dialect. C assumes everything is an int unless specified otherwise. You can declare parameter types after the function name. So: init(s, t) char s[]; { would be equivalent to: int init(char s[], int t) { This still works with modern compilers. I'd be interested if anyone has any more info about this: waste() /* waste space */ { waste(waste(waste),waste(waste),waste(waste)); waste(waste(waste),…

That was the standard way of declaring parameter types until ANSI C in 1989. C actually copied the current style back from C++.

Re: Dennis Ritchie's first C compiler on Github

#20
post #9
post #3

Earlier quoted context omitted.

It compiles itself! http://en.wikipedia.org/wiki/Bootstrapping_(compilers)

I understand bootstrapping, but at some point there has to exist some outside compiler in another language or a hand-compiled version of this otherwise the chicken and egg chain never ends.

You can use any language available in the machine to create the first, most basic compiler. You can also use a cross-compiler if a compiler for the language already exists for another machine. If all else fails, you can write the proto-compiler in assembly.
Post reply on HN