Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
language:langs:chp [2023/04/07 12:13] – [Channels in expressions] rajit | language:langs:chp [2025/05/23 11:56] (current) – [Syntactic replication] rajit | ||
---|---|---|---|
Line 86: | Line 86: | ||
In the published literature, non-deterministic selections are usually written using a thin bar '' | In the published literature, non-deterministic selections are usually written using a thin bar '' | ||
+ | |||
+ | ===== Arrays: dynamic v/s non-dynamic indices ===== | ||
+ | |||
+ | Suppose an array '' | ||
+ | <code act> | ||
+ | int x[10]; | ||
+ | </ | ||
+ | |||
+ | Now when '' | ||
+ | <code act> | ||
+ | chp { | ||
+ | ... | ||
+ | x[0] := x[0] + 1; | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | uses '' | ||
+ | <code act> | ||
+ | chp { | ||
+ | ... | ||
+ | x[i] := x[i] + 1; | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | uses '' | ||
+ | |||
===== Loops ===== | ===== Loops ===== | ||
Line 130: | Line 156: | ||
===== Advanced expression syntax ===== | ===== Advanced expression syntax ===== | ||
+ | |||
+ | ==== Bitslice assignment ==== | ||
+ | |||
+ | For integer-valued variables, one can assign to some of the bits. The syntax for this is: | ||
+ | |||
+ | <code act> | ||
+ | | ||
+ | ... | ||
+ | chp { | ||
+ | ... | ||
+ | x{4..2} := 4; | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | This will update three bits of '' | ||
+ | |||
+ | |||
==== Channels in expressions ==== | ==== Channels in expressions ==== | ||
Line 223: | Line 266: | ||
Essentially every channel variable '' | Essentially every channel variable '' | ||
+ | |||
+ | ===== Advanced channels ===== | ||
==== Exchange channels ==== | ==== Exchange channels ==== | ||
Line 235: | Line 280: | ||
Four-phase handshake channels involve two synchronizations. If you need to make this explicit in the CHP, the '' | Four-phase handshake channels involve two synchronizations. If you need to make this explicit in the CHP, the '' | ||
- | ==== Syntactic replication ==== | + | ===== Syntactic replication |
There are three common uses of syntactic replication in CHP, and the language has syntactic support for them. The first two correspond to scenarios where you have a number of items separated by semicolon or comma. The syntax for this follows the generic template for [[language: | There are three common uses of syntactic replication in CHP, and the language has syntactic support for them. The first two correspond to scenarios where you have a number of items separated by semicolon or comma. The syntax for this follows the generic template for [[language: | ||
Line 257: | Line 302: | ||
Similarly, the semicolon can be replaced with a comma to specify parallel execution. | Similarly, the semicolon can be replaced with a comma to specify parallel execution. | ||
+ | |||
+ | Syntactic replication is also supported for guarded commands. | ||
+ | |||
+ | <code act> | ||
+ | [ v = 0 -> x := x - v | ||
+ | [] ( [] i : 3 : v = i+2 -> x := x + i ) | ||
+ | ] | ||
+ | </ | ||
+ | |||
+ | is the same as | ||
+ | |||
+ | <code act> | ||
+ | [ v = 0 -> x := x - v | ||
+ | [] v = 0+2 -> x := x + 0 | ||
+ | [] v = 1+2 -> x := x + 1 | ||
+ | [] v = 2+2 -> x := x + 2 | ||
+ | ] | ||
+ | </ | ||
+ | |||
+ | This construct can be used to work around one of the current restrictions of CHP. A natural way to write a merge process in ACT is: | ||
+ | <code act> | ||
+ | *[ C?c; I[c]?d; O!d ] | ||
+ | </ | ||
+ | This will error out because the CHP has a //dynamic// channel access---i.e. the channel accessed is computed at run-time. While this is supported for int arrays, for example, that is because there is an efficient compilation mechanism for large int arrays (via memory macros). To work around this restriction, | ||
+ | <code act> | ||
+ | *[ C?c; [ ([] i : N : c = i -> I[i]?d) ]; O!d ] | ||
+ | </ | ||
+ | where '' | ||
+ | |||
+ | ===== Debugging and other support functions for simulation ===== | ||
+ | |||
+ | When running CHP simulations, | ||
+ | |||
+ | <code act> | ||
+ | ... | ||
+ | chp { | ||
+ | ... | ||
+ | log (" | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | The statement above will display '' | ||
+ | |||
+ | <code act> | ||
+ | int x; | ||
+ | ... | ||
+ | chp { | ||
+ | ... | ||
+ | log (" | ||
+ | log ("%x This is hex: ", x+3); | ||
+ | log ("%b This is binary", | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Booleans are displayed as integers, with '' | ||
+ | |||
+ | Other support functions of this type are: | ||
+ | * '' | ||
+ | * '' | ||
+ | * In the standard '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||