For almost 40 years I’ve wanted a language for small computers that was as easy/simple to use as BASIC but “better.” Forth almost does the trick, but it is a bit, uh, unconventional. Something structured and “extensible” with named subroutines that take parameters, have local variables, and can return values. Something like C or Pascal, but interactive. Both of those are probably too big to make interactive on a 32 to 64K machine.
The B programming language:
The B language was the predecessor to C. The best description for my purpose here is by Dennis Richie, The History of the C Programming Language. That’s a very interesting document, and I suggest you read it, but here is a quick summary as I see it.
Ken Thompson had been working on Multics but then Bell Labs pulled out of the project. He wanted to continue some of the work he had been doing and decided to write a smaller OS on a PDP 7 he “found” unused at Bell Labs. (Wouldn’t you like to work in a place in the late 60’s that just had computers sitting around unused?) He wrote the first version of Unix in assembly language, but wanted a high-level language. With only 8KW of memory, not much would fit. He had been using BCPL on the Multics project. BCPL was an “untyped” language. Everything was simply a computer word. He stripped the language down to absolute bare essentials, wrote a compiler that created “threaded code,” and an interpreter for that threaded code. Some I/O libraries were added later. A few programs were written in B, but soon Unix moved to the new PDP 11, which was byte addressed instead of word addressed, and Dennis Richie decided to extend B to fit better. One important aspect of this is that the B compiler was written in B!
A Project is born
What’s important to me is that here is a very small but very powerful language, that will fit (with an OS!) into 8 KW of memory (a bit more than 16 KB.) The OS, the runtime library, and the application program all had to fit at once. The application program could very well be the compiler. It was powerful enough to host its own compiler.
Apparently the original compiler has been lost. However, it has been recreated by Warren Toomey and others.
The runtime library was disassembled from a binary.
And so was the interpreter
The compiler was recreated.
Now, while I was researching doing this project, I realized that finding a working B compiler for a modern machine would be unlikely. But since C was an extension of B, I figured it wouldn’t be too hard to port the B code to C to get it working, then port it back to B once I had a compiler for B. But, Mr. Toomey beat me to it:
Here is a B compiler written in C.
I’ve been doing some reverse engineering. I pretty well understand the interpreter and some of the compiler. I think it would be fairly easy to port the whole system to other architectures. But…
Pretty much any system we are interested in is also byte addressed. So we run into the same problem Richie did. I think a few small extensions would account for that. I sure don’t want to recreate C, but some 8 bit I/O I think would be enough to make a neat little language for our 8 bit systems. It could be self-hosted on many of them. It is small enough that the compiler and runtime should fit into at least 64K of RAM, maybe 32K, and still leave room for some source code. So you could have an interactive, compiled language. A simple text editor could be added and you could write the code, hit a key to compile it, and run it immediately.
That’s my idea/plan as it stands now. I would be interested in hearing thoughts.
Here are some links to B reference material:
Introduction to B
B tutorial
Users’ Reference to B