Live data from Hacker News

Dennis Ritchie’s first C compiler (c. 1972)

github.com

21–30 of 163 posts

Re: Dennis Ritchie’s first C compiler (c. 1972)

#21
post #11

Earlier quoted context omitted.

Yes, bootstrapping with regard to languages is the trick of getting that first compiler running so you can compile the rest of the compiler. It has been done many times. The first assemblers were written directly in machine language. The first compilers were written in assembly. Many implementations of FORTRAN, ALGOL, COBOL, etc. As late as the 1970s it was not unknown to write a new high level language directly in m…

> Steve Woz's BASIC for the Apple II was "hand-assembled", as he put it. Very cool - so basically (haha) Woz's integer BASIC was bootstrapped by writing it in assembly language and translating it into machine code by hand. I wonder if someone (Woz?) has written a 6502 assembler in integer BASIC to allow it to bootstrap itself?

I'm not an expert, but I guess "bootstrapping" only applies to compilers, and Apple II BASIC was an interpreter. An interpreter doesn't have to compile itself, only run the programs you give it. So on an 8-bit computer the priority is to have an implementation that (a, and most importantly) takes up as little space as possible and (b) is reasonably fast.

Re: Dennis Ritchie’s first C compiler (c. 1972)

#22
post #21

Earlier quoted context omitted.

> Steve Woz's BASIC for the Apple II was "hand-assembled", as he put it. Very cool - so basically (haha) Woz's integer BASIC was bootstrapped by writing it in assembly language and translating it into machine code by hand. I wonder if someone (Woz?) has written a 6502 assembler in integer BASIC to allow it to bootstrap itself?

I'm not an expert, but I guess "bootstrapping" only applies to compilers , and Apple II BASIC was an interpreter . An interpreter doesn't have to compile itself, only run the programs you give it. So on an 8-bit computer the priority is to have an implementation that (a, and most importantly) takes up as little space as possible and (b) is reasonably fast.

[deleted]

Re: Dennis Ritchie’s first C compiler (c. 1972)

#23
post #20

I have to say, the way indentation and brackets were done here looks like it's just inviting subtle bugs. Take this for example: if (peekc) { c = peekc; peekc = 0; } else if (eof) return(0); else c = getchar();

It would have made code review a nightmarish activity for the team.

Re: Dennis Ritchie’s first C compiler (c. 1972)

#25
post #11

Earlier quoted context omitted.

When people say bootstrapping, is this how all computer languages came to be? Or there has been multiple attempts at bootstrapping? What I’m getting at is whether all languages have a single root.

Yes, bootstrapping with regard to languages is the trick of getting that first compiler running so you can compile the rest of the compiler. It has been done many times. The first assemblers were written directly in machine language. The first compilers were written in assembly. Many implementations of FORTRAN, ALGOL, COBOL, etc. As late as the 1970s it was not unknown to write a new high level language directly in m…

> No one has implemented a serious high level systems language, except in a high level systems language, for a long time now.

LuaJIT is a prominent counterexample. The base interpreter in written in assembly for performance. It comes with its own tradeoffs, especially portability.

Re: Dennis Ritchie’s first C compiler (c. 1972)

#26
post #9

Very interesting. Does anyone have any idea how the C compiler was bootstrapped. Was it first written in B, or was it written in PDP-11 assembler?

It was written in B. And B was written in B. To trace the bootstrap up into the high level, you have to go further back than the PDP-11. To bootstrap B on the PDP-7 and GE-635 machines he had access too, Ritchie wrote the minimum subset required to compile a compiler in B, in a language known as TMG (in the vein of, and a big influence on, Yacc and similar). This minimal bootstrap was then used to compile a B compile…

I like that the Bootstrappable Builds folks are working on a bootstrap process that goes from a small amount of machine code (~512 bytes) all the way up to a full Linux distro, including compilers/interpreters for modern languages.

https://bootstrappable.org/

Re: Dennis Ritchie’s first C compiler (c. 1972)

#27
post #20

I have to say, the way indentation and brackets were done here looks like it's just inviting subtle bugs. Take this for example: if (peekc) { c = peekc; peekc = 0; } else if (eof) return(0); else c = getchar();

If you judge the coding style of the early 1970s with modern standards, it isn't going to look great. 50 years is a loooong time.

dmr was one of, if not the first C programmer(s).

Re: Dennis Ritchie’s first C compiler (c. 1972)

#28
post #9

Earlier quoted context omitted.

It was written in B. And B was written in B. To trace the bootstrap up into the high level, you have to go further back than the PDP-11. To bootstrap B on the PDP-7 and GE-635 machines he had access too, Ritchie wrote the minimum subset required to compile a compiler in B, in a language known as TMG (in the vein of, and a big influence on, Yacc and similar). This minimal bootstrap was then used to compile a B compile…

When people say bootstrapping, is this how all computer languages came to be? Or there has been multiple attempts at bootstrapping? What I’m getting at is whether all languages have a single root.

Some languages have multiple implementations in different languages. The Bootstrappable Builds folks are working on proper bootstrap for everything.

https://bootstrappable.org/ https://bootstrapping.miraheze.org/wiki/Main_Page

Re: Dennis Ritchie’s first C compiler (c. 1972)

#30
post #20

I have to say, the way indentation and brackets were done here looks like it's just inviting subtle bugs. Take this for example: if (peekc) { c = peekc; peekc = 0; } else if (eof) return(0); else c = getchar();

I dont think it would look that out of place if he was using the ternary operator which is the same thing after all.

E.g.:

  if (peekc) {
    c = peekc;
    peekc = 0;
  } else
    eof ?
      return(0) :
      c = getchar();
The first else clause sill looks weird, but the final part isn't nearly as out of place (well i guess assigning in a ternary would be weird, but in terms of indentation) and its not like we actually changed anything.
Post reply on HN