Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
intro_example:chp_fifo2 [2025/04/21 23:18] – [Dynamic creation of buffers] rajit | intro_example:chp_fifo2 [2025/05/01 10:47] (current) – [Alternate Buffer] rajit | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Alternate Buffer ====== | ====== Alternate Buffer ====== | ||
- | We start with the previous definition | + | We start with the earlier example |
<code act> | <code act> | ||
Line 121: | Line 121: | ||
Each '' | Each '' | ||
+ | |||
+ | Note that when connecting to ports, you can leave connections dangling and then refer to them later. | ||
+ | For example, the following avoids using the extra channel array. | ||
+ | |||
+ | <code act> | ||
+ | template< | ||
+ | defproc buffer (chan?(int) L; chan!(int) R) | ||
+ | { | ||
+ | | ||
+ | (i : N : | ||
+ | | ||
+ | [ i = 0 -> b[i](.L=L); | ||
+ | [] i = N-1 -> b[i](.L=b[i-1].R, | ||
+ | [] else -> b[i](.L=b[i-1].R); | ||
+ | ] | ||
+ | ) | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ... which may be easier to read as follows: | ||
+ | |||
+ | <code act> | ||
+ | template< | ||
+ | defproc buffer (chan?(int) L; chan!(int) R) | ||
+ | { | ||
+ | | ||
+ | (i : N : | ||
+ | | ||
+ | [ i = 0 -> b[i].L=L; | ||
+ | [] i = N-1 -> b[i](.L=b[i-1].R, | ||
+ | [] else -> b[i].L=b[i-1].R; | ||
+ | ] | ||
+ | ) | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | This version is similar to the original version we started with. | ||