Call Block

To further illustrate the atomic channel communication mechanism, here is an example of a Sutherland-style CALL block:

	use(channels).
	
	call(i1:var(chan(T:type)),i2:var(chan(T)),o:var(chan(T))):expr(void)=(
	
	  forever(
	    i1?(o!?i1)
	  ) |
	  forever(
	    i2?(o!?i2)
	  )
	).
This block contains two concurrent processes, one of which copies values from input 1 to the output and the other copies values from input 2 to the output. In the case when values arrive on inputs 1 and 2 simultaneously the behaviour is undefined - just as in the real hardware.

A variation on the basic call block is an arbitrating call. In this version if both inputs arrive at around the same time the block continues to be well behaved and chooses one nondeterministically. Here is an implementation of this:

	use(channels).
	
	arb_call(i1:var(chan(T:type)),i2:var(chan(T)),o:var(chan(T))):expr(void)=(
	
	  forever(
	    wait_until(chan_ready(i1)||chan_ready(i2));
	    if (chan_ready(i1))
	    then
	      i1?(o!?i1)
	    else
	      i2?(o!?i2)
	  )
	).
The new features in this code are:

The combination of wait_until and chan_ready used here implements a "select" operation on the two input channels.

Note how an implicit type parameter has been used to make the call block generic.

Here is a third example, a checking call block. This has the same behaviour as the basic Sutherland call block, but reports an error message if both channels become active at the same time:

	use(channels).
	
	check_call(i1:var(chan(T:type)),i2:var(chan(T)),o:var(chan(T))):expr(void)=(
	
	  forever(
	    i1?(o!?i1)
	  ) |
	  forever(
	    i2?(o!?i2)
	  ) |
	  (
	    wait_until(chan_ready(i1)&&chan_ready(i2));
	    fatal("Overlapping inputs on CALL block\n")
	  )
	).
Note: this code is not garaunteed to detect the error condition when the block connected to the output of the call has zero delays. This is due to the lack of a "delta delay model" in LARD, and may be fixed in some future version.

Here's an li screenshot showing how the arbitrating call works: