use(channels).The operations declared by this library are similar to those provided by Tangram and Occam.
Here is the declaration of a block with two ports, i and o. It reads a value from i, waits for 10 time units, and sends the incremented value to port o:
incblock(i:var(chan(int)),o:var(chan(int))):expr(void)=( v:var(int). forever( i?(v:=?i); wait_for(10); o!(v+1) ) ).The main program declares two channels and instances two of these incrementer blocks to join them in a ring. Finally it sends an initial value to one of the channels to start the system running:
C1:var(chan(int)). C2:var(chan(int)). init_chan(C1,"C1"); init_chan(C2,"C2"); ( incblock(C1,C2) | incblock(C2,C1) | C1 ! 0 )
Within the body expression the received value can be read using the expression ? channel.
i ? ( o ! ?i )
i ? ( v:=?i ) ; o ! vIn the first case the block sending to channel i cannot continue until after the block receiving from channel o has completed receiving - there is no pipeline stage within the code shown. In the second example the varaible v explicitly describes a pipeline latch allowing the sender to i to continue as soon as the value has been latched. Tangram and Occam allow only the latter style of description.
To observe activity on the channels during execution you can use li's channel viewer display. Invoke this by adding the module name channels to the li command line.
ernie$ lcd -lchannels -ltime -O incchan.l ernie$ li incchan.bcode channelsThree windows appear; the main window for I/O interaction, the Selector window and the Time View window. Running the simulation (Simulation->Run from the main window menubar) causes the structure of the program to be displayed in the Selector window:
This display shows the hierarchy of the program (not very complex in this case). advance_time is an internal process that can be ignored. The names of the two channels, C1 and C2, are displayed. Alongside their names are buttons that enable their display on the time view window.
The triangular buttons can be used to hide regions of the structure that are not of interest.
After enabling the display of C1 and C2 and scrolling the Time View window right to show the new data that window appears something like this:
To the right of the channel name is a symbol which conceals a pop-up menu. This menu provides facilities to hide, delete, and reformat the display of that channel. Deleting and hiding a channel both remove the channel from the display, but a hidden channel can be recalled using the Unhide menu and its data will be intact. Information about a deleted channel is discarded.
The coloured rectangles in the trace display give information about the timing of the communications - this is described in another example. The actual values that are transfered chan be shown by enabling either Show Data or Show Blobs from the pop-up menu. Enabling Show Data displays all values which can look rather cluttered in some cases. Show Blobs displays a red blob for each value, and pointing at this shows the data value in a transient window as shown in the following screenshot: