Newsgroups: comp.sys.transputer
From: jdd@aiki.demon.co.uk (Jim Dixon)
Subject: An occam query
Organization: AIKI Parallel Systems Ltd
Date: Tue, 14 Jun 1994 19:38:26 +0000
Message-ID: <771622706snz@aiki.demon.co.uk>

wgd@ukc.ac.uk (Warren Day) writes
> Does anyone have any light to throw on this problem of automated type
> measurement in occam?
>
> I'm trying to write something like,
>
> []BYTE packet
>   ...
>   INT value RETYPES [packet FROM 0 FOR bytes.in.an(INT) ]:
>   value := expr
>
> I've tried,
>
>   INT value RETYPES [packet FROM 0 FOR (SIZE INT) ]:
>   value := expr
>
> but the compiler complains,
>
> Error 2017:13 Monadic operator INT and operand not in parentheses

The SIZE operator expects a structure as an operand; INT is a type.
The procedure below will compile correctly:

PROC junk(CHAN OF ANY InChan)
  [512]BYTE packet:
  INT offset, val:
  SEQ
    InChan ? offset
    INT ValInPacket RETYPES [packet FROM offset FOR 4]:
    val := ValInPacket
:

However, this may not return the value that you expect.  The transputer
calculates the byte offset of ValInPacket by adding the value of offset
to the byte offset of packet; this sum is not guaranteed to be aligned.
The transputer ignores the two low order address bits and fetches
the integer at (in C terminology)
	(int *) ( (offset + (int)&packet) & 0xfffffffd)

This can lead to very puzzling errors!
-- 
+------------------------------------+---------------------------------------+
|  Jim Dixon<jdd@aiki.demon.co.uk>   |       Compuserve: 100114,1027         |
| AIKI Parallel Systems Ltd + parallel processing hardware & software design |
|             voice +44 272 291 316  | fax +44 272 272 015                   |
+------------------------------------+---------------------------------------+

