1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-08 15:29:37 +00:00

Add support of unnamed labels with @ (.localchar) prefix.

This commit is contained in:
Evgeny Vrublevsky 2023-06-03 16:33:18 +03:00
parent b993d88339
commit c500cb9086
4 changed files with 59 additions and 13 deletions

View File

@ -707,6 +707,24 @@ static void OneLine (void)
NextTok (); NextTok ();
} }
/* Handle @-style unnamed labels */
if (CurTok.Tok == TOK_ULABEL) {
if (CurTok.IVal != 0) {
Error ("Invalid unnamed label definition");
}
ULabDef ();
NextTok ();
/* Skip the colon. If NoColonLabels is enabled, allow labels without
** a colon if there is no whitespace before the identifier.
*/
if (CurTok.Tok == TOK_COLON) {
NextTok ();
} else if (CurTok.WS || !NoColonLabels) {
Error ("':' expected");
}
}
/* If the first token on the line is an identifier, check for a macro or /* If the first token on the line is an identifier, check for a macro or
** an instruction. ** an instruction.
*/ */

View File

@ -1124,17 +1124,33 @@ Again:
/* Local symbol? */ /* Local symbol? */
if (C == LocalStart) { if (C == LocalStart) {
/* Read the identifier. */ NextChar ();
ReadIdent ();
/* Start character alone is not enough */ if (IsIdChar (C)) {
if (SB_GetLen (&CurTok.SVal) == 1) { /* Read a local identifier */
Error ("Invalid cheap local symbol"); CurTok.Tok = TOK_LOCAL_IDENT;
goto Again; SB_AppendChar (&CurTok.SVal, LocalStart);
ReadIdent ();
} else {
/* Read an unnamed label */
CurTok.IVal = 0;
CurTok.Tok = TOK_ULABEL;
if (C == '-' || C == '<') {
int PrevC = C;
do {
--CurTok.IVal;
NextChar ();
} while (C == PrevC);
} else if (C == '+' || C == '>') {
int PrevC = C;
do {
++CurTok.IVal;
NextChar ();
} while (C == PrevC);
}
} }
/* A local identifier */
CurTok.Tok = TOK_LOCAL_IDENT;
return; return;
} }
@ -1314,22 +1330,30 @@ CharAgain:
break; break;
case '-': case '-':
case '<':
{
int PrevC = C;
CurTok.IVal = 0; CurTok.IVal = 0;
do { do {
--CurTok.IVal; --CurTok.IVal;
NextChar (); NextChar ();
} while (C == '-'); } while (C == PrevC);
CurTok.Tok = TOK_ULABEL; CurTok.Tok = TOK_ULABEL;
break; break;
}
case '+': case '+':
case '>':
{
int PrevC = C;
CurTok.IVal = 0; CurTok.IVal = 0;
do { do {
++CurTok.IVal; ++CurTok.IVal;
NextChar (); NextChar ();
} while (C == '+'); } while (C == PrevC);
CurTok.Tok = TOK_ULABEL; CurTok.Tok = TOK_ULABEL;
break; break;
}
case '=': case '=':
NextChar (); NextChar ();

View File

@ -71,7 +71,7 @@ typedef enum token_t {
TOK_REG, /* Sweet16 R.. register (in sweet16 mode) */ TOK_REG, /* Sweet16 R.. register (in sweet16 mode) */
TOK_ASSIGN, /* := */ TOK_ASSIGN, /* := */
TOK_ULABEL, /* :++ or :-- */ TOK_ULABEL, /* An unnamed label */
TOK_EQ, /* = */ TOK_EQ, /* = */
TOK_NE, /* <> */ TOK_NE, /* <> */

View File

@ -107,8 +107,12 @@ ExprNode* ULabRef (int Which)
int Index; int Index;
ULabel* L; ULabel* L;
/* Which can never be 0 */ /* Which should not be 0 */
PRECONDITION (Which != 0); if (Which == 0) {
Error ("Invalid unnamed label reference");
/* We must return something valid */
return GenCurrentPC();
}
/* Get the index of the referenced label */ /* Get the index of the referenced label */
if (Which > 0) { if (Which > 0) {