Related articles |
---|
Testing strategy for compiler kuangpma@gmail.com (kuangpma) (2010-06-16) |
Re: Testing strategy for compiler ott@mirix.org (Matthias-Christian Ott) (2010-06-18) |
Re: Testing strategy for compiler gneuner2@comcast.net (George Neuner) (2010-06-18) |
Re: Testing strategy for compiler gah@ugcs.caltech.edu (glen herrmannsfeldt) (2010-06-19) |
Re: Testing strategy for compiler gneuner2@comcast.net (George Neuner) (2010-06-21) |
Re: Pascal design, was Testing strategy for compiler marcov@turtle.stack.nl (Marco van de Voort) (2010-06-22) |
Re: Pascal design, was Testing strategy for compiler gneuner2@comcast.net (George Neuner) (2010-06-25) |
From: | George Neuner <gneuner2@comcast.net> |
Newsgroups: | comp.compilers |
Date: | Fri, 25 Jun 2010 19:10:50 -0400 |
Organization: | A noiseless patient Spider |
References: | 10-06-037 10-06-044 10-06-050 10-06-054 10-06-061 10-06-065 |
Keywords: | design, optimize |
Posted-Date: | 26 Jun 2010 10:54:09 EDT |
On Tue, 22 Jun 2010 11:17:52 +0000 (UTC), Marco van de Voort
<marcov@turtle.stack.nl> wrote:
>On 2010-06-21, George Neuner <gneuner2@comcast.net> wrote:
>> Pascal's FOR loop is required to terminate in all cases - deliberately
>> causing an infinite loop is illegal. The compiler is required to
>> check that step <> zero on entry to the loop and it is illegal to
>> modify any of the loop control values (index, finish, step) from
>> within the body of the loop.
>
>(isn't the loopvar also required to be a ordinal local var? Or is that
>Borland dialects only? Anyway it is a rule that also excludes a lot of
>dodgy use cases)
Yes, the named loop variable must be a local variable. However, the
named variable may not be in control of the loop:
The standard (ISO-10206) says:
for v := e1 to e2 do BODY
shall be equivalent to
begin
temp1 := e1;
temp2 := e2;
if temp1 <= temp2 then
begin
v := temp1;
BODY;
while v <> temp2 do
begin
v := succ(v);
BODY
end
end
end
There's an analogous equivalence using pred() for
for v := e1 downto e2 do BODY
It doesn't take much thought to simplify the code above to
temp1 := e1;
temp2 := e2;
if temp1 <= temp2 then
repeat
v := temp1;
BODY
temp1 := succ(temp1);
until ( temp1 > temp2 );
which both separates the named variable from loop control and ensures
the variable has the proper value at the start of each iteration.
Separation of the loop variable from control is not strictly necessary
because it is illegal to assign to the loop variable within the loop
body, but it is what a lot of compilers do because it is not illegal
to pass the loop variable to a function by reference and it can be
difficult to statically find every indirect modification.
George
Return to the
comp.compilers page.
Search the
comp.compilers archives again.