Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
language:langs:chp [2023/04/07 08:14] rajit [Syntactic replication] |
language:langs:chp [2023/04/09 19:28] (current) rajit [Arrays: dynamic v/s non-dynamic indices] |
||
---|---|---|---|
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 260: | Line 286: | ||
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 '' | ||
====== The chp-txt sublanguage ====== | ====== The chp-txt sublanguage ====== |