ALGOL 68RS

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

ALGOL 68RS
Original author(s)I. F. Currie, J. D. Morrison
Developer(s)Royal Signals and Radar Establishment
Initial releaseAugust 1977; 43 years ago (1977-08)
Stable release
algol68toc 1.14 / 25 August 2012; 8 years ago (2012-08-25)
Written inALGOL 68
Operating systemVMS
PlatformICL 2900 Series, Multics, VAX
Available inEnglish
TypeCompiler, translator
LicenseFreeware, public domain (parts)
Websitealgol68.sourceforge.net

ALGOL 68RS is the second ALGOL 68 compiler written by I. F. Currie and J. D. Morrison, at the Royal Signals and Radar Establishment (RSRE).[1] Unlike the earlier ALGOL 68-R, it was designed to be portable, and implemented the language of the Revised Report.

Versions of ALGOL 68RS were written for the ICL 2900 Series, Multics, and VAX running VMS.[2][3]

Subsequently, parts of this compiler were released into the public domain, as a translator from ALGOL 68 to C, as part of the public release of the hardware description language ELLA, also by the RSRE.

History[edit]

Although the ALGOL 68-R compiler, written by I.F. Currie, J.D. Morrison, and S.G. Bond, was a great success, it suffered from two major problems: it had been written for the nearly obsolete ICL 1900 computer, and it implemented an out-of-date version of the language as it was released before the Revised Report on ALGOL 68 was available.

RSRE needed a newer compiler for various internal projects, so the team of Currie and Morrison wrote a new compiler designed for cross-platform software portability between machines. The compiler dealt with the parsing of ALGOL 68, producing a high level intermediate language known as stream language that is then compiled to machine code by a translator. The compiler needed to know only the sizes of the various object machine data types and the character encoding (set) available.

The compiler was written in ALGOL 68, bootstrapped initially using the ALGOL 68-R compiler.

A team of two programmers at Oxford University Computing Services wrote a code generator for the ICL 2900 series.[4] Martyn Thomas of South West Universities Regional Computer Centre (SWURCC) arranged that this system be sponsored by International Computers Limited (ICL) and sold as an official ICL product.[5]

Later, the Avon Universities Joint Computer Centre, a large user of Multics requested the SWURCC team to produce a Multics version of ALGOL 68RS. A version for the Digital Equipment Corporation (DEC) VAX computer was also written.

Eventually the team at SWURCC formed a company, Praxis, initially supporting the Multics version of ALGOL 68RS.

RSRE also used the ALGOL 68RS compiler for internal projects, including the Flex machine and the ELLA hardware design language. When it was decided to make ELLA freely available, Praxis was commissioned to write an ALGOL 68 to C translator named ctrans, based on the ALGOL 68RS compiler.

Restrictions in the language compiled[edit]

Like the earlier ALGOL 68-R compiler, ALGOL 68RS was a one-pass compiler, which required some restrictions on the language compiled.

Declaration before use[edit]

The ALGOL 68 program:

proc even = (int number) bool: ( number = 0 | true | odd (abs (number - 1)));
proc odd = (int number) bool: ( number = 0 | false | even (abs (number - 1)));

would have to be re-written as:

proc (int) bool odd;
proc even = (int number) bool : ( number = 0 | true | odd (abs (number - 1)));
odd := (int number) bool : ( number = 0 | false | even (abs (number - 1)));

To allow recursive declarations of modes (types) a special stub mode declaration was used to inform the compiler that an upcoming symbol was a mode rather than an operator:

mode b,
     a = struct (ref b b),
     b = [1:10] ref a;

Parallel processing[edit]

Like ALGOL 68-R, the operators par clause and the sema mode with its associated up, down, and level, were omitted.

Extensions to ALGOL 68[edit]

Straightening[edit]

One major misfeature of ALGOL 68 is that it is impossible to write the standard transput (input/output) procedures in pure ALGOL 68. The print procedure takes, for example, an array of items to print of any mode and, by a process named straightening, converts them into simple values that can be printed. For example:

struct (int a, real b) c := ...;

print(c);   { magically transformed to print ((a of c, b of c)); }

The writers of ALGOL 68RS decided to make straightening available as part of the language. A straight mode resembles an array but has the special feature that items can be coerced to a straight mode if their components can be coerced to the mode. For example:

struct (int a, real b) c;

straight union (int, real) z = c;

Both the fields of c can be coerced to union (int, real) so the field "a of c" can be accessed as z[1] and "b of c" is z[2].

The standard print procedure can now be declared as:

mode printmode = union (int, real, ... straight printmode);
proc print = ([] printmode arguments ) void: ...;

Efficient array handling[edit]

The ALGOL 68 array modes are very powerful, including multiple dimensions, defined upper and lower bounds, trimming (making a new array by taking a contiguous subset of an array), slicing (making a new array by removing one dimension from an array), and rowing (making a new array by adding a dimension to an extant array.

For example:

[5:23, -7:7] int a;               { a two dimensional array }
ref [,] int b = a [ 6:21, 0:3 ]   { a slice of a }
ref [] int c = a [5]              { just one row of a }

While the compiler made all efforts to generate optimal code for all cases, it was felt that adding some simpler facilities would allow better code in some cases. To this end ALGOL 68RS included indexable structures (i-structs), vectors, and the forall statement.

Indexable structures[edit]

ALGOL 68 already included fixed length structures to efficiently handle characters and bit-data on word-based machines, the bytes and bits modes. A bytes variable held one machine word of characters, a bits variable held the bits of one machine word.

ALGOL 68RS generalised these ideas. A struct 4 char variable held exactly 4 chars. The size was part of the type. On most ALGOL 68RS systems, the mode bytes was equivalent to struct 4 char.

mode bytes = struct 4 char;
op elem = (int index, bytes val) char: val[index];
...
bytes b = "abcd";
...
print (2 elem b);

The ALGOL 68RS compiler would compile any string constant to an appropriate struct n char.

In contexts where a vector or array was wanted, an i-struct could be widened to the appropriate vector or array type.

Vectors[edit]

A vector is a simplified array, with only one dimension and a lower bound fixed at 1.

vector [4] int a;     { similar to [1:4] int a; }

In any context where an array was required a vector could be converted to an array.

FORALL statement[edit]

The forall statement allows efficient stepping through the elements of an array.

[12] int a := ...;

forall xa in a
do xa := xa * 2
od

xa will be a reference to each element of a in turn. forall can step through multiple arrays in parallel, and be controlled by a while clause:

[12] int a, b;
...
forall xa in a,
       xb in b
while xa > xb
do
    f(xa, xb)
od

Separate compiling[edit]

ALGOL 68RS provided a mechanism to build libraries similar to the separate compiling facilities of ALGOL 68-R and a mechanism to build programs in a top-down manner similar to those of ALGOL 68C.

Declaration modules[edit]

Libraries in ALGOL 68RS are written using declaration modules which consist of a sequence of mode, variable, operator and procedure declarations followed by a keep list which defines which declarations are visible to other segments.

The library user then adds a use header that tells the compiler to make the symbols of one or more declaration libraries available to the program.

For example, a graphics library might be written as:

decs graphlib
use some other library

mode graphdata = struct ( ... );
mode graph = ref graphdata;
proc new graph = ( ... ) graph : ...;
proc draw graph = (graph g) void : ...;
   ...

keep graph, new graph, draw graph
finish

And a user program to use this library would look like:

program myprog
use graphlib
begin
    graph g = new graph (...);
    ...
    draw graph (g);
    ...
end
finish

Nested modules[edit]

To support a top-down programming style, ALGOL 68RS provided the here and context facilities.

A program could be written with parts to be filled in later marked by a here tag followed by a keeplist of declarations to be made available.

program (pass1, pass2) compiler
begin
   string source := ...;
   tree parsetree;
...
   here pass1 (source, parsetree);
...
   instructions insts;
   here pass2 (parsetree, insts);
...
end
finish

The code to be executed in the context of the here tags would be written as:

program pass1 implementation
context pass1 in compiler
begin
  ...   { code using "source" and "parsetree" }
end
finish

here is similar to the ALGOL 68C environ and context is equivalent to the ALGOL 68C using.

Code and alien access[edit]

ALGOL 68RS was intended to be usable for low level systems programming. To allow this, facilities were included for access to machine code and non-ALGOL 68RS objects.

Code was inserted with the code construct:

somemode code (item1, item2, ...) "...code..."

Where the items are ALGOL 68RS values to be made available to the code insertion and somemode is the mode returned. The mode can be omitted if the code returns no value.

Access to non-ALGOL68 objects was available with the alien insertion:

somemode name = alien "external-name"

Any simple ALGOL 68RS object could be cast into a vector of characters using the spell operator:

struct (int a, real b) c = ...;

print (("internal repr = ", spell c, newline));

A simple object is one that contains no arrays or vectors.

Availability[edit]

The ALGOL 68 to C translator written by Praxis for the ELLA system contains most of the ALGOL 68RS compiler. The notable exception is the code for handling formats.

As of September 2020, ALGOL 68RS is available from SourceForge.[6]

References[edit]

  1. ^ Bond, S. G.; Woodward, P. M. (August 1977). "Introduction to the 'RS' Portable ALGOL 68 Compiler". Technical Note (802). Archived from the original on 14 December 2012.
  2. ^ Woodward, P. M.; Bond, S. G. (1983). Guide to ALGOL 68 for Users of RS Systems. Edward Arnold (Publishers) Ltd. ISBN 978-0-7131-3490-2.
  3. ^ Lindsey, C. H. (August 1998). "Survey of Viable ALGOL 68 Implementations". ALGOL Bulletin (52): 5–8. ISSN 0084-6198.
  4. ^ "Multics Site History: Avon".
  5. ^ Lindsey, C. H. (December 1980). "ALGOL 68 Implementations: The ICL 2900 Compiler". ALGOL Bulletin (46): 7–8. ISSN 0084-6198.
  6. ^ van der Veer, Marcel; NevilleDNZ. "Open source ALGOL 68 implementations". SourceForge. Retrieved 18 September 2020.