From 8cb76d3ed89fef2eceee8bb62516c906cc3efcee Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 30 Oct 1989 15:45:43 +0000 Subject: [PATCH] fix to for-loop code was wrong; fixed again --- lang/pc/comp/body.c | 11 ++--------- lang/pc/comp/statement.g | 7 +++---- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lang/pc/comp/body.c b/lang/pc/comp/body.c index 2bd8a2874..31ccc63b0 100644 --- a/lang/pc/comp/body.c +++ b/lang/pc/comp/body.c @@ -219,7 +219,7 @@ arith CodeInitFor(nd, priority) 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. */ @@ -237,10 +237,9 @@ CodeInitFor(nd, priority) return (arith) 0; } -CodeFor(nd, stepsize, l1, l2, tmp1) +CodeFor(nd, stepsize, l1, l2) struct node *nd; label l1, l2; - arith tmp1; { /* Test if loop has to be done */ if( stepsize == 1 ) /* TO */ @@ -248,12 +247,6 @@ CodeFor(nd, stepsize, l1, l2, tmp1) else /* DOWNTO */ 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 */ C_df_ilb(l1); diff --git a/lang/pc/comp/statement.g b/lang/pc/comp/statement.g index e9cff0332..ea8c8b83c 100644 --- a/lang/pc/comp/statement.g +++ b/lang/pc/comp/statement.g @@ -341,7 +341,6 @@ ForStatement int stepsize; label l1 = ++text_label; label l2 = ++text_label; - arith tmp1 = (arith) 0; arith tmp2 = (arith) 0; } : FOR @@ -357,9 +356,10 @@ ForStatement Expression(&(nd->nd_right)) { ChkForStat(nd); if( !err_occurred ) { - tmp1 = CodeInitFor(nd->nd_left, 0); + CodePExpr(nd->nd_left); + C_dup(int_size); tmp2 = CodeInitFor(nd->nd_right, 2); - CodeFor(nd, stepsize, l1, l2, tmp1); + CodeFor(nd, stepsize, l1, l2); } } DO @@ -369,7 +369,6 @@ ForStatement EndForStat(nd); chk_labels(slevel + 1); FreeNode(nd); - if( tmp1 ) FreeInt(tmp1); if( tmp2 ) FreeInt(tmp2); } ; -- 2.34.1