fix to for-loop code was wrong; fixed again

This commit is contained in:
ceriel 1989-10-30 15:45:43 +00:00
parent 67e5a8e7a5
commit 8cb76d3ed8
2 changed files with 5 additions and 13 deletions

View file

@ -219,7 +219,7 @@ arith
CodeInitFor(nd, priority) CodeInitFor(nd, priority)
register struct node *nd; register struct node *nd;
{ {
/* Push init-value or final-value, the value may only be evaluated /* Push final-value, the value may only be evaluated
once, so generate a temporary for it, when not a constant. once, so generate a temporary for it, when not a constant.
*/ */
@ -237,10 +237,9 @@ CodeInitFor(nd, priority)
return (arith) 0; return (arith) 0;
} }
CodeFor(nd, stepsize, l1, l2, tmp1) CodeFor(nd, stepsize, l1, l2)
struct node *nd; struct node *nd;
label l1, l2; label l1, l2;
arith tmp1;
{ {
/* Test if loop has to be done */ /* Test if loop has to be done */
if( stepsize == 1 ) /* TO */ if( stepsize == 1 ) /* TO */
@ -248,12 +247,6 @@ CodeFor(nd, stepsize, l1, l2, tmp1)
else /* DOWNTO */ else /* DOWNTO */
C_blt(l2); C_blt(l2);
/* Store init-value in control-variable */
if( tmp1 )
C_lol(tmp1);
else
CodePExpr(nd->nd_left);
/* Label at begin of the body */ /* Label at begin of the body */
C_df_ilb(l1); C_df_ilb(l1);

View file

@ -341,7 +341,6 @@ ForStatement
int stepsize; int stepsize;
label l1 = ++text_label; label l1 = ++text_label;
label l2 = ++text_label; label l2 = ++text_label;
arith tmp1 = (arith) 0;
arith tmp2 = (arith) 0; arith tmp2 = (arith) 0;
} : } :
FOR FOR
@ -357,9 +356,10 @@ ForStatement
Expression(&(nd->nd_right)) Expression(&(nd->nd_right))
{ ChkForStat(nd); { ChkForStat(nd);
if( !err_occurred ) { if( !err_occurred ) {
tmp1 = CodeInitFor(nd->nd_left, 0); CodePExpr(nd->nd_left);
C_dup(int_size);
tmp2 = CodeInitFor(nd->nd_right, 2); tmp2 = CodeInitFor(nd->nd_right, 2);
CodeFor(nd, stepsize, l1, l2, tmp1); CodeFor(nd, stepsize, l1, l2);
} }
} }
DO DO
@ -369,7 +369,6 @@ ForStatement
EndForStat(nd); EndForStat(nd);
chk_labels(slevel + 1); chk_labels(slevel + 1);
FreeNode(nd); FreeNode(nd);
if( tmp1 ) FreeInt(tmp1);
if( tmp2 ) FreeInt(tmp2); if( tmp2 ) FreeInt(tmp2);
} }
; ;