[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: occam: out ! 0 :: "" semantics



Oyvind asks:

> -- In a "ByteStream.PROTOCOL.Tokenizer" I've written to marshal
> -- bytes on the socket stream I/O, I came upon this problem of
> -- what to do when a counted array has zero bytes "to send" off.
> -- In SPoC it seems to do a synchronization and an OUTPUT/INPUT
> -- pair of len zero in the case, and no memcpy.
> 
> -- Obviously we can't send zero bytes over a network, but inside
> -- the SPoC runtime system it's ok to say "here is your zero bytes"
> -- as long as both parts adher to the same protocol.
> --
> -- What does KRoC do?
> 
> PROTOCOL Envelope IS INT :: []BYTE:
> 
> PROC Producer (CHAN OF Envelope out)
  > out ! 0 :: ""
> :
> PROC Consumer (CHAN OF Envelope in)
>   INT len:
>   [100]BYTE data:
>   in ? len :: data
> :
> 
> CHAN OF Envelope chan:
> PAR
>   Producer(chan)
>   Consumer(chan)

KRoC uses the code generator from the transputer compiler as the first
step of compiling - so KRoC does just what the transputer would do with
the above code.

Namely, Producer generates a *single* communication of the 0 (INT) and
Consumer inputs the len (INT) count, tests it for *greater* than zero and -
only if that tests TRUE - does it do a further input (of len bytes).  Of
course, it also tests that len is <= 100, causing an error if that fails.

Peter.