Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionBoth sides next revision | ||
alvis:stepscounting [2013/12/31 13:46] marcin | — (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Steps counting ====== | ||
- | Let us focus on the **step** idea. It is necessary to distinguish between **code statements** and **steps**. Most of the Alvis statements e.g. **exec**, **exit**, etc. are **single-step statements**. On the other hand, **if**, **loop** and **select** are **multi-step statements**. We use recursion to count the number of steps for multi-step statements. For each of them, the first step enters the statement interior. Then, we count steps of statements put inside curly brackets. | ||
- | |||
- | For a given statement //s//, let // | ||
- | |||
- | Let us consider the piece of code shown in Listing 1. The steps number are put inside comments. For example, the step 7 denotes entering the **if** statement, while the step 8 denotes the **out** statement. | ||
- | |||
- | < | ||
- | agent A { | ||
- | i :: Int = 0; | ||
- | loop { -- 1 | ||
- | select { -- 2 | ||
- | alt (i == 0) { | ||
- | in p; -- 3 | ||
- | i = 1; -- 4 | ||
- | } | ||
- | alt (i == 1) { | ||
- | in q; -- 5 | ||
- | i = 0; -- 6 | ||
- | } | ||
- | } | ||
- | if(i == 1) { -- 7 | ||
- | out p; -- 8 | ||
- | } | ||
- | else { | ||
- | null; -- 9 | ||
- | } | ||
- | } | ||
- | } | ||
- | </ | ||
- | **Listing 1.** Steps counting in Alvis code. | ||
- | |||
- | To simplify the formal description of transitions, | ||
- | |||
- | **The //nextpc// returns 0 if there is no next step.** | ||
- | |||
- | |||
- | **[[: |