OEP

109

Title

RESULT parameters and abbreviations

Summary

RESULT keyword allows enhanced usage checking for result parameters.

Owner

Fred Barnes <F.R.M.Barnes@kent.ac.uk>

Status

Accepted

Date-Accepted

2001-12-18

Keywords

language result parameters abbreviation occam3

As per the occam-3 specification, parameters and abbreviations may be declared with the RESULT "prefix". The primary purpose of these is to provide more information to the compiler, so it can check that parameters are defined when PROCs return, and that RESULT abbreviations are left defined when they go out of scope.

Syntactically, the RESULT occurs where one might park a VAL, for example:

PROC fac (VAL INT n, RESULT INT v)
  SEQ
    ...
    v := ...
:

PROC thing (...)
  INT v:
  SEQ
    ...
    RESULT INT i IS v:
    fac (6, i)
:

Two different implementations of RESULT abbreviations are supported. The first, and default, treats the abbreviation as one without the RESULT keyword, but performs the additional check (for definedness) when the variable leaves scope, e.g.:

RESULT TYPE a IS v:
P

becomes:

TYPE a IS v:
SEQ
  P
  -- checks that "a" is defined

The second implementation, selected with the "-zrv" compiler flag generates a fresh variable then assigns into it. From the above:

TYPE anon:
SEQ
  TYPE a IS anon:
  P
  -- checks that "a" is defined
  v := anon

Although probably rare, there are cases where this second transformation will ultimately result in more efficient code, especially if "v" is large and non-local (accessed through the static-link).

OEP/109 (last edited 2007-09-27 00:11:30 by ats1)