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
language:introduction [2020/12/02 06:00] – external edit 127.0.0.1language:introduction [2025/09/04 11:09] (current) – [Loops and conditionals] rajit
Line 16: Line 16:
 To get a feel for how a circuit is described in ACT, we begin with a simple example circuit. The purpose of this circuit is to create a dual rail channel (called ''a1of2'' for a one-of-two encoded data channel and an acknowledge) and attach a bit-bucket to it. To get a feel for how a circuit is described in ACT, we begin with a simple example circuit. The purpose of this circuit is to create a dual rail channel (called ''a1of2'' for a one-of-two encoded data channel and an acknowledge) and attach a bit-bucket to it.
  
-<code>+<code act>
 /* my first act program */ /* my first act program */
 defchan a1of2 <: chan(bool) (bool d0,d1,a) defchan a1of2 <: chan(bool) (bool d0,d1,a)
Line 72: Line 72:
 legal: legal:
  
-<code>+<code act>
 bitbucket b; bitbucket b;
 a1of2 x1; a1of2 x1;
Line 81: Line 81:
 On the other hand, the following declaration is incorrect. On the other hand, the following declaration is incorrect.
  
-<code>+<code act>
 pbool 5; pbool 5;
 +</code>
 +<code>
 -[ERROR]-> Expecting bnf-item `instance_id', got `5' -[ERROR]-> Expecting bnf-item `instance_id', got `5'
 </code> </code>
Line 90: Line 92:
 parser was expecting. Error messages are accompanied by the file name, parser was expecting. Error messages are accompanied by the file name,
 line number, and column number of the item that resulted in the error. line number, and column number of the item that resulted in the error.
 +
 +The variable names ''self'' and ''selfack'' are reserved. They are used to support
 +ACT language features like functions and user-defined types.
  
 The names in the port list of a user-defined type are the only parts of The names in the port list of a user-defined type are the only parts of
Line 96: Line 101:
 consider the following definition of ''bitbucket''. consider the following definition of ''bitbucket''.
  
-<code>+<code act>
 defproc bitbucket(a1of2 d) defproc bitbucket(a1of2 d)
 { {
Line 112: Line 117:
 result in the following message: result in the following message:
  
-<code>+<code act>
 bitbucket b; bitbucket b;
 a1of2 c; a1of2 c;
 b.p = c.d0; b.p = c.d0;
 +</code>
 +<code>
 -[ERROR]-> `p' is not a port for `bitbucket' -[ERROR]-> `p' is not a port for `bitbucket'
 </code> </code>
Line 141: Line 148:
 circuits. The simplest way to create an array is shown below. circuits. The simplest way to create an array is shown below.
  
-<code>+<code act>
 bool x[10]; bool x[10];
 a1of2 y[5][3]; a1of2 y[5][3];
Line 153: Line 160:
 be specified as shown below be specified as shown below
  
-<code>+<code act>
 bool w[4..7]; // create Booleans w[4], ..., w[7] bool w[4..7]; // create Booleans w[4], ..., w[7]
 </code> </code>
Line 162: Line 169:
 block. Consider the following instantiation: block. Consider the following instantiation:
  
-<code>+<code act>
 bool x[10]; bool x[10];
 bool x[12..14]; bool x[12..14];
Line 172: Line 179:
 following, on the other hand, is not valid. following, on the other hand, is not valid.
  
-<code>+<code act>
 bool x[10]; bool x[10];
 bool x[9..14]; bool x[9..14];
Line 189: Line 196:
 below. below.
  
-<code>+<code act>
 bool x[10]; bool x[10];
 bool x[12..14]; bool x[12..14];
Line 203: Line 210:
 succeed, and their shapes also have to be compatible. succeed, and their shapes also have to be compatible.
  
-<code>+<code act>
 bool x[12]; bool x[12];
 bool w[4][3]; bool w[4][3];
 x=w; x=w;
 +</code>
 +<code>
 -[ERROR]-> Type-checking failed in connection -[ERROR]-> Type-checking failed in connection
            Types `bool[12]' and `bool[4][3]' are not compatible            Types `bool[12]' and `bool[4][3]' are not compatible
Line 213: Line 222:
 The following are examples of valid connections: The following are examples of valid connections:
  
-<code>+<code act>
 bool x[10]; bool x[10];
 bool x[10..12]; bool x[10..12];
Line 233: Line 242:
 carry chain for a ten bit ripple-carry adder. carry chain for a ten bit ripple-carry adder.
  
-<code>+<code act>
 fulladder fa[10]; fulladder fa[10];
 (i : 9 : fa[i].co=fa[i+1].ci; ) (i : 9 : fa[i].co=fa[i+1].ci; )
Line 240: Line 249:
 The parentheses are used to group the body of the loop. ''i'' is The parentheses are used to group the body of the loop. ''i'' is
 the dummy variable, and it ranges from zero to eight in this the dummy variable, and it ranges from zero to eight in this
-example. The '';'' is a separator, and separates each instance of +example. In general if only one integer is specified for
-the body of the loop.  In general if only one integer is specified for+
 the range, the variable ranges from zero to one less than the integer. the range, the variable ranges from zero to one less than the integer.
 +This is a special case of a more general [[syntacticreplication|syntactic replication]] construct
 +that can be used in many contexts.
  
 The conditional statement uses the guarded command notation. They are The conditional statement uses the guarded command notation. They are
Line 251: Line 261:
 indices are connected to ''z''. indices are connected to ''z''.
  
-<code>+<code act>
 bool x[10], y[10], z[10]; bool x[10], y[10], z[10];
  
Line 282: Line 292:
 instance, ACT files will tend to begin with instance, ACT files will tend to begin with
  
-<code>+<code act>
 bool Reset,Reset_; bool Reset,Reset_;
 </code> </code>
Line 304: Line 314:
 within the namespace. within the namespace.
  
-<code>+<code act>
 namespace lib { namespace lib {
   export defchan a1of2 <: chan(bool) (bool d0,d1,a) { ... }   export defchan a1of2 <: chan(bool) (bool d0,d1,a) { ... }
Line 327: Line 337:
 Namespaces can be nested. For instance, we could have: Namespaces can be nested. For instance, we could have:
  
-<code>+<code act>
 namespace processor { namespace processor {
  
   namespace lib {   namespace lib {
-       export defchan a1of2 chan(bool) (bool d0,d1,a) { ... } +       export defchan a1of2 <: chan(bool) (bool d0,d1,a) { ... } 
   }   }
  
Line 345: Line 355:
 ''processor'' namespace. ''processor'' namespace.
  
-<code>+<code act>
 namespace processor { namespace processor {
  
   namespace lib {   namespace lib {
-       export defchan a1of2 chan(bool) (bool d0,d1,a) { ... }+       export defchan a1of2 <: chan(bool) (bool d0,d1,a) { ... }
   }   }
  
Line 355: Line 365:
  
 processor::lib::a1of2 d; processor::lib::a1of2 d;
 +</code>
 +<code>
 -[ERROR]-> Type is not exported up the namespace hierarchy: -[ERROR]-> Type is not exported up the namespace hierarchy:
            processor::lib::a1of2            processor::lib::a1of2
Line 363: Line 375:
 exporting the namespace itself. exporting the namespace itself.
  
-<code>+<code act>
 namespace processor { namespace processor {
  
   export namespace lib {   export namespace lib {
-       export defchan a1of2 chan(bool) (bool d0,d1,a) { ... }+       export defchan a1of2 <: chan(bool) (bool d0,d1,a) { ... }
   }   }
  
Line 402: Line 414:
 ''import'' to include type definitions defined elsewhere. ''import'' to include type definitions defined elsewhere.
  
-<code>+<code act>
 import "channel.act"; import "channel.act";
 ... ...
Line 424: Line 436:
 the namespaces, and could create naming conflicts (e.g. multiple the namespaces, and could create naming conflicts (e.g. multiple
 definition of types having the same name---an error). To solve this definition of types having the same name---an error). To solve this
-problem, one can do the following:+problem, one can do the following: 
  
-<code>+<code act>
 import "lib1.act"; import "lib1.act";
 open lib -> lib1; open lib -> lib1;
Line 446: Line 458:
 because not all types might be exported! In this case we can say: because not all types might be exported! In this case we can say:
  
-<code>+<code act>
 import "lib.act"; import "lib.act";
 open processor::lib; open processor::lib;
Line 467: Line 479:
 hierarchy. The import statement hierarchy. The import statement
  
-<code>+<code act>
 import processor::lib; import processor::lib;
 </code> </code>
Line 473: Line 485:
 is equivalent to the following: is equivalent to the following:
  
-<code>+<code act>
 import "processor/lib/_all_.act"; import "processor/lib/_all_.act";
 </code> </code>