The great-grandfather of Oberon: Algol60 running on LuaJIT

Algol 60 is the mother of nearly all imperative programming languages in existence today. I started to implement a compiler a few years ago at the 60th anniversary of the language. Meanwhile I spent a lot of time with experiments and implementation variations of intermediate languages and backends, from my Oberon to my recent Micron compiler. Micron has an IR which I derived from the DotNet (ECMA 335) CIL which I used for my Oberon+ compiler. For the Algol compiler I derived a new IR from Micron which is better suitable for the LuaJIT backend and which will allow me to implement the Simula 67 compiler which is in the making since 2020 as well.

In case anyone is interested, here is the project: GitHub - rochus-keller/Algol60: Algol 60 compiler with reusable intemediate representation (AIR) and LuaJIT backend, written in C++98/Qt5 · GitHub

There are precompiled versions for Linux x64 and Windows x86.

6 Likes

How does the new ALGOL 60 compare to the Compilers of the mid 60’s?

There are quite many differences, e.g. my new compiler accepts UTF-8 sources supporting the special “publication characters” directly, but also the other alternative representations. The LuaJIT backend is also special; the traditional compilers generated platform dependent machine code; my compiler and the generated code on every platform supported by LuaJIT. There are much more differences when you look into the details, let alone the completely different hardware and OS situation we have today. But it’s the same language, even considering the revisions. Since Algol didn’t define the full I/O feature scope, existing code cannot be expected to run on other compilers without modifications. I tried to support the I/O features expected by the testcode at hand. So if you have old Algol code, it’s worthwhile to try to run it; you likely need a character conversion, and maybe replace some I/O stuff.

2 Likes

I don’t think anything is truly portable. I have this IBM 709 sitting in the loft here:)
How do you enter the UTF-8 source? Do you have Keyboard driver or use a editor language
configurable?
From what little I have seen,I/O tended to magnetic or paper tape. One never wrote Algol
programs, just the compiler.

Ok, I see, that’s indeed not well portable :wink:
I had two microvaxes for many years (the small rack versions) and even tried to use them for my AI and music projects (using VAX Lisp), but they were far too loud and had a bad latency.

How do you enter the UTF-8 source?

If you have Linux or Windows, the text editor usually stores UTF-8 format. Or they offer at least an option where you can select the format. If you only use ASCII characters, the result is the same. But if you copy/paste the posh Algol symbols, then you don’t get around it.

I/O tended to magnetic or paper tape

There is e.g. outinteger or outreal as the modified report added them which usually print to the terminal. But there were also compilers which offered newline or space, for which I had to implement a more dynamic function registration.

I think it was wise choice not to have a standard IO, because back then you did not have a operating
system like today.

For a language intended to support portable executable programs, I think Simula 67 made the better choice. Algol 60’s omission was understandable as a way of keeping an algorithmic notation independent of particular machines, but the lack of a modern operating system was not a technical necessity for omitting standard I/O. Section 1.3.7 of the 1968 Simula Common Base Language says “ALGOL 60 has been seriously affected by the lack of standardized input/output and string handling. Also, a general purpose programming language should have great flexibility in these areas. Consequently, input/output are defined and made a standardized part of SIMULA 67.” Already In 1964, an ACM proposal and an IFIP WG 2.1 report added Algol 60 input/output conventions (i.e. the “outinteger”, “outreal”, etc. mentioned above), which eventually appeared in the “Modified Report” in 1976. The latter states in its Introduction chapter: “In 1972 a version of the Revised Report, together with the various proposals on subsets and input/output, was published by the International Organization for Stan­dardization as ISO Recommendation 1538 [ISO], but IFIP refused to recognise this document as valid.” So even the Algol people recogniced the issue, but eventually had more than ten years to get to a generally accepted standard.

1 Like

I guess, having standard I/O in the late 1950s (1958/59) would have been much too ambitious given how this would have been targeting what was mostly one-off machines or rather limited production runs. Moreover, Algol is really more an executable description language than a well-defined programming language for a particular platform. There’s a hierarchy of reference language, publication language and hardware representation. Regarding I/O, the “hardware group” (which detected various issues regarding implementation, which lead to the 1960 revised report) was apparently working with paper tape, which wasn’t necessarily available for a given machine. The workaround to this was to add specific implementation rules that defined the hardware representation for each installation. As stated at the beginning of the Revised Report.

Each of these must by accompanied by a special set of rules for transliterating from publication or reference language.

(Meaning, as a programming language, the definition of Algol is necessarily incomplete.)

If I recall this correctly, Simula 67 solved this by acting on input and output buffers (SYSIN.IMAGE and SYSOUT.IMAGE, respectively), which will be filled and outputted/flushed as needed by calls to INIMAGE and OUTIMAGE, generally presuming punched cards as the working model. Notably, any specifics would be contained to the classes SYSIN and SYSOUT.

Algol 60 is only my intermediate towards a Simula 67 implementation which I assume will be ready in two or three month (I need to write the code generator which translates the AST to my Algol IR).

I think we need to replace the hardware group! The last time I saw paper tape was on a PDP-8/S :slight_smile:
If Simula 67 came out around the late 60’s did machines start to have ample core memory for things
like I/O buffers, so that made sense.
With the IBM 360 becoming the standard main frame you also got byte’s even if not ASCII,
thus a more modern back end.

The PDP-8 would have been strikingly futuristic! :slight_smile:
(Mind that the hardware group was evaluating the original 1958 proposal of the language, which happened in 1958/59. This was still before the first PDP-1 production prototype became available and eventually went to BBN in late 1960. While this may be up to personal taste, I think the paper tape reader looks great on the PDP-1. :slight_smile: )

1 Like

Who or what was BBN?

That’s a pretty easy web search and leads happily to @NoLand’s pages here.

Among other things, the folks who devised ARPANET and delivered the code for it.
(Originally, BBN, in full Bolt, Beranek and Newman, was a psycho-acoustics firm located in Cambridge, MA. Leo Baranek, one of the founders, did the original acoustic design for the Amy Fisher Hall in NY, nowadays the David Geffen Hall. Before JCR Licklider became ARPA’s first IPTO director, he was vice president at BBN, which is also how and where he became acquainted with computing. For our purpose, BBN was much like DEC’s “bridgehead” into the “real world”. They are pretty important for various things that shaped computing as we know it. They are also the party who’s comment was requested in the RFCs that define the Internet.)

FILECOMP (predecessor/fundamental ideas of MUMPS, see GitHub - rochus-keller/MUMPS: A faithful implementation of the 1976 MUMPS standard plus some DEC MUMPS-11 Extensions · GitHub) came originally from BBN, also what later became INTERLISP, and Papert’s Logo which later influenced Smalltalk.

Small world! I’m working on something very similar right now, with IMP, which is very similar to Algol60 except for passing parameters by reference rather than name.

I had previously started a translation project for IMP to C that was targeted at producing readable maintainable C and did the whole stack from parsing through AST to C generation, but I had got a bit bogged down in some of the details concerning data types and pointers. So I decided, relatively recently, to pivot and work on an alternative translator of just the Imp77 variant of IMP, using the intermediate code produced by the first pass of an original-era Imp77 compiler as the starting point and not worrying as to whether the produced C was readable or maintainable. Since the intermediate code was semi-compiled to a lower level, the problems that I had got stuck on, in my high-level IMP to C, were no longer relevant.

This turned out to be a wise decision because after just a few weeks I’ve now got translations that cover the majority of language constructs and can output object code via the GCC back end for multiple architectures. Code that works and looks pretty efficient - indeed more efficient than the equivalent original era compilers could have produced.

Here’s an example extract from the VAX/VMS Imp77 compiler:

1052       key = kdict(sym)
                                    movl	4(%ebp), %edx
                                    movl	68(%edx), %edx
                                    movzwl	77628(%edx,%eax,2), %edx
                                    movswl	%dx, %ecx
                                    movl	%ecx, KEY.6560@GOTOFF(%ebx)

1053       %IF key&3 = 0 %AND symtype = 2 %START;            !keyword
                                    testb	$1, %dl
                                    jne	.L191
                                    cmpl	$2, SYMTYPE.6071@GOTOFF(%ebx)
                                    je	.L203

1054          %IF sym = 'C' %AND current char = nl %START;     !%C...
                                    .L191:
                                    cmpl	$67, %eax
                                    jne	.L168
                                    movl	CURRENTCHAR.6126@GOTOFF(%ebx), %eax
                                    cmpb	$10, (%eax)
                                    jne	.L168

1055             get next source char;  cont = '+';  ->s1
                                    call	GETNEXTSOURCECHAR.6603
                                    movl	$43, CONT.6074@GOTOFF(%ebx)
                                    jmp	.L170

1056          %FINISH
                                    .LVL202:
1057       %ELSE
                                    .L202:
1058          symtype = key&3-2
                                    andl	$3, %edx
                                    subl	$2, %edx
                                    movl	%edx, SYMTYPE.6071@GOTOFF(%ebx)
                                    .L168:
1059       %FINISH
1060       %RETURN
                                    jmp	.L168
                                    .L203:
1061    %FINISH

I’ll put the translator on github when it’s finished and properly tested. It’s all written in C but uses some GCC language extensions to simplify code generation.

G

1 Like

There are quite many differences, e.g. my new compiler accepts UTF-8 sources supporting the special “publication characters” directly, but also the other alternative representations.

Have you run my UTF8 test suite of Algol 60 code through it? uparse/tests-out at main · gtoal/uparse · GitHub (those are after canonicalisation; the input files are in uparse/tests at main · gtoal/uparse · GitHub )

I had a quick look at your grammar and you’ve covered the official spec but you might find that quite a lot of the code out there uses alternative representations that I don’t see mentioned in your grammar, and even a few language extensions. I think I’ve identified most of them (except for some variants of Algol that are so far from Algol60 that it’s dubious even calling them Algol :slight_smile: ) so if you want to have a quick eyeball of my own reconstructed grammar at uparse/algol60.g at main · gtoal/uparse · GitHub you might find some useful odds and ends in there!

Thanks for the hints and the test code.

a lot of the code out there uses alternative representations that I don’t see mentioned in your grammar

I even have test code in my corpus which doesn’t compile. My intention was to implement the specs and run a decent number of programs to validate the IR.