Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
language:types [2022/05/13 08:32]
rajit
language:types [2023/04/09 19:55] (current)
rajit [Parameterized types]
Line 208: Line 208:
 brackets, as shown below: brackets, as shown below:
  
-<code>+<code act>
 int<1> x; // x is a one bit integer int<1> x; // x is a one bit integer
 int<37> y; // y is a thirty-seven bit integer int<37> y; // y is a thirty-seven bit integer
Line 219: Line 219:
 being sent and received on the channel. being sent and received on the channel.
  
-<code>+<code act>
 chan(bool) x; // x is a Boolean channel chan(bool) x; // x is a Boolean channel
 chan(int<16>) y; // y is a 16-bit integer channel chan(int<16>) y; // y is a 16-bit integer channel
Line 226: Line 226:
 The default data type for a channel is assumed to be the default The default data type for a channel is assumed to be the default
 ''int'', namely ''int<32>''. ''int'', namely ''int<32>''.
 +
 +Channels are almost always unidirectional, with data being transferred from sender to receiver.
 +In a few cases, it is useful to be able to transfer data from the sender to the receiver, and from the
 +receiver to the sender in one channel action. To declare a channel where data are transferred in
 +both directions, use:
 +<code act>
 +// a bool is transferred from sender to receiver, and
 +// an int is transferred from the receiver to the sender
 +chan(bool,int) x;
 +</code>
 +These are sometimes called //exchange channels//, since data is exchanged between the sender and receiver.
 +
  
 Another built-in data type is the //enumeration// type. An Another built-in data type is the //enumeration// type. An
Line 231: Line 243:
 restricted range. restricted range.
  
-<code>+<code act>
 enum<5> x; // x can take on values 0, 1, 2, 3, 4 enum<5> x; // x can take on values 0, 1, 2, 3, 4
 </code> </code>
Line 248: Line 260:
 type can be defined, and they are shown below: type can be defined, and they are shown below:
  
-<code>+<code act>
 bool x;  // Boolean that may be read or written bool x;  // Boolean that may be read or written
 bool! y; // Boolean that must be written, and may be read bool! y; // Boolean that must be written, and may be read
Line 263: Line 275:
 output on ''c''. output on ''c''.
  
-<code>+<code act>
 defcell nand2 (bool? a, b; bool! c) { ... } defcell nand2 (bool? a, b; bool! c) { ... }
 </code> </code>
Line 270: Line 282:
 different. different.
  
-<code>+<code act>
 chan(int) x;  // Sends or receives are permitted chan(int) x;  // Sends or receives are permitted
 chan!(int) y; // Only sends permitted chan!(int) y; // Only sends permitted