1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-31 11:29:16 +00:00

Fixed a while loop bug

git-svn-id: svn://svn.cc65.org/cc65/trunk@803 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2001-07-17 17:18:07 +00:00
parent c1c402c6ba
commit e370e447f6

View File

@ -199,24 +199,17 @@ static void WhileStatement (void)
/* Test the loop condition */ /* Test the loop condition */
test (lab, 0); test (lab, 0);
/* If the statement following the while loop is empty, that is, we have /* Loop body */
* something like "while (1) ;", the test function ommitted the jump as Statement (&PendingToken);
* an optimization. Since we know, the condition codes are set, we can
* do another small optimization here, and use a conditional jump /* Jump back to loop top */
* instead an absolute one. g_jump (loop);
*/
if (CurTok.Tok == TOK_SEMI) { /* Exit label */
/* Use a conditional jump */ g_defcodelabel (lab);
g_truejump (CF_NONE, loop);
/* Shortcut */ /* Eat remaining tokens that were delay because of line info correctness */
NextToken (); SkipPending (PendingToken);
} else {
/* There is code inside the while loop, parse the body */
Statement (&PendingToken);
g_jump (loop);
g_defcodelabel (lab);
SkipPending (PendingToken);
}
/* Remove the loop from the loop stack */ /* Remove the loop from the loop stack */
DelLoop (); DelLoop ();
@ -641,7 +634,7 @@ static void ForStatement (void)
struct expent lval1; struct expent lval1;
struct expent lval2; struct expent lval2;
struct expent lval3; struct expent lval3;
int HaveIncExpr; int HaveIncExpr;
CodeMark IncExprStart; CodeMark IncExprStart;
CodeMark IncExprEnd; CodeMark IncExprEnd;
int PendingToken; int PendingToken;
@ -652,7 +645,7 @@ static void ForStatement (void)
unsigned IncLabel = GetLocalLabel (); unsigned IncLabel = GetLocalLabel ();
unsigned lstat = GetLocalLabel (); unsigned lstat = GetLocalLabel ();
/* Skip the FOR token */ /* Skip the FOR token */
NextToken (); NextToken ();
/* Add the loop to the loop stack */ /* Add the loop to the loop stack */
@ -715,7 +708,7 @@ static void ForStatement (void)
/* Jump back to the increment expression */ /* Jump back to the increment expression */
g_jump (IncLabel); g_jump (IncLabel);
} }
/* Skip a pending token if we have one */ /* Skip a pending token if we have one */
SkipPending (PendingToken); SkipPending (PendingToken);