On May 2, 1979, a small working group at the US Department of Defense voted for a language that was named Ada that same evening. The tender itself had run for four years and drawn some fifteen proposals, but only two made it to the final, and right up until the winner was announced they went by code names: Green and Red. Green won; its specification came from Jean Ichbiah’s French-American team, and it is GREEN that became known as Ada. Red, the work of the Boston company Intermetrics, lost and was all but forgotten. And yet Red already had a working translator, which, as its authors remember, was ready on time. Under the terms of the contract it was not taken into account in the selection, and apart from its authors nobody has ever laid eyes on it.

Of course, a series on paleocomputing could not walk past this tender. I wanted to dig up the specifications submitted to it and finally build the programming languages that never existed, write a self-compiling compiler in each, and see what these languages can do. In RED I even wrote a small OS and something like a Kubernetes control plane. I modelled the OS on Tandem NonStop, the computers that banks and stock exchanges bought from 1976 on because they never stopped. One variant of my control plane works like their process pairs: a primary and a backup process, with no etcd and no quorum, and it survives the death of the API server in the middle of an application rollout. But the most instructive find wasn’t in the code: the Ada that won then spent decades, slowly and expensively, trying to implement what the losing RED had from the very beginning.

This is the third part of my series on paleocomputing. In the first I ran Niklaus Wirth’s processor in a browser, in QEMU and in Kubernetes; in the second I built Kubernetes on Oberon machines that exchange signals over radio. You don’t need to read them first; this story stands entirely on its own.

I’m interested in the ideas that lived inside technologies that lost: what we lost along with them, and which of the lost things came back later in other technologies. Ada turned out to be an especially good example. Its requirements were written over years, in public, by the whole world; dozens of review teams picked the finalists apart; and the whole story is very well documented.

The article, of course, came out long. First we’ll briefly look at how that tender came about and why the Greens won, then see what is actually left of the losing languages. After that we’ll talk about both languages and their compilers, and about how a 1979 program ran for the first time. Then come the operating systems, Kubernetes, a comparison of RED with classic Ada, and a bit of tinfoil-hat speculation: what our industry might have become if in May 1979 the experts had picked a different winner. And at the end there will be labs. The two other contenders, blue and yellow, are well documented too, but they dropped out back in 1978, so they will get a separate piece.

All the sources, notes and instructions are in the repository github.com/tym83/paleocomputing, under impl/ada-colors, available under the Apache 2.0 license.

How the Pentagon chose a language

In the mid-seventies the US Department of Defense had a problem that today we’d call a technology zoo. Embedded software for aircraft, ships and command systems was written in hundreds of languages and dialects, every contractor brought its own, and maintaining the whole menagerie cost billions. In January 1975 the High Order Language Working Group, HOLWG, was formed, and its chairman, Air Force Lieutenant Colonel William Whitaker, proposed something strange for a military agency: first agree, in public, on the requirements for the language, and only then go looking for the language.

The requirements took several years to write, and you can see from the names of the revisions how they grew ever more precise, even hardened: Strawman in April 1975, then a wooden Woodenman, a tin Tinman, an iron Ironman and finally Steelman in June 1978. Tinman went out to a thousand people in industry and academia, and even earlier, for Strawman, Dijkstra, Hoare and Wirth sent in comments. Twenty-three existing languages were checked against the requirements, and none of them fit. The new language, it was decided, should be built on one of the three that came closest: Pascal, PL/I or Algol 68. One amusing detail from Whitaker’s recollections: C was invited to the evaluation too, but Bell Labs, where it was created, themselves asked that C be left off the list, and the group honored the request.

In the spring of 1977 the competition was announced. Fourteen proposals came in, and in August four teams were funded. So that reviewers would judge on substance rather than brand names, the designs were anonymized by color: Green went to CII-Honeywell-Bull, Red to Intermetrics, Blue to SofTech and Yellow to SRI International. According to Whitaker, the colors had no hidden meaning.

In February 1978 the four preliminary designs went out for evaluation, and some eighty teams from military and civilian organizations pored over them. Dijkstra spent a whole month on them and wrote a review of each. He called Yellow a hopeless mess, faulted Blue for a 160-page chapter on types, ended his review of Green with a phrase about “technical incompetence, probably enhanced by dishonesty,” and confessed to being baffled by Red: the design was at once advanced and backward, and he couldn’t see how the two went together. He advised Whitaker not to choose any of the four. The advice wasn’t taken: in April 1978 Green and Red went through to the second round.

The second round lasted a year. And here is what matters most for this story. The Red team threw out its first design entirely. The chief designer, John Nestor, rewrote the language from scratch, so there are actually two red languages. The first, REDL, was built on Hoare’s monitors, modules with shared data that only one process can enter at a time, and on events. The second, RED, the one that reached the final, rested on mailboxes and critical sections, which the tour of RED covers in detail. The Red project was managed by Ben Brosgol, and the language was designed by Nestor. Red’s consultants included Barbara Liskov, William Wulf, Paul Abrahams and Robert Dewar, the future head of the GNAT project, the free Ada compiler. On March 15, 1979, both teams handed in a complete specification, a rationale for the design, solutions to the same ten contract problems, small exercises set by the DoD for every team, from a ring buffer to a scheduler, and a test translator.

Red’s translator worked. It was built by Mark Davis’s group, and in the recollections of Mary Van Deusen, co-author of the RED manual, it comes across as a small feat: a compiler for a language that kept changing under it, ready on time. But the second-round contract stated that the translator would not be considered in the selection. Whitaker, for his part, explains it differently: both translators turned out to be too incomplete, and possibly too slow, to influence the evaluation.

On May 2, 1979, the group chose GREEN. That same day Whitaker sent out three thousand green postcards reading “Green is Ada!” The vote was unanimous, like every vote this group ever took: Whitaker admits he only put a question to a vote once everyone already agreed. Van Deusen tells a story from the losing side about a young Air Force representative who had been ordered to vote for Green, discuss nothing and not change his mind. I found no confirmation of this, so let it remain just a historical anecdote (though it does look a lot like the way decisions get made in cases like this).

Why Green won is written, in the documents available, mostly between the lines. The reviewers’ reports on the final have not survived online. The analyses of the first round, however, as it turned out, did survive, and they will get the next article. Tucker Taft, who joined Intermetrics in 1980 and later led the design of Ada 95, says Green reached stability and completeness earlier than the others, and that Ichbiah was remarkably good at presenting it to the reviewers. Van Deusen recalls that the Green team had a very fine sense of politics from day one, and that its first design decision was the length of the description. And a popular Time-Life book on programming languages from 1986 has what I think is the most accurate line of all, put in the mouth of one of the competitors: in the final, both languages changed, with Red growing bolder and Green more conservative.

Then came a long polishing period. The Preliminary Ada Reference Manual was published in June 1979 in SIGPLAN Notices; it was picked apart and reworked, and only in February 1983 did the ANSI/MIL-STD-1815A standard appear, the one we now call Ada 83. The standard’s number comes from the year Ada Lovelace was born. Intermetrics buried the red language quickly and, according to Van Deusen, completely. But this story has a sequel that I’ll come back to.

What was left of the losers

When I first took up this story, I was sure almost nothing of the red language had survived. The opposite was true, and that’s a common story in paleocomputing: “nothing survived” is almost never the case. What survived is simply lying somewhere other than where people look.

The RED manual of March 8, 1979, was retyped in full as HTML by Mary Van Deusen, its co-author, for the competition’s thirtieth anniversary. Next to it sits the complete Rationale, with its discussion of rejected alternatives, solutions to the ten contract problems and an example of a library capsule, as RED calls a module. Van Deusen writes that after the competition these documents were unavailable to the public. That’s true for 1979–1990, but in March 1990 the manual went into the Defense Technical Information Center archive, DTIC, marked “approved for public release,” and it’s still there under the number AD-A219453.

The syntax of RED is given in the manual not as text but as diagrams, and every one of them is an image. The eighty-three language diagrams and twelve lexical ones had to be redrawn to get a conventional grammar, and along the way 105 code examples, also images, had to be transcribed. In the process, inconsistencies turned up within the manual itself. For example, the diagram puts a semicolon after a goto label, while the table of special characters and the examples use a colon.

Diagram 36 from the RED manual: a statement with a goto label

Diagram 36 from the RED manual (Intermetrics, 1979), as reprinted at iment.com: a statement with a goto label. The diagram puts a semicolon after the label’s identifier, while the table of special symbols and the examples call for a colon

With the green language I expected the opposite: since Ada (that very GREEN) won, its documentation should be easy to get. Yet Ada 83 is everywhere, while the green language as it stood in the spring of 1979, before all the rework, was harder to find. The DTIC mirror on the Internet Archive came to the rescue. It had the “Informal Introduction to the Green Language,” its formal definition, solutions to the same contract problems and, most valuable of all, two documents: the “Preliminary Ada Reference Manual” of May 1979, with a letter attached from the Deputy Secretary of Defense dated May 14 announcing the choice of language, and the complete Rationale of the Green design dated March 15, 1979, the day the final materials were due. All of it is scans with poor text recognition, in places nightmarish, but readable.

The letter of Deputy Secretary of Defense Charles Duncan of May 14, 1979

The letter of Deputy Secretary of Defense Charles Duncan of May 14, 1979, which opens the Preliminary Ada Reference Manual (DTIC AD-A071761, scanned at the Internet Archive). Comments on the language are invited until November 30, and the last paragraph explains whom the language is named after

The contract problems deserve a word of their own. These are ten problems the DoD handed to every team: polling keyboards through a shared ring buffer, an interrupt system with four priority levels, a file package, dynamic graphics with joysticks, protecting a database from concurrent access, process control, adaptive routing, a real-time scheduler, distributed broadcast, and unpacking bit-level message headers. Both teams solved the same problems, which gives us a unique chance to compare their approaches once more. Once again all twenty solutions had to be recognized to get source code. The Red team got by in 815 lines of code without comments, the Green team needed 1660, twice as many, and I’ll show why once I get to the solutions themselves.

The Blue and Yellow designs, judging by a 2023 thread on the systemsafety mailing list, are inside a huge 4575-page volume of first-round reports in the same DTIC (and so it turned out; we’ll cover them in the next article). What I couldn’t find is Red’s translator. All that remains of it is a bibliographic reference in a 1981 article by Van Deusen (“M. Davis and D. Levine, RED Translator, Intermetrics, Inc., March 1979”), a couple of paragraphs in the Rationale about what input/output it supported and how the syntax of the contract problems was run through it, and Van Deusen’s own recollections. No source code is available. So we won’t see the compiler that was built in 1979, but we can write a new one, and it’s probably the first publicly available RED compiler in the language’s entire history.

A tour of RED

At first glance RED looks like Pascal that has spent a long time at the gym. Here’s a piece of a matrix arithmetic package from the appendix to the Rationale, whose examples were written by Paul Abrahams, Bruce Knobe, David Levine and others. I’ve substituted the constants and removed the comments. Look first of all at the types and at the function header:

CAPSULE matrix_vector_package EXPORTS ALL; CONST maxdim := 100; ABBREV mvfloat : FLOAT(6, -1.0E99 .. 1.0E99); ABBREV dim : INT(2 .. maxdim); TYPE matrix(m : dim, n : dim) : ARRAY INT(1 .. m), INT(1 .. n) OF mvfloat; TYPE vector(n : dim) : ARRAY INT(1 .. n) OF mvfloat; FUNC *(READONLY b : matrix, READONLY c : vector) => vector(b.m); ASSERT b.n = c.n; VAR a : vector(b.m); FOR i : INT(1 .. b.m) REPEAT a(i) := 0.0; FOR j : INT(1 .. b.n) REPEAT a(i) := a(i) + b(i,j) * c(j); END REPEAT; END REPEAT; RETURN a; END FUNC *; 

Look closer, though, and these fifteen-odd lines already contain a lot of things the mainstream would only get much later. ABBREV here is just a short name for a subtype, and FLOAT(6, …) is a floating-point type with precision 6 and the given range. Dimensions live in the type: vector(n) is a type with a parameter, and b.m and c.n read like ordinary attributes of a value. That’s why the result type is computed from the arguments, and the function promises up front to return vector(b.m). The * operator is overloaded on operand types, so a single sign multiplies scalar times vector, matrix times scalar, matrix times vector, matrix times matrix. And further on in the package the cross product is declared as * for vector(3): the constraint on the dimension is written right into the parameter type, and a call with a vector of a different length raises a subtype exception. In Rust you’d express that constraint with const generics, Vector<3>. And there’s ASSERT right in the function body, as part of the language.

Below I’ll go through what struck me as most interesting in RED. Almost none of this is a summary of the Reference Manual; it’s the stuff I personally tripped over while writing (not with my own hands, admittedly) a compiler, an operating system and Kubernetes in RED.

Capsules and abstract types without the word private

A module in RED is called a capsule. A capsule exports exactly what is listed after EXPORTS, and whoever uses it explicitly opens up what they need with EXPOSE:

CAPSULE stackcap EXPORTS stack, init, push, pop; TYPE stack : RECORD[top : INT(0 .. 100), elem : ARRAY INT(1 .. 100) OF INT]; ... END CAPSULE stackcap; EXPOSE stack, push, pop FROM stackcap; 

In Ada an abstract type is made with a private section in the package specification. RED has no such section, but it does have a rule that I skipped at first and later got caught by myself: when a capsule exports a type, it exports neither selection of its components nor assignment. From outside you can declare a variable of type stack and pass it to push, but you can’t write s.top := 0. If you want to expose the insides, the simplest way is to export everything with EXPORTS ALL. In other words, whether a type is abstract is determined not by how it’s declared but by what the capsule lets out. When you think about it, that’s a very honest model: the type itself hides nothing; the module boundary does the hiding.

Closed scopes and IMPORTS

This rule turned out to be the one I felt most in day-to-day work. A procedure in RED is a closed scope: it can see constants, types and other procedures from outside, but not variables, unless it imports them explicitly:

VAR hits : INT := 0; VAR limit : INT := 3; PROC hit IMPORTS hits, READONLY limit; IF hits < limit THEN hits := hits + 1; END IF; END PROC hit; 

A variable can also be imported read-only, like limit in the example. Essentially it’s the same thing as a lambda capture list in C++, except mandatory and for every procedure. For a language meant for maintaining enormous programs over decades, that’s sensible: the procedure header tells you at a glance what state it can mess up.

Next to it is the distinction between normal and abnormal functions. A normal function depends only on its arguments, and the translator is allowed to drop a repeated call with the same arguments. If a function’s result depends on more than its arguments, say it reads outside variables, you have to put ABNORMAL in front of it. A normal function is allowed side effects only on its own capsule’s variables, such as a call counter or a memo table. The word looks funny, but the idea is close to what we now call pure functions.

Parameters are passed in four ways: CONST copies, READONLY passes by reference without the right to modify, VAR passes by reference with modification, and OUT is a local variable whose value goes to the actual parameter only if the procedure completes normally. If the procedure ends with an exception, the caller’s variable stays as it was. Why reading by copy and reading by reference must be distinguished, the Red team explains separately. Leaving the choice to the translator won’t do, because then the program’s behavior depends on the implementation, and always copying is too expensive for large objects.

Exiting a loop by name

A small thing I really liked. EXIT in RED must name the statement it exits from:

outer WHILE p /= NIL REPEAT ... IF found THEN EXIT outer; END IF; END REPEAT outer; 

The rationale is simple: if EXIT left the nearest loop, then wrapping a new loop around it would silently change the meaning of the program. And I’ve seen that bug in production more times than I’d like.

Diagram 45 from the RED manual: the EXIT statement

Diagram 45 from the RED manual (Intermetrics, 1979), as reprinted at iment.com. EXIT is followed by an identifier, and the diagram has no way around it

Mailboxes, WAIT and REGION

The main difference between RED and the future Ada is concurrency, and here a short digression is in order for those who haven’t written Ada (which is almost everyone). In both languages a task is what today we’d call a thread: a piece of the program that runs at the same time as the rest. The question is how tasks come to terms with each other. In Ada, and in the green language before it, the only way is the rendezvous. A server task has entries that look like procedures. The client calls an entry and waits; the server reaches an accept statement for that entry in its own code and waits too; and when both are there, the body of the accept runs, after which each goes its own way. It’s a meeting, hence the name. RED works differently: tasks exchange messages through mailboxes, that is, message queues between tasks inside the program, and protect shared data with critical sections:

VAR m : MAILBOX[msg](3); % a mailbox for three messages VAR d : DATA_LOCK; TASK consumer IMPORTS m; VAR data : msg; WHILE TRUE REPEAT RECEIVE(m, data); ... END REPEAT; END TASK consumer; VAR c : ACT; CREATE consumer NAMED c; SEND(m, x); REGION d DO shared := shared + 1; % the lock is released however the body ends END REGION; 

A mailbox is typed and bounded. A mailbox of size zero is a rendezvous: the sender can’t get ahead of the receiver. The WAIT statement waits for the first of several events: a receive from any mailbox, a send, or a timeout:

WAIT WHEN RECEIVE(ports(me), m) => handle(m); WHEN DELAY(35) => take_over; END WAIT; 

And here’s a detail that shows how carefully the language was thought through. A SEND to a zero-size mailbox inside WAIT is forbidden: the attempt raises the X_EMPTY_MAILBOX exception. Why? Because otherwise tasks waiting on each other to send to zero-size mailboxes could end up in a circular wait, and the only way to prevent it would be global scheduling.

REGION acquires a data lock and is guaranteed to release it no matter how the body ends: normally, by an exception, by exiting a loop, or by returning from a procedure. Ada 83 has nothing like it; there a lock is built as a separate task with two entries, and if an exception strikes between acquire and release, the lock simply stays held. More on that in the chapter on Ada 83.

Mailboxes and REGION in RED next to the rendezvous of the green language

On the left, RED: tasks pass messages through a mailbox, and REGION guards the shared data. On the right, the green language: a client calls an entry of the server task and waits in its queue until the server reaches its accept

Tasks are started explicitly, CREATE task NAMED variable, and every activation, that is, every running instance of a task, has a name, a variable of type ACT. You can ask it whether the task is alive, change its priority, wait for it to finish, or kill it with EXTERMINATE. The built-in scheduler is priority-based: higher priority goes first, and among equals whoever has waited longest goes first.

Your own scheduler

At the language’s lowest level, in chapter fourteen of the Reference Manual, a systems programmer can describe their own scheduler and their own synchronization mechanisms. The language hands them the operations of the scheduler itself: suspend an activation, wait for a signal, make a stretch of code critical so that it is neither preempted nor killed halfway. The built-in mailboxes, locks and WAIT are described in the same chapter as special cases built from these operations. The manual shows it with examples: a round-robin scheduler, Hoare’s monitors on top of data locks, and even MAILBOX itself, defined in the language. All of these examples run in my compiler. The very fact that a 1979 language invited the user to write schedulers, not just use the one provided, says a lot to me.

Generics that instantiate themselves

A generic procedure in RED looks like this:

GENERIC t : TYPE NEEDS :=(t, t) PROC swap(VAR a, b : t); CONST c := a; a := b; b := c; END PROC swap; swap(i, j); % i and j are integers swap(s, r); % s and r are strings 

Notice what isn’t there. In Ada you first have to create an instance explicitly, procedure SWAP_INT is new SWAP(INTEGER), and only then call it. RED has no instantiation statement at all: each call tells the translator which types it needs, and the translator creates an instance or reuses one it already has. C++ templates would later work the same way, but RED did it eleven years earlier. And the NEEDS list spells out which operations the type parameter must have, assignment in this case. C++ got the same thing only in 2020, under the name of concepts. My compiler checks this list at every call: if the operation isn’t there or has the wrong header, the call doesn’t translate. Generic parameters can be types, values, procedures and even tasks. In its solution to the scheduler contract problem, the Red team passes a task as a parameter to a generic wrapper task that launches it on schedule.

Strings that remember their length

The string type in RED is STRING[ASCII](n), and the length is fixed for each object. You can’t assign a string of a different length; that’s a subtype error. For variable-length text you need a pointer type with a parameter, and the Reference Manual has exactly such an example, a symbol table:

TYPE sym : PTR (len : INT) STRING[ASCII](len); ALLOC s.syms(s.top) PTR (val.LEN) := val; 

ALLOC creates a dynamic string of exactly the length of val and puts a pointer to it into the table. The RED compiler written in RED stores all its names and chunks of generated code exactly this way. ASCII characters in RED are named enumeration values, so a lowercase a is written 'L_A, an apostrophe 'APOS, a double quote 'QUOTE. You can’t put a double quote inside a string literal at all; you can only concatenate the string with the character. In the source of a compiler that generates C, this looks rather funny: "rt_str(" & q & "TRUE" & q & ", 4)", where q is a function that returns a double quote.

A FREE that refuses to free

One last thing in the Reference Manual impressed me. A dynamic variable in RED lives as long as there are references to it, which means that by default the language assumes garbage collection. But for those who can’t afford it, there’s a FREE procedure. If other pointers to the variable being freed still exist, FREE doesn’t free it; it raises the X_FREE exception. A dangling pointer becomes impossible by construction, and the check itself can be switched off if it is too expensive, with a pragma, a directive to the translator written in the program itself: PRAG(SUPPRESS(X_FREE)). All of this in 1979. In my compiler, FREE walks all reachable memory before it frees anything: the globals, the frames of every task’s running subprograms, the dynamic variables and the mailbox buffers. A program that doesn’t use FREE pays nothing for this.

GREEN in the spring of 1979

It’s easy to take the green language for early Ada, and that’s a mistake. The preliminary manual of May 1979 describes a language that looks like Ada 83 in its syntax and yet in places is something else entirely. I built a compiler for the green language in the green language itself alongside the red one, and along the way the language showed as much character as RED did.

What a program looks like

Here’s one of the programs from the “Informal Introduction,” a change counter:

restricted (TEXT_IO) procedure COUNT_YOUR_CHANGE is use TEXT_IO; ... begin ... PUT("CHANGE IS $"); PUT(NUM_DOLLARS); PUT("."); PUT(NUM_CENTS); end if; end; 

Several differences from Ada 83 are visible right away. Instead of with TEXT_IO, the procedure is preceded by restricted(TEXT_IO): in the green language every compilation unit is by default restricted to an empty visibility list, and libraries have to be named explicitly. What’s more, restricted can go in front of any nested module, not just a compilation unit, narrowing its visibility inside the program. There’s no PUT_LINE procedure: a line break is the string constant NEWLINE, printed with PUT(NEWLINE). This program, by the way, doesn’t print one at all. And under the 1979 I/O rules, every number printed anywhere other than the start of a line gets a space in front of it. So this program from the introduction literally prints CHANGE IS $ 2. 53, and apparently nobody noticed at the time.

Plenty of small things give away a different language. A character literal in the green language is simply a string of length one, "A"; there’s no apostrophe for characters, it’s only for attributes. Enumeration positions count from one, so CHARACTER'ORD("A") is 66 rather than the familiar 65. The mod operation takes the sign of the left operand, which means it behaves like rem in Ada 83. There’s no abs operator, only an ABS function, and the branches of a case come after of, not is. In named association the parameter mode is written right at the call site: F := x passes a value in, F =: v takes the result out, and F :=: v does both. The language also had an assert statement, which would not make it into Ada 83. A detailed table of differences from Ada 83 is in the project notes.

Rules the compiler had to be built around

The main thing I tripped over was the function purity rules in section 6.5 of the manual. A function in the green language may not assign to anything nonlocal, modify objects through pointers, allocate memory, or, since input/output and external procedures can have side effects, call them. For generators like “give me the next unique number” there are value-returning procedures: procedure NEXT return INTEGER. They’re allowed to change global variables, but they may be called only in an assignment, an initialization or a procedure call, and only where those global variables are out of scope.

That sounds like a formality until you start writing a parser. An ordinary recursive descent parser works like this: there’s a pointer to the current token, and an EXPR function parses an expression, advancing the pointer and returning a tree. In the green language you can’t do that. A function can’t advance the pointer, and a value-returning procedure can’t be called where the pointer is visible, and inside a parser it’s visible everywhere. So the entire parser of the green-language compiler is written as procedures with out parameters: EXPR(X) instead of X := EXPR. The compiler checks these rules for other people’s programs too, and its own source passes them.

Interestingly, the red language settled the same question the opposite way. In RED a function is normal by default: its result depends only on its arguments, and the only things it may change are the hidden variables of its own capsule. If it needs more, it’s marked ABNORMAL, and then anything goes. The green language forbids; the red language makes you label it. For military code the green approach is probably safer. For someone writing a compiler, the red one is more convenient, and I suspect places like this are exactly what got softened in 1980–1983.

Tasks without task types

Multitasking in the green language is built on the rendezvous, as in Ada, but it looks different. There are no task types. You declare a task and it exists, but it starts only with an initiate statement. If the task is already running, a second initiate raises the INITIATE_ERROR exception, while a task that has finished can be started again, with fresh variables. To get many identical tasks there are families: task KUBELET(INTEGER range 1 .. 3) (that’s what the node agents of my Kubernetes are called; we’ll get to them), and inside its body a task learns its number through KUBELET'INDEX. There are entry families too.

A select has guards, delays and else, but no terminate alternative, and if all the alternatives are closed and there’s no else, SELECT_ERROR is raised. The calling side can’t choose between waits at all: no timed call, no conditional call. An exception raised in the body of an accept reaches both sides of the rendezvous. And the only exception you can raise in another task is called FAILURE: raise T.FAILURE. Another task, on the other hand, can be killed with an abort statement. There are fifteen predefined exceptions, and each names its trouble outright: RANGE_ERROR, INDEX_ERROR, ACCESS_ERROR, DIVIDE_ERROR, NO_VALUE_ERROR for reading an uninitialized variable or for a function that ended without return, and so on. Ada 83 replaced them with five more general ones: of the green names only TASKING_ERROR survived, and the rest merged into CONSTRAINT_ERROR, NUMERIC_ERROR, PROGRAM_ERROR and STORAGE_ERROR.

A compiler that compiles itself

The goal I set myself was this: each language should have a compiler written in that language. That’s not just a nice tradition. A compiler is an honest test of a language: if you can write several thousand lines of parsing, symbol tables, type checking and code generation in it, the language is fit for real work, and all its awkward spots will surface on their own.

A shared runtime and predictable time

Both compilers translate a program into C and build it against a shared runtime, also written in C. It’s about eight and a half thousand lines, and it holds everything the languages need at run time: strings, exceptions, checked arithmetic, I/O, RED’s mailboxes and locks, the green language’s rendezvous, and the task scheduler.

With the scheduler I did one thing that paid for itself many times over. Every task in the runtime is an operating system thread, but the threads pass a baton to one another, and at any moment exactly one of them is running. Thanks to that, RED’s scheduling rules hold to the letter: the task with the highest priority runs, among equals the one that has waited longest goes first, and a task that becomes ready with a higher priority preempts the current one.

Time is virtual: when every task is waiting for something, the clock jumps straight to the nearest wake-up. And if there’s nobody left to wake, the runtime doesn’t hang; it prints that all tasks are blocked. The upshot is that any program prints exactly the same thing on every run, even with a dozen tasks, timeouts and tasks being killed, and the expected output can sit next to the test. For an operating system and for Kubernetes, where the whole point is what happens when something fails at a bad moment, this is priceless: the bad moment is reproducible down to the millisecond.

Bootstrapping

You can’t build a compiler written in language X until you have a compiler for language X. The classic way out is bootstrapping. First I made a small seed translator in Python, around two and a quarter thousand lines including the parser, that understands only the subset of RED the real compiler would be written in. Then I wrote the real compiler, redc, in that subset and ran it through the Python seed. The resulting compiler translated its own source, that result translated itself once more, and the two C files matched byte for byte. That’s the fixed point: the compiler reproduces itself, and the seed is no longer needed.

This is where it gets interesting. From then on, all you need to build it is the C file that the latest compiler produced from its own source, and the language grows inside the compiler itself. Every new feature is added to redc in such a way that redc itself doesn’t use it yet; then the compiler is built with the previous version, the fixed point is checked, and only after that may the new feature be used in its own source. That’s how capsules, exports and nested procedures with static links, that is, pointers to the frame of the enclosing procedure, arrived first, then multitasking, then overloading with parameterized types, two-dimensional arrays and sets, and finally generics. Today the compiler is about eleven thousand lines of RED and translates itself in a couple of tenths of a second. On every change, CI rebuilds it twice from that C file and compares the results, and a separate build target repeats the very first step, from the Python seed, so the chain can be verified from scratch.

The bootstrap and growth of the RED compiler

The bootstrap and growth of the RED compiler. The Python seed is needed only for the first step; after that each version of redc is built by the previous one from the stored C file

What RED did to me

Eleven thousand lines in a 1979 language are a good test not only of the language but of your patience. Here are the places where headstrong RED argued with me, and almost every time, on reflection, it was right.

The very first thing the compiler did was refuse to translate its own lexer. The upper function turned a lowercase letter into an uppercase one via POS(c), and the compiler insisted that POS wasn’t a function. It turned out I had a global variable pos, the position in the token stream, and names in RED are case-insensitive, and built-in names like POS aren’t reserved. By every rule, my variable had hidden the built-in function. Later the same thing happened with a record field len, which collided with the .LEN attribute, and later still with a task parameter me that hid the built-in function ME, which returns the current activation. Each time the compiler did what the scoping rules told it to, and each time it took me about five minutes to believe it.

RED has more than fifty reserved words, and some of them are unexpected: TO, CAPSULE, EXPOSE, IMPORTS, READONLY, SUBTYPE. The parser function subtype had to be renamed, and the variable to in the operating system’s client became dest.

RED has no null statement. An empty body is written as empty space, so WHEN DELAY(20) => ; is a syntax error. Later I found the same construct, DELAY_UNTIL (next) => ;, in the solution to the eighth contract problem, even though, according to the Red team, their translator had checked the syntax of all the solutions. Apparently the 1979 translator was more forgiving about this than the diagrams.

Fixed-length strings annoyed me at first, but turned out not to be scary at all: anything that lives longer than a single expression the compiler keeps in pointer strings, and the expressions themselves concatenate strings to their heart’s content.

But the most valuable rule is IMPORTS. While the compiler didn’t check it, I naturally ...