From: cuz Date: Fri, 17 Oct 2003 00:38:21 +0000 (+0000) Subject: Add := assignment op, define some currently unused keywords X-Git-Tag: V2.12.0~1250 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c12c231f1456b6c3e94503d0b21401fe4bd5f229;p=cc65 Add := assignment op, define some currently unused keywords git-svn-id: svn://svn.cc65.org/cc65/trunk@2542 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ca65/main.c b/src/ca65/main.c index 047c37b02..972a8869c 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -183,7 +183,7 @@ static void DefineSymbol (const char* Def) } /* Define the symbol */ - SymDef (SymName, GenLiteralExpr (Val), 0, 0); + SymDef (SymName, GenLiteralExpr (Val), SYM_DEFAULT); } @@ -373,16 +373,20 @@ static void OneLine (void) /* If a colon follows, this is a label definition. If there * is no colon, it's an assignment. */ - if (Tok == TOK_EQ) { + if (Tok == TOK_EQ || Tok == TOK_ASSIGN) { + /* If it's an assign token, we have a label */ + unsigned Flags = (Tok == TOK_ASSIGN)? SYM_LABEL : SYM_DEFAULT; /* Skip the '=' */ NextTok (); /* Define the symbol with the expression following the '=' */ - SymDef (Ident, Expression(), 0, 0); + SymDef (Ident, Expression(), Flags); /* Don't allow anything after a symbol definition */ Done = 1; } else { + /* Define the symbol flags */ + unsigned Flags = IsZPSeg ()? SYM_ZP | SYM_LABEL : SYM_LABEL; /* Define a label */ - SymDef (Ident, GenCurrentPC(), IsZPSeg(), 1); + SymDef (Ident, GenCurrentPC (), Flags); /* Skip the colon. If NoColonLabels is enabled, allow labels * without a colon if there is no whitespace before the * identifier. diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index 41d259aba..20dfe2e0c 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -1243,7 +1243,11 @@ static void DoProc (void) { if (Tok == TOK_IDENT) { /* The new scope has a name */ - SymDef (SVal, GenCurrentPC (), IsZPSeg (), 1); + unsigned Flags = SYM_LABEL; + if (IsZPSeg ()) { + Flags |= SYM_ZP; + } + SymDef (SVal, GenCurrentPC (), Flags); NextTok (); } SymEnterLevel (); @@ -1418,6 +1422,14 @@ static void DoSmart (void) +static void DoStruct (void) +/* Struct definition */ +{ + Error (ERR_NOT_IMPLEMENTED); +} + + + static void DoSunPlus (void) /* Switch to the SUNPLUS CPU */ { @@ -1426,6 +1438,14 @@ static void DoSunPlus (void) +static void DoUnion (void) +/* Union definition */ +{ + Error (ERR_NOT_IMPLEMENTED); +} + + + static void DoUnexpected (void) /* Got an unexpected keyword */ { @@ -1525,6 +1545,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoUnexpected }, /* .ENDMACRO */ { ccNone, DoEndProc }, { ccNone, DoUnexpected }, /* .ENDREPEAT */ + { ccNone, DoUnexpected }, /* .ENDSTRUCT */ { ccNone, DoError }, { ccNone, DoExitMacro }, { ccNone, DoExport }, @@ -1589,9 +1610,12 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoUnexpected }, /* .STRAT */ { ccNone, DoUnexpected }, /* .STRING */ { ccNone, DoUnexpected }, /* .STRLEN */ + { ccNone, DoStruct }, { ccNone, DoSunPlus }, + { ccNone, DoUnexpected }, /* .TAG */ { ccNone, DoUnexpected }, /* .TCOUNT */ { ccNone, DoUnexpected }, /* .TIME */ + { ccNone, DoUnion }, { ccNone, DoUnexpected }, /* .VERSION */ { ccNone, DoWarning }, { ccNone, DoWord }, diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 12c92c86f..7ac09acdf 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -159,6 +159,7 @@ struct DotKeyword { { ".ENDPROC", TOK_ENDPROC }, { ".ENDREP", TOK_ENDREP }, { ".ENDREPEAT", TOK_ENDREP }, + { ".ENDSTRUCT", TOK_ENDSTRUCT }, { ".ERROR", TOK_ERROR }, { ".EXITMAC", TOK_EXITMACRO }, { ".EXITMACRO", TOK_EXITMACRO }, @@ -233,9 +234,12 @@ struct DotKeyword { { ".STRAT", TOK_STRAT }, { ".STRING", TOK_STRING }, { ".STRLEN", TOK_STRLEN }, + { ".STRUCT", TOK_STRUCT }, { ".SUNPLUS", TOK_SUNPLUS }, + { ".TAG", TOK_TAG }, { ".TCOUNT", TOK_TCOUNT }, { ".TIME", TOK_TIME }, + { ".UNION", TOK_UNION }, { ".VERSION", TOK_VERSION }, { ".WARNING", TOK_WARNING }, { ".WORD", TOK_WORD }, @@ -911,6 +915,11 @@ CharAgain: Tok = TOK_ULABEL; break; + case '=': + NextChar (); + Tok = TOK_ASSIGN; + break; + default: Tok = TOK_COLON; break; diff --git a/src/ca65/scanner.h b/src/ca65/scanner.h index 1ac9ff69b..f65ecde76 100644 --- a/src/ca65/scanner.h +++ b/src/ca65/scanner.h @@ -59,57 +59,58 @@ enum Token { TOK_MNEMO, /* A mnemonic */ TOK_INTCON, /* Integer constant */ - TOK_CHARCON, /* Character constant */ - TOK_STRCON, /* String constant */ - - TOK_A, /* A)ccu */ - TOK_X, /* X register */ - TOK_Y, /* Y register */ - TOK_S, /* S register */ - - TOK_ULABEL, /* :++ or :-- */ - - TOK_EQ, /* = */ - TOK_NE, /* <> */ - TOK_LT, /* < */ - TOK_GT, /* > */ - TOK_LE, /* <= */ - TOK_GE, /* >= */ - - TOK_BAND, /* .and */ - TOK_BOR, /* .or */ - TOK_BXOR, /* .xor */ - TOK_BNOT, /* .not */ - - TOK_PLUS, /* + */ - TOK_MINUS, /* - */ + TOK_CHARCON, /* Character constant */ + TOK_STRCON, /* String constant */ + + TOK_A, /* A)ccu */ + TOK_X, /* X register */ + TOK_Y, /* Y register */ + TOK_S, /* S register */ + + TOK_ASSIGN, /* := */ + TOK_ULABEL, /* :++ or :-- */ + + TOK_EQ, /* = */ + TOK_NE, /* <> */ + TOK_LT, /* < */ + TOK_GT, /* > */ + TOK_LE, /* <= */ + TOK_GE, /* >= */ + + TOK_BAND, /* .and */ + TOK_BOR, /* .or */ + TOK_BXOR, /* .xor */ + TOK_BNOT, /* .not */ + + TOK_PLUS, /* + */ + TOK_MINUS, /* - */ TOK_MUL, /* * */ TOK_STAR = TOK_MUL, /* Alias */ - TOK_DIV, /* / */ - TOK_MOD, /* ! */ - TOK_OR, /* | */ - TOK_XOR, /* ^ */ - TOK_AND, /* & */ - TOK_SHL, /* << */ - TOK_SHR, /* >> */ - TOK_NOT, /* ~ */ - - TOK_PC, /* $ if enabled */ + TOK_DIV, /* / */ + TOK_MOD, /* ! */ + TOK_OR, /* | */ + TOK_XOR, /* ^ */ + TOK_AND, /* & */ + TOK_SHL, /* << */ + TOK_SHR, /* >> */ + TOK_NOT, /* ~ */ + + TOK_PC, /* $ if enabled */ TOK_NAMESPACE, /* :: */ - TOK_DOT, /* . */ - TOK_COMMA, /* , */ - TOK_HASH, /* # */ - TOK_COLON, /* : */ - TOK_LPAREN, /* ( */ - TOK_RPAREN, /* ) */ - TOK_LBRACK, /* [ */ - TOK_RBRACK, /* ] */ + TOK_DOT, /* . */ + TOK_COMMA, /* , */ + TOK_HASH, /* # */ + TOK_COLON, /* : */ + TOK_LPAREN, /* ( */ + TOK_RPAREN, /* ) */ + TOK_LBRACK, /* [ */ + TOK_RBRACK, /* ] */ TOK_OVERRIDE_ZP, /* z: */ TOK_OVERRIDE_ABS, /* a: */ TOK_OVERRIDE_FAR, /* f: */ - TOK_MACPARAM, /* Macro parameter, not generated by scanner */ + TOK_MACPARAM, /* Macro parameter, not generated by scanner */ TOK_REPCOUNTER, /* Repeat counter, not generated by scanner */ /* The next ones are tokens for the pseudo instructions. Keep together! */ @@ -147,6 +148,7 @@ enum Token { TOK_ENDMACRO, TOK_ENDPROC, TOK_ENDREP, + TOK_ENDSTRUCT, TOK_ERROR, TOK_EXITMACRO, TOK_EXPORT, @@ -211,9 +213,12 @@ enum Token { TOK_STRAT, TOK_STRING, TOK_STRLEN, + TOK_STRUCT, TOK_SUNPLUS, + TOK_TAG, TOK_TCOUNT, TOK_TIME, + TOK_UNION, TOK_VERSION, TOK_WARNING, TOK_WORD, @@ -221,7 +226,7 @@ enum Token { TOK_ZEROPAGE, TOK_LASTPSEUDO = TOK_ZEROPAGE, - TOK_COUNT /* Count of tokens */ + TOK_COUNT /* Count of tokens */ }; diff --git a/src/ca65/symtab.c b/src/ca65/symtab.c index a89113d2b..09837720c 100644 --- a/src/ca65/symtab.c +++ b/src/ca65/symtab.c @@ -394,7 +394,7 @@ int SymIsLocalLevel (void) -void SymDef (const char* Name, ExprNode* Expr, int ZP, int Label) +void SymDef (const char* Name, ExprNode* Expr, unsigned Flags) /* Define a new symbol */ { /* Do we have such a symbol? */ @@ -422,10 +422,10 @@ void SymDef (const char* Name, ExprNode* Expr, int ZP, int Label) S->V.Expr = Expr; } S->Flags |= SF_DEFINED; - if (ZP) { + if (Flags & SYM_ZP) { S->Flags |= SF_ZP; } - if (Label) { + if (Flags & SYM_LABEL) { S->Flags |= SF_LABEL; } diff --git a/src/ca65/symtab.h b/src/ca65/symtab.h index 71cc42977..9c3c1987a 100644 --- a/src/ca65/symtab.h +++ b/src/ca65/symtab.h @@ -59,6 +59,11 @@ #define SCOPE_GLOBAL 1 #define SCOPE_LOCAL 2 +/* Flags used in SymDef */ +#define SYM_DEFAULT 0x00 +#define SYM_ZP 0x01 +#define SYM_LABEL 0x02 + /*****************************************************************************/ @@ -76,7 +81,7 @@ void SymLeaveLevel (void); int SymIsLocalLevel (void); /* Return true if we are on a local symbol table level. */ -void SymDef (const char* Name, ExprNode* Expr, int ZP, int Label); +void SymDef (const char* Name, ExprNode* Expr, unsigned Flags); /* Define a new symbol */ SymEntry* SymRef (const char* Name, int Scope);