Skip to content

Commit 921f92b

Browse files
Merge pull request #1770 from herd/aslspec-fix
[aslspec] fixed tick_loop_limit to match implementation
2 parents ee8eecc + d60b5a8 commit 921f92b

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

asllib/doc/Statements.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,11 @@ \subsection{Semantics}
15401540
starts at $\nvint(4)$ and decrements towards $\nvint(0)$,
15411541
stopping at $\nvint(1)$ on the last iteration of the loop.
15421542

1543+
\ExampleDef{Negative Loop Limit Values}
1544+
In \listingref{semantics-swhile-negative-limit}, the loop limit value starts at $\nvint(-1)$
1545+
so the loop limit is immediately reached, resulting in a \dynamicerrorterm{} without executing the loop body at all.
1546+
(The same would happen if the loop limit value started at $\nvint(0)$.)
1547+
\ASLListing{A \texttt{while} statement with a negative loop limit}{semantics-swhile-negative-limit}{\semanticstests/SemanticsRule.SWhile.negative_limit.asl}
15431548

15441549
\RenderProseAndFormally{tick_loop_limit}
15451550

asllib/doc/asl.spec

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10147,14 +10147,17 @@ semantics relation tick_loop_limit(v_opt: option(N)) -> (v_opt': option(N)) | TD
1014710147
}
1014810148

1014910149
case some_ok {
10150-
v_opt =: some(v);
10151-
v > zero;
10150+
v_opt =: some(limit);
10151+
new_limit := limit - one;
10152+
new_limit >= zero;
1015210153
--
10153-
some(v - one);
10154+
some(new_limit);
1015410155
}
1015510156

1015610157
case some_error {
10157-
v_opt =: some(zero);
10158+
v_opt =: some(limit);
10159+
new_limit := limit - one;
10160+
new_limit < zero;
1015810161
--
1015910162
DynamicError(DE_LE);
1016010163
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
func main () => integer
2+
begin
3+
// A negative loop limit prevents loops from executing.
4+
while TRUE looplimit -1 do
5+
println "This should not be printed";
6+
end;
7+
return 0;
8+
end;

asllib/tests/ASLSemanticsReference.t/run.t

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ ASL Semantics Tests:
7272
end;
7373
ASL Dynamic error: loop limit reached.
7474
[1]
75+
$ aslref SemanticsRule.SWhile.negative_limit.asl
76+
File SemanticsRule.SWhile.negative_limit.asl, line 4, character 2 to line 6,
77+
character 6:
78+
while TRUE looplimit -1 do
79+
println "This should not be printed";
80+
end;
81+
ASL Dynamic error: loop limit reached.
82+
[1]
7583
$ aslref SemanticsRule.SRepeat.asl
7684
File SemanticsRule.SRepeat.asl, line 24, character 4 to line 31, character 17:
7785
repeat

0 commit comments

Comments
 (0)