Live data from Hacker News

Dennis Ritchie's first C compiler on Github

github.com

1–10 of 88 posts

Re: Dennis Ritchie's first C compiler on Github

#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),waste(waste),waste(waste));
  	waste(waste(waste),waste(waste),waste(waste));
  	waste(waste(waste),waste(waste),waste(waste));
  	waste(waste(waste),waste(waste),waste(waste));
  	waste(waste(waste),waste(waste),waste(waste));
  	waste(waste(waste),waste(waste),waste(waste));
  	waste(waste(waste),waste(waste),waste(waste));
  }
Found in last1120c/c10.c

Re: Dennis Ritchie's first C compiler on Github

#5
post #3
post #2

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

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

Presumably the first step on the road to a self-compiling C compiler was written in B.

Re: Dennis Ritchie's first C compiler on Github

#6
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 originally compiled BCPL)

Re: Dennis Ritchie's first C compiler on Github

#7
Coincidences... I thought "How come Warren Toomey (one of the guys of the Unix Heritage Society [1]), has never posted this?"

Turns out, this Github-repo is just a mirror/copy of his work, but with attribution [2]. Still worth reading through there, tuhs also stores some extremely old UNIX versions.

[1] www.tuhs.org

[2] http://cm.bell-labs.com/cm/cs/who/dmr/primevalC.html

Edit: Warren has written a paper on restoring ancient UNIX versions and C-compilers, you might like it [3]

[3] http://epublications.bond.edu.au/infotech_pubs/146/

Edit2: Now that I've thought a little bit about it, I'm not happy that the sources are on GitHub in this form. This is Warren's work - he did a lot of work in getting these tapes to work again, and "mortdeus" just copied the work and didn't even change the folder-names - "last1120c" is the first tape, "prestruct" the second. And you still need Warren's Apout emulator to get these files to work.

Re: Dennis Ritchie's first C compiler on Github

#8
post #2

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

Your question is answered at length in http://plan9.bell-labs.com/who/dmr/chist.html. But it is common to write compilers some subset of the language that you want to compile, see http://en.wikipedia.org/wiki/Bootstrapping_(compilers).

Re: Dennis Ritchie's first C compiler on Github

#9
post #3
post #2

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

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.

Re: Dennis Ritchie's first C compiler on Github

#10
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),…

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 function; in the later, the start is simply taken to be 0. This indicates that the first compiler was written before we had a machine with memory mapping, so the origin of the program was not at location 0, whereas by the time of the second, we had a PDP-11 that did provide mapping. (See the Unix History paper). In one of the files (prestruct-c/c10.c) the kludgery is especially evident.

Post reply on HN