Relaxed Template Examples - The HAC Language
Description: The HAC Language

Up: Template Type Equivalence

#### 9.4.1 Template Examples

The following example illustrates how one might describe a ROM array using relaxed template arguments.

         template <> <pbool VAL>
         defproc ROMcell(...) { ... }

         template <pint X, Y> <pbool V[X][Y]>
         defproc ROMarray(...) {
           ROMcell<> x[X][Y];  // <> is optional
           // can't reference x[i][j].member yet
           // because instance types are incomplete
           (i:X:
             (j:Y: x[i][j] <V[i][j]> (...); )
           )
           // from here, may reference x[i][j].member
         }

         ROMarray <2,3>
             a <{{false,true,false},
               {true,false,true}}>;

This following example shows how one would declare an array of sources (like for a test environment):

         template <pint N>
         defchan e1of (...) {...}

         template <pint N> <pint M; pint V[M]>
         defproc source_e1of (e1of<N> c) {...}

         e1of<4> C[10];
         source_e1of<4> CS[10];  // instances' types are incomplete
         CS[0] <1, {2}> (C[0]);  // can complete types and connect
         CS[1] <3, {2,0,1}> (C[1]);
         CS[2] <2, {1,0}> (C[2]);
         ...

We could have also declared the array of sources with sparse instantiation, as long as the strict template arguments match:

         source_e1of<4> CS[0..0];
           // this determines the entire collection's strict parameters
           // but sets the relaxed parameters for only the indexed range
         CS[0]<1, {2}>(C[0]);
           // This binds the relaxed template parameters and connects ports.
         source_e1of<4> CS[1..1];
         CS[1]<3, {2,0,1}>(C[1]);
         source_e1of<4> CS[2..2];
         CS[2]<2, {1,0}>(C[2]);
         ...

[TODO: write section on connection examples]