Occam (language)

The programming language Occam is a programming language adapted to the parallel architecture, which appeared in 1983. It was developed by Inmos for the programming of its parallel Transputer architectures , but was also used on other platforms.

The name is a tribute to Guillaume d’Occam (sometimes spelled Ockham) and to the methodological principle of Occam ‘s razor .

The Occam language is a procedural language that, besides the execution of instructions sequentially (with SEQ), offers the execution of instructions in parallel (with PAR) and even the “asynchronous parallel” process (with ALT) for A non-deterministic execution of one of several. The execution in PAR of the processes is done with appointments, as in Ada .

Occam also contains the “guarded orders” of Edsger Dijkstra : a process is only launched if the value of its guard, evaluated by the system, is true.

The Inmos Transputer Development System (TDS) was the classic development tool for this language, but it was possible to use Parallel C or other tools. The TDS editor allowed code 1 folding , which was very innovative 2 .

Fundamentals

In Occam the indentation is significant, which avoids the start and end markers of blocks common to other languages ​​inheriting from Pascal and C (begin … end, {…}, loop … endloop etc . ). An expression is terminated by an end of line. Several expressions can be grouped in a block where all lines start at the same indentation.

The communication between parallel processes is done with “channels” defined by the expression “CHAN OF”. These channels are implemented by fast serial bidirectional links (2 Mb / s, 4 links / Transputer, communication independent of the CPU). A process sends data on the channel with “!” While another process receives the data with “?”, The transmission and reception being synchronous:

Keyboard? C
Screen! C

SEQ introduces a list of expressions that are evaluated in sequence, one after the other. Example:

 SEQ ID NO:
 X: = x + 1
 Y: = x * x

PAR announces a list of expressions that are likely to be evaluated simultaneously. Example:

 BY
 P ()
 Q ()

ALT indicates a list of stored instructions . The guards are combinations of conditions and binary input on channel. An alternative among those whose conditions are true and whose input channels are ready, is executed. Example:

 ALT
 Count1 <100 & c1? Data
 SEQ ID NO:
 Count1: = count1 + 1
 Merged! Data
 Count2 <100 & c2? Data
 SEQ ID NO:
 Count2: = count2 + 1
 Merged! Data
 Status? Request
 SEQ ID NO:
 Out! Count1
 Out! Count2

This example will read the data from channels “c1” and “c2” (if they are ready) and merge them into a single “merged” output channel. If countN reaches 100, N-channel playback will be disabled. A query on the state of the channel will have for answer the two counters.

Code examples

Some examples of real code

CHAN OF ANY FromServer, CHAN OF ANY ToServer, CHAN OF ANY FromNetwork, ToNetwork,
 [] CHAN OF Process FromMenu, CHAN OF FilerProtocol FromFiler, ToFiler, [] INT UserWindow, SystemWindow,
 [] INT ConfigData, freespace, VAL [] BYTE parnomfic, parNumVersion, FicSorties, INT FicSortiesPtr)
- Disk Configuration Constants
VAL WrkExt IS ".CPS":
VAL OutExt IS ".LIE":
VAL IntExt IS ". $$$":
VAL MaxCompressedRecordSize IS 45: - size with CGA compression !!!
VAL kAccesSequential IS TRUE:
VAL theta1 IS 1.618 (REAL32):
- Estimated Constants
VAL MaxTailleZone IS 9111833:
VAL MaxVilles2 IS INT ROUND ((REAL32 TRUNC MaxVilles) * theta1):
- Variables
[ReadBufferSize] BYTE MyReadBuffer:
INT FicPos, FicSize: - position in, and number of bytes of the file
[80] BYTE FicRes1,
 FicInt:
- Functions
BOOL FUNCTION EndOfFile () IS ((FicPos + MyReadPtr)> = FicSize):
BOOL FUNCTION NotFini () IS ((Result = 0) AND (NOT EndOfFile ())):
PROC Error (VAL [] BYTE by)
 [82] BYTE loc:
 --BOOL poub:
 --INT len:
 SEQ ID NO:
 --len: = 82
 --InitTabByte (loc, '')
 [Loc FROM 0 FOR (SIZE par)]: = par
 [Loc FROM (SIZE par) FOR 2]: = "* c * n"
 --delete.string (len, loc, (SIZE by) + 2.81 - (SIZE by), poub)
 WriteInTextWindow (ToServer, SystemWindow, [loc FROM 0 FOR (SIZE by) + 2])
 - previously UserWindow

Another example :

IF
 Sgf.res <> 0
 SKIP
 TRUE
 IF
 Compare.strings (ThfareKey, "99999999") <> 0
 SEQ ID NO:
 ThfareKeyInt: = AtoI (ThfareKey)
 ThfareOffsets [ThfareKeyInt]: = Offset
 TRUE
 SKIP

Example of channel multiplexer:

WHILE TRUE
 VAR x;
 SEQ ID NO:
 ALT
 C1? X
 C2? X
 C3? X

Evolution

  • Occam 1 (1983) was a preliminary version, inspired by the work of David May on EPL, and that of Tony Hoare on CSP . This version only allowed one datatype, denoted VAR, designating an integer whose length is the word of the target machine, and one-dimensional tables.
  • Occam 2 (1987) is an operational extension produced by INMOS Ltd; It adds floating point, functions, multi-dimensional tables, and various integer types (BYTE, INT16, INT32). Occam 2 is much more practical and useful, occam 1 keeping an exploratory character; However, since the occam compiler 1 was written in occam 1, this already proved that occam 1 could be sufficient for various applications of modest size.
  • Occam 2.1 (1994) was the last contribution of INMOS, influenced by an earlier proposal by Geoff Garett called occam91 then occam 3;A revised definition of this proposal was circulated for comment, but this opportunity was not fully implemented.It 2.1 introduces in particular:
    • The naming of types (DATA TYPE x IS y)
    • The nomination of articles (normal or compressed)
    • The relaxation of certain conversion rules
    • New operators (eg BYTESIN)
    • Channel charts and their retyping;
    • The possibility for the functions to make a table of imposed size.
  • Occam-π designates the variant of occam proposed by the latest versions of KRoC (for Kent Retargetable occam Compiler). The addition of the symbol “π” (pi) indicates that this occam takes up several ideas of the pi-calculus .It introduces in particular:
    • The imbrication of protocols
    • Dynamic process creation
    • The mobility of channels, data and processes
    • Recursion
    • Inheritance of protocols
    • Table constructors
    • The extension of appointments.

References

  1. ↑ Inmos technical note on TDS  [ archive ]
  2. ↑ http://www.moria.de/~michael/fe/folding.html  [ archive ]
  3. ↑ ( in ) Ericsson-Zenith , occam 2 Reference Manual , Prentice-Hall, ( ISBN  0-13-629312-3 )