Hei,
However I'm not keen on your syntax, not c or xc enough! So how about an alternate approach
I'm not overkeen on the first draft protocol declaration syntax either. I do like your proposal to use braces for enclosing protocol definitions, with a few thoughts.
You need to be able to write 'chan of type p' and also 'chanend of type p'. One advantage in defining a protocol is to allow re-use over different sources (for example when linking with an object code library), or for communicating with either a remote channel (in a non-local memory system) or a mobile one; for which you need chanend definitions. Another advantage of protocols in chanend definitions is to publish an interface, or a service definition; I explored service definitions using xc and c in the xspi-bus project.
Based on your ideas I would like to suggest a more definitive syntax using braces. In defining a protocol, as before, the case component clearly seperates either elementary types or compound block structure types:
Code: Select all
protocol p
{
case { unsigned char[ 10 ], int }
case int;
}
It is more difficult to get the syntax for declaring a 'chan of type p' right. The first draft led to the ':' syntax, which I agree isn't C-like as the type qualifier is written after the name. But I don't think braces work well as a qualifier either - braces in C define a block structure and 'protocol p' is already defined (so expanding 'c {p} d' becomes 'c {{ ... }} d'). How about writing the obvious thing (borrowing 'chan of' from Occam):
Code: Select all
int main( void )
{
chan of { int, char } c;
chan of p d;
par
{
tx( c );
rx( c );
ptx( d );
prx( d );
}
}
This obvious syntax also works for chanend, and shows why defining a protocol is a good thing; see examples below.
For communication events, in sending and receiving, I think you mean to use braces (as in 'c <: {i, j}') to signify something like an 'atomic action'. But the communication of a compound type (as in the first case in p above) will not happen atomically at runtime - rather it will be a sequence of out operations. And there seems no extra clarity achieved by enclosing the elements to be communicated in braces if the protocol case was defined as an elementary type (as in the second case in p above). So I prefer:
Code: Select all
void tx( chanend of { int, char } c )
{
int i;
char j;
c <: i, j;
}
void rx( chanend of { int, char } c )
{
int i;
char j;
c :> i, j;
}
void ptx( chanend of p d )
{
int x;
unsigned char bytes[ 10 ];
d <: bytes, x;
}
void prx( chanend of p d )
{
int x;
unsigned char bytes[ 10 ];
select
{
case d :> bytes, x;
case d :> x;
}
}
Any thoughts or feedback?