Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision |
intro_example:template_deps [2025/05/02 10:06] – rajit | intro_example:template_deps [2025/05/07 18:26] (current) – rajit |
---|
</code> | </code> |
| |
Parameters can be used in expressions as well. For example, the standard memory definition in the ACT standard library is: | 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> | <code act> |
export template<pint N, W> | 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) | defproc ram (chan?(int<2>) rd; chan?(int<std::ceil_log2(N)>) addr; |
| chan?(int<W>) din; chan!(int<W>) dout) |
{ | { |
... | ... |
} | } |
</code> | </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. |
| |
| |