# Occam 2 Reference Manual

First published 1988 by Prentice Hall International (UK) Ltd.

ISBN-10: 0-13-629312-3

INMOS document number: 72-OCC-45-01

141 Pages

© INMOS Limited 1988. INMOS reserves the right to make changes in specifications at any time and without notice. The information furnished by INMOS in this publication is believed to be accurate; however, no responsibility is assumed for its use, nor for any infringement of patents or other rights of third parties resulting from its use. No license is granted under any patents, trademarks or other rights of INMOS.

## Preface

The occam programming language is a high level language, designed to express concurrent algorithms and their implementation on a network of processing components.

The occam reference manual serves to provide a single reference, and definition of the language occam. The manual describes each aspect of the language, starting with the most primitive components of an occam program, and moving on to cover the whole language in detail. The manual is addressed to the wider audience, including not only the computer scientist, software engineer and programmer, but also the electronics engineer and system designer.

Programming in occam is easy. occam enables an application to be described as a collection of processes, where each process executes concurrently, and communicates with other processes through channels. Each process in such an application describes the behaviour of a particular aspect of the implementation, and each channel describes the connection between each of the processes. This approach has two important consequences. Firstly, it gives the program a clearly defined and simple structure. Secondly, it allows the application to exploit the performance of a system which consists of many parts.

Concurrency and communication are the prime concepts of the occam model. occam captures the hierarchical structure of a system by allowing an interconnected set of processes to be regarded as a unified, single process. At any level of detail, the programmer is only concerned with a small, manageable set of processes.

occam is an ideal introduction to a number of key methodologies in modern computer science. occam programs can provide a degree of security unknown in conventional programming languages such as C, FORTRAN or Pascal. occam simplifies the task of program verification, by allowing application of mathematical proof techniques to prove the correctness of programs. Transformations, which convert a process from one form to a directly equivalent form, can be applied to the source of an occam program to improve its efficiency in any particular environment. occam makes an ideal language for specification and behavioural description. occam programs are easily configured onto the hardware of a system or indeed, may specify the hardware of a system.

The founding principle of occam is a minimalist approach which avoids unnecessary duplication of language mechanism, and is named after the 14th century philosopher William of Occam who proposed that invented entities should not be duplicated beyond necessity. This proposition has become known as "Occam's razor".

The occam programming language arises from the concepts founded by David May in EPL (Experimental Programming Language) and Tony Hoare in CSP (Communicating Sequential Processes). Since its conception in 1982 occam has been, and continues to be under development at INMOS Ltd, in the United Kingdom, under the direction of David May. The development of the INMOS transputer, a device which places a microcomputer on a single chip, has been closely related to occam, its design and implementation. The transputer reflects the occam architectural model, and may be considered an occam machine. occam is the language of the transputer and as such, when used to program a single transputer or a network of transputers, provides the equivalent efficiency to programming a conventional computer at assembler level. However, this manual does not make any assumptions about the hardware implementation of the language or the target system.

occam is a trademark of the INMOS group of companies.

## Contents

Contents overview Preface Introduction Syntax and program format 1 Primitive processes 1.1 Assignment 1.2 Communication 1.2.1 Input 1.2.2 Output 1.3 SKIP and STOP 2 Combining processes 2.1 Sequence 2.1.1 Replicated sequence 2.2 Conditional 2.2.1 Replicated conditional 2.3 Selection 2.4 Loop 2.5 Parallel 2.5.1 Replicated parallel 2.6 Alternation 2.6.1 Replicated alternation 3 Data types 3.1 Data types Rounding of real values 3.1.1 Arrays 3.2 Literals 3.3 Variables 4 Channels 4.1 Channel type 4.2 Declaring a channel 4.3 Channel protocol 4.3.1 Simple protocols 4.3.2 Naming a protocol 4.3.3 Sequential protocol 4.3.4 Variant protocol Input on a channel with variant protocol Variants in alternatives 4.3.5 Anarchic protocol 5 Timers 5.1 Timer type 5.2 Declaring a timer 5.3 Timer input 6 Arrays and elements 6.1 Data type arrays 6.2 Channel arrays and timer arrays 6.3 Elements 7 Expressions 7.1 Tables 7.2 Operations 7.2.1 Arithmetic operators Rounding the results of real operations 7.2.2 Modulo arithmetic operators 7.2.3 MOSTPOS and MOSTNEG (integer range) 7.2.4 Bit operations 7.2.5 Shift operations 7.2.6 Boolean operations 7.2.7 Relational operations AFTER (later than) 7.2.8 SIZE (number of components in an array) 7.3 Data type conversion 8 Scope 8.1 Names in the scope of parallel constructs 9 Abbreviation 9.1 Abbreviation of expressions 9.2 Abbreviation of elements 9.3 Disjoint arrays in parallels 10 Procedures 11 Functions Appendices A Configuration A.1 Execution on multiple processors A.2 Execution priority on a single processor A.2.1 Priority parallel A.2.2 Priority alternation A.3 Allocation to memory B Ports C Usage rules check list C.1 Usage in parallel C.2 The rules for abbreviations C.3 The rules for procedures C.4 The rules for value processes and functions D Mapping types E Invalid processes F Rounding errors G Syntax summary G.1 Syntax in context G.1.1 Processes G.1.2 Construction G.1.3 Replicator G.1.4 Types G.1.5 Literal G.1.6 Declaration G.1.7 Protocol G.1.8 Timer access G.1.9 Element G.1.10 Expression G.1.11 Abbreviation G.1.12 Scope G.1.13 Procedure G.1.14 Function G.1.15 Configuration G.2 Ordered syntax H Keywords and symbols I Character set J Standard libraries J.1 Multiple length integer arithmetic functions J.2 Floating point functions J.3 Full IEEE arithmetic functions J.4 Elementary function library J.5 Value, string conversion procedures K Floating point functions K.1 Not-a-Number values K.2 Absolute K.3 Square root K.4 Test for Not-a-Number K.5 Test for Not-a-Number or infinity K.6 Scale by power of two K.7 Return exponent K.8 Unpack floating point value K.9 Negate K.10 Copy sign K.11 Next representable value K.12 Test for orderability K.13 Perform range reduction K.14 Fast multiply by two K.15 Fast divide by two K.16 Round to floating point integer L Multiple length arithmetic functions L.1 The integer arithmetic functions L.2 Arithmetic shifts L.3 Word rotation M IEEE floating point arithmetic M.1 ANSI/IEEE real comparison N Elementary function library N.1 Logarithm N.2 Base 10 logarithm N.3 Exponential N.4 X to the power of Y N.5 Sine N.6 Cosine N.7 Tangent N.8 Arcsine N.9 Arccosine N.10 Arctangent N.11 Polar Angle N.12 Hyperbolic sine N.13 Hyperbolic cosine N.14 Hyperbolic tangent N.15 Pseudo-random numbers O Value, string conversion routines O.1 Integer, string conversions O.2 Boolean, string conversion O.3 Real, string conversion P Glossary of terms Index