From 359a89d0bfc1f6bf089b8f622e9a2450c5b47c4e Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 15 Jul 2000 10:33:32 +0000 Subject: [PATCH] Added the .TCOUNT function git-svn-id: svn://svn.cc65.org/cc65/trunk@151 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/expr.c | 48 +++++++++++++++++++++++++++++++++++++++++++--- src/ca65/pseudo.c | 1 + src/ca65/scanner.c | 1 + src/ca65/scanner.h | 3 ++- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/ca65/expr.c b/src/ca65/expr.c index 44c7524d1..0bad48328 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -117,7 +117,7 @@ static void FreeExprNode (ExprNode* E) /* Dump an expression tree on stdout for debugging */ /*****************************************************************************/ - + static void InternalDumpExpr (ExprNode* Expr) /* Dump an expression in UPN */ @@ -467,6 +467,44 @@ static int FuncReferenced (void) +static int FuncTCount (void) +/* Handle the .TCOUNT function */ +{ + /* We have a list of tokens that ends with the closing paren. Skip + * the tokens, handling nested braces and count them. + */ + int Count = 0; + unsigned Parens = 0; + while (Parens != 0 || Tok != TOK_RPAREN) { + + /* Check for end of line or end of input. Since the calling function + * will check for the closing paren, we don't need to print an error + * here, just bail out. + */ + if (Tok == TOK_SEP || Tok == TOK_EOF) { + break; + } + + /* One more token */ + ++Count; + + /* Keep track of the nesting level */ + switch (Tok) { + case TOK_LPAREN: ++Parens; break; + case TOK_RPAREN: --Parens; break; + default: break; + } + + /* Skip the token */ + NextTok (); + } + + /* Return the number of tokens */ + return Count; +} + + + static int FuncXMatch (void) /* Handle the .XMATCH function */ { @@ -492,7 +530,7 @@ static ExprNode* Function (int (*F) (void)) NextTok (); /* Call the function itself */ - Result = (F () != 0); + Result = F (); /* Closing brace must follow */ ConsumeRParen (); @@ -509,7 +547,7 @@ static ExprNode* Factor (void) SymEntry* S; switch (Tok) { - + case TOK_INTCON: case TOK_CHARCON: N = LiteralExpr (IVal); @@ -620,6 +658,10 @@ static ExprNode* Factor (void) N = Function (FuncReferenced); break; + case TOK_TCOUNT: + N = Function (FuncTCount); + break; + case TOK_XMATCH: N = Function (FuncXMatch); break; diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index ea222968f..f41a3968b 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -1164,6 +1164,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoSmart }, { ccNone, DoUnexpected }, /* .STRING */ { ccNone, DoSunPlus }, + { ccNone, DoUnexpected }, /* .TCOUNT */ { ccNone, DoWord }, { ccNone, DoUnexpected }, /* .XMATCH */ { ccNone, DoZeropage }, diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index c737f6c6f..e51009cfa 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -221,6 +221,7 @@ struct DotKeyword { { "SMART", TOK_SMART }, { "STRING", TOK_STRING }, { "SUNPLUS", TOK_SUNPLUS }, + { "TCOUNT", TOK_TCOUNT }, { "WORD", TOK_WORD }, { "XMATCH", TOK_XMATCH }, { "XOR", TOK_BXOR }, diff --git a/src/ca65/scanner.h b/src/ca65/scanner.h index dea582994..8f5e4486c 100644 --- a/src/ca65/scanner.h +++ b/src/ca65/scanner.h @@ -183,13 +183,14 @@ enum Token { TOK_REFERENCED, TOK_RELOC, TOK_REPEAT, - TOK_RES, + TOK_RES, TOK_RIGHT, TOK_RODATA, TOK_SEGMENT, TOK_SMART, TOK_STRING, TOK_SUNPLUS, + TOK_TCOUNT, TOK_WORD, TOK_XMATCH, TOK_ZEROPAGE, -- 2.39.5