OEP

123

Title

Protocol inheritance

Summary

Allow tagged protocols to inherit tags from other tagged protocols.

Owner

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

Status

Accepted

Date-Accepted

2004-01-04

Keywords

language protocols

Support for protocol inheritance has now been added to the occam compiler. This allows tagged (variant) protocols to inherit tags from others, creating a type-compatibility between them.

For example:

PROTOCOL MOUSE.EVENTS
  CASE
    mouse.x.y; INT; INT
    mouse.down; INT
    mouse.up; INT
:

PROTOCOL KEY.EVENTS
  CASE
    key.down; INT; INT
    key.up; INT; INT
:

PROTOCOL GFX.EVENTS EXTENDS MOUSE.EVENTS, KEY.EVENTS
  CASE
    gen.error; INT
:

This can be used in the expected way. Given the set of PROCs:

PROC graphics.server (CHAN GFX.EVENTS in?)
PROC mouse.driver (CHAN MOUSE.EVENTS out!)
PROC keyboard.driver (CHAN KEY.EVENTS out!)

We can wire them up this way:

CHAN GFX.EVENTS c:
PAR
  mouse.driver (c!)
  graphics.server (c?)

or this way:

CHAN KEY.EVENTS c:
PAR
  keyboard.driver (c!)
  graphics.server (c?)

These show the two allowed ways of using protocol inheritance. There are two others which are not legal, however, and are banned by the compiler.

In the first example, there would normally be a type incompatability in the instance of "mouse.driver", since a channel of a different type is passed as a parameter. However, since "GFX.EVENTS" (actual type) includes all the tags of "MOUSE.EVENTS" (formal type), anything that "mouse.driver" outputs is potentially handled (by a process that inputs "GFX.EVENTS").

In the second example, the incompatability is the instance of "graphics.server". A similar logic as before applies, however. The "graphics.server" process accepts (potentially) any of the "GFX.EVENTS", of which "KEY.EVENTS" are a subset.

The two invalid cases are substantially less natural. Assuming there was:

PROC mouse.handler (CHAN MOUSE.EVENTS in?)
PROC graphics.plex ([]CHAN GFX.EVENTS in?, CHAN GFX.EVENTS out!)

Then:

CHAN MOUSE.EVENTS c:
PAR
  graphics.plex (..., c!)
  mouse.handler (c?)

and

CHAN GFX.EVENTS c:
PAR
  graphics.plex (..., c!)
  mouse.handler (c?)

are illegal. In the first, for example, an attempt is made to connect a channel of "MOUSE.EVENTS" to a process that outputs any "GFX.EVENTS", of which "MOUSE.EVENTS" are possibly only a subset -- i.e. "graphics.plex" could output something that couldn't be handled by "mouse.handler". And that makes good sense. The second example is similar, but with the error being at the other end of the channel (an attempt to connect an input channel carrying potentially any "GFX.EVENTS" to a process that can only handle "MOUSE.EVENTS").

There are several restrictions associated with protocol inheritance, that are largely technical. The compiler will abort when it finds cases that it can't handle.

OEP/123 (last edited 2007-09-27 00:36:09 by ats1)