From: cuz Date: Sun, 25 Jun 2000 17:48:28 +0000 (+0000) Subject: Working on .MID X-Git-Tag: V2.12.0~3383 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=158714acf959cc8c97678ee3d698f9a83173707c;p=cc65 Working on .MID git-svn-id: svn://svn.cc65.org/cc65/trunk@130 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ca65/nexttok.c b/src/ca65/nexttok.c index 418130d86..72c80708a 100644 --- a/src/ca65/nexttok.c +++ b/src/ca65/nexttok.c @@ -61,7 +61,7 @@ static TokList* CollectTokens (unsigned Start, unsigned Count) /* Read the token list */ unsigned Current = 0; unsigned Parens = 0; - while (Parens != 0 && Tok != TOK_RPAREN) { + while (Parens != 0 || Tok != TOK_RPAREN) { /* Check for end of line or end of input */ if (Tok == TOK_SEP || Tok == TOK_EOF) { @@ -83,6 +83,7 @@ static TokList* CollectTokens (unsigned Start, unsigned Count) } /* Get the next token */ + ++Current; NextTok (); } @@ -187,7 +188,7 @@ static void FuncMid (void) /* Count argument */ Count = ConstExpression (); - if (Count > 100) { + if (Count < 0 || Count > 100) { Error (ERR_RANGE); Count = 1; } @@ -197,9 +198,7 @@ static void FuncMid (void) List = CollectTokens ((unsigned) Start, (unsigned) Count); /* Insert it into the scanner feed */ - - - + PushTokList (List, ".MID"); } diff --git a/src/ca65/toklist.c b/src/ca65/toklist.c index a45d8f0a9..fc4eec608 100644 --- a/src/ca65/toklist.c +++ b/src/ca65/toklist.c @@ -37,6 +37,7 @@ #include "../common/xmalloc.h" +#include "istack.h" #include "scanner.h" #include "toklist.h" @@ -181,3 +182,56 @@ void AddCurTok (TokList* List) +static int ReplayTokList (void* List) +/* Function that gets the next token from a token list and sets it. This + * function may be used together with the PushInput function from the istack + * module. + */ +{ + /* Cast the generic pointer to an actual list */ + TokList* L = List; + + /* Set the next token from the list */ + TokSet (L->Last); + + /* If this was the last token, decrement the repeat counter. If it goes + * zero, delete the list and remove the function from the stack. + */ + if (L->Last == 0) { + if (--L->Repeat == 0) { + /* Done with this list */ + FreeTokList (L); + PopInput (); + } else { + /* Replay one more time */ + L->Last = L->Root; + } + } + + /* We have a token */ + return 1; +} + + + +void PushTokList (TokList* List, const char* Desc) +/* Push a token list to be used as input for InputFromStack. This includes + * several initializations needed in the token list structure, so don't use + * PushInput directly. + */ +{ + /* If the list is empty, just delete it and bail out */ + if (List->Count == 0) { + FreeTokList (List); + return; + } + + /* Reset the last pointer to the first element */ + List->Last = List->Root; + + /* Insert the list specifying our input function */ + PushInput (ReplayTokList, List, Desc); +} + + + diff --git a/src/ca65/toklist.h b/src/ca65/toklist.h index fb0351349..498631d83 100644 --- a/src/ca65/toklist.h +++ b/src/ca65/toklist.h @@ -105,6 +105,12 @@ void FreeTokList (TokList* T); void AddCurTok (TokList* T); /* Add the current token to the token list */ +void PushTokList (TokList* List, const char* Desc); +/* Push a token list to be used as input for InputFromStack. This includes + * several initializations needed in the token list structure, so don't use + * PushInput directly. + */ + /* End of toklist.h */