Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
intro_example:template_deps [2025/05/02 10:04] rajitintro_example:template_deps [2025/05/07 18:26] (current) rajit
Line 25: Line 25:
   out!1; out!3; out!5   out!1; out!3; out!5
 </code> </code>
 +
 +Dependent templates have //left to right// evaluation order. In the example above this means that ''t.N'' is created and assigned value ''3'', and then after that the value of ''t.N'' can be used to infer the type of ''pint d[N]''. Switching the order would result in an error:
 +<code act>
 +template<pint data[N]; pint N> defproc test(chan!(int) out);
 +</code>
 +<code>
 +-[ERROR]-> The identifier `N' does not exist in the current scope
 +</code>
 +
 +
 +Parameters can be used in expressions as well. For example, the memory definition in the [[stdlib:start|ACT standard library]] is:
 +<code act>
 +export template<pint N, W>
 +defproc ram (chan?(int<2>) rd; chan?(int<std::ceil_log2(N)>) addr;
 +             chan?(int<W>) din; chan!(int<W>) dout)
 +{
 +  ...
 +}
 +</code>
 +The first template parameter ''N'' corresponds to the number of elements in the memory, and ''W'' corresponds to the bit-width of the data in the memory. The bit-width of the address channel ''addr'' is computed from ''N'' by a standard library parameter function that is used to compute the smallest number of address bits needed to be able to hold the address values.
 +