Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
language:impl [2021/11/21 12:36] rajit [Implementation] |
language:impl [2023/04/09 18:06] (current) rajit [Overrides] |
||
---|---|---|---|
Line 38: | Line 38: | ||
A more interesting option is to use the implementation relationship | A more interesting option is to use the implementation relationship | ||
- | between two user-defined types. | + | between two user-defined types. |
an existing type. If type '' | an existing type. If type '' | ||
basic rule is that one can use '' | basic rule is that one can use '' | ||
Line 45: | Line 45: | ||
detail below. | detail below. | ||
- | ==== Refinement | + | ==== Aspects of the implementation relation |
When a user defined type implements another, there are several items | When a user defined type implements another, there are several items | ||
Line 59: | Line 59: | ||
port list. As an illustration, | port list. As an illustration, | ||
- | < | + | < |
defproc type1 (bool a, b) { ... } | defproc type1 (bool a, b) { ... } | ||
defproc type2 <: type1 (bool c) { ... } | defproc type2 <: type1 (bool c) { ... } | ||
Line 72: | Line 72: | ||
the port list example above. | the port list example above. | ||
- | < | + | < |
template< | template< | ||
defproc type1 (bool a, b) { ... } | defproc type1 (bool a, b) { ... } | ||
Line 82: | Line 82: | ||
However, we can also define '' | However, we can also define '' | ||
- | < | + | < |
template< | template< | ||
defproc type1 (bool a, b) { ... } | defproc type1 (bool a, b) { ... } | ||
Line 103: | Line 103: | ||
as follows: | as follows: | ||
- | < | + | < |
type2< | type2< | ||
// x.N, x.M are both accessible! | // x.N, x.M are both accessible! | ||
Line 113: | Line 113: | ||
the instance | the instance | ||
- | < | + | < |
type2< | type2< | ||
// x.M=5, x.N=7 | // x.M=5, x.N=7 | ||
</ | </ | ||
- | would set '' | + | would set '' |
- | '' | + | '' |
the following would be an error: | the following would be an error: | ||
- | < | + | < |
template< | template< | ||
template< | template< | ||
+ | </ | ||
+ | < | ||
-[ERROR]-> | -[ERROR]-> | ||
| | ||
Line 134: | Line 136: | ||
consider the following example: | consider the following example: | ||
- | < | + | < |
defproc buffer (e1of2? l, e1of2! r) | defproc buffer (e1of2? l, e1of2! r) | ||
{ | { | ||
Line 149: | Line 151: | ||
define a specific implementation as follows: | define a specific implementation as follows: | ||
- | < | + | < |
defproc wchb <: buffer () | defproc wchb <: buffer () | ||
{ | { | ||
Line 167: | Line 169: | ||
specification for a buffer at the CHP level of abstraction would be: | specification for a buffer at the CHP level of abstraction would be: | ||
- | < | + | < |
defproc buffer (chan? | defproc buffer (chan? | ||
{ | { | ||
Line 191: | Line 193: | ||
implementation of the original. The syntax for this is shown below: | implementation of the original. The syntax for this is shown below: | ||
- | < | + | < |
defproc wchb <: buffer() | defproc wchb <: buffer() | ||
+{ e1of2 l, r; } // override block | +{ e1of2 l, r; } // override block | ||
Line 210: | Line 212: | ||
only syntax permited is of the form within an override block is | only syntax permited is of the form within an override block is | ||
- | < | + | < |
+{ | +{ | ||
type list-of-ids; | type list-of-ids; | ||
Line 243: | Line 245: | ||
representation of the Boolean variable. | representation of the Boolean variable. | ||
+ | === Overriding conditional instances and templated types === | ||
+ | An instance created in a type definition may be created only under certain circumstances. | ||
+ | This can occur in templated types, where template parameters can affect the instances within the type. | ||
+ | The override block has the simple syntax shown above. However, to account for conditional instances, | ||
+ | the override block directives implicitly check if the instance exists before applying the override. (Note that | ||
+ | ACT does not permit different types for the same instance name under different conditions.) | ||
+ | When a type is being overridden by another, the new implementation may have additional template parameters. | ||
+ | The override syntax above requires the complete list of template parameters to be specified. Instead, we also | ||
+ | provide a single extension override syntax | ||
- | ===== The ptype ===== | + | <code act> |
- | + | +{ | |
- | **XXX: this section not yet implemented** | + | type< |
- | + | ... | |
- | The special '' | + | } |
- | into a process definition. These types can be used to build a process | + | |
- | using other processes as building blocks. The syntax for using a | + | |
- | '' | + | |
- | + | ||
- | <code> | + | |
- | ptype(foo) x; | + | |
</ | </ | ||
- | + | The '' | |
- | This says that '' | + | |
- | constraint | + | |
- | '' | + | |
- | operations supported by type '' | + | |
- | + | ||
- | '' | + | |
- | following example: | + | |
- | + | ||
- | < | + | |
- | // A constructor for a datapath with W-bit ripple connections, | + | |
- | // where each component has M inputs and one output | + | |
- | + | ||
- | // A skeleton | + | |
- | template< | + | |
- | defproc bitslice (e1of2? rin[W]; e1of2! rout[W]; | + | |
- | e1of2? in[M]; e1of2! out) { } | + | |
- | + | ||
- | // the constructor | + | |
- | template< | + | |
- | defproc build_dpath (e1of2? rin[W]; e1of2! rout[W]; | + | |
- | | + | |
- | { | + | |
- | t x[N]; | + | |
- | + | ||
- | // ripple connections | + | |
- | | + | |
- | | + | |
- | | + | |
- | + | ||
- | // i/o connections | + | |
- | | + | |
- | x[i].out=out[i] ) | + | |
- | } | + | |
- | + | ||
- | // A one-bit adder | + | |
- | defproc onebit (e1of2? in[2], rin[1]; e1of2! out, rout[1]) { ... } | + | |
- | + | ||
- | defproc ripple_adder (e1of2? a[32], b[32], cin; e1of2! out[32], cout) | + | |
- | { | + | |
- | build_dpath< | + | |
- | + | ||
- | (; i : 32 : dp.in[2*i] = a[i]; dp.in[2*i+1] = b[i]); | + | |
- | dp.out = out; | + | |
- | dp.rin[0] = cin; | + | |
- | dp.rout[0] = cout | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + |