Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions asllib/doc/Statements.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,11 @@ \subsection{Semantics}
starts at $\nvint(4)$ and decrements towards $\nvint(0)$,
stopping at $\nvint(1)$ on the last iteration of the loop.

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

\RenderProseAndFormally{tick_loop_limit}

Expand Down
11 changes: 7 additions & 4 deletions asllib/doc/asl.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10147,14 +10147,17 @@ semantics relation tick_loop_limit(v_opt: option(N)) -> (v_opt': option(N)) | TD
}

case some_ok {
v_opt =: some(v);
v > zero;
v_opt =: some(limit);
new_limit := limit - one;
new_limit >= zero;
--
some(v - one);
some(new_limit);
}

case some_error {
v_opt =: some(zero);
v_opt =: some(limit);
new_limit := limit - one;
new_limit < zero;
--
DynamicError(DE_LE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
func main () => integer
begin
// A negative loop limit prevents loops from executing.
while TRUE looplimit -1 do
println "This should not be printed";
end;
return 0;
end;
8 changes: 8 additions & 0 deletions asllib/tests/ASLSemanticsReference.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ ASL Semantics Tests:
end;
ASL Dynamic error: loop limit reached.
[1]
$ aslref SemanticsRule.SWhile.negative_limit.asl
File SemanticsRule.SWhile.negative_limit.asl, line 4, character 2 to line 6,
character 6:
while TRUE looplimit -1 do
println "This should not be printed";
end;
ASL Dynamic error: loop limit reached.
[1]
$ aslref SemanticsRule.SRepeat.asl
File SemanticsRule.SRepeat.asl, line 24, character 4 to line 31, character 17:
repeat
Expand Down
Loading