X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=token.c;h=9d6decf5468709082b4c4551c4ed3948f219b837;hp=2e6c4563df05517a7e8cbb3e4bfcdb565d9fda4e;hb=9153334781cd2e23750f4dc002e847606c07a1f0;hpb=f3c7d186a15b89c39e360b9cc89545a0d24bd6a4 diff --git a/token.c b/token.c index 2e6c456..9d6decf 100644 --- a/token.c +++ b/token.c @@ -1,12 +1,14 @@ // // RMAC - Reboot's Macro Assembler for all Atari computers // TOKEN.C - Token Handling -// Copyright (C) 199x Landon Dyer, 2011-2017 Reboot and Friends +// Copyright (C) 199x Landon Dyer, 2011-2018 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 // Source utilised with the kind permission of Landon Dyer // #include "token.h" + +#include #include "direct.h" #include "error.h" #include "macro.h" @@ -32,7 +34,7 @@ char irbuf[LNSIZ]; // Text for .rept block line char lnbuf[LNSIZ]; // Text of current line WORD filecount; // Unique file number counter WORD cfileno; // Current file number -TOKENPTR tok; // Ptr to current token +TOKEN * tok; // Ptr to current token TOKEN * etok; // Ptr past last token in tokbuf[] TOKEN tokeol[1] = {EOL}; // Bailout end-of-line token char * string[TOKBUFSIZE*2];// Token buffer string pointer storage @@ -305,7 +307,7 @@ INOBJ * a_inobj(int typ) // Install INOBJ on top of input stack inobj->in_ifent = ifent; // Record .if context on entry inobj->in_type = (WORD)typ; - inobj->in_otok = tok.u32; + inobj->in_otok = tok; inobj->in_etok = etok; inobj->in_link = cur_inobj; cur_inobj = inobj; @@ -529,22 +531,12 @@ arg_num: switch ((int)*tk++) { case SYMBOL: -#if 0 -// d = (char *)*tk++; - d = string[*tk++]; -#else - // This fix should be done for strings too d = symbolString[*tk++]; DEBUG { printf("ExM: SYMBOL=\"%s\"", d); } -#endif break; case STRING: -#if 0 -// d = (char *)*tk++; - d = string[*tk++]; -#else d = symbolString[*tk++]; -#endif + if (dst >= edst) goto overflow; @@ -714,6 +706,11 @@ char * GetNextRepeatLine(void) // strp = irept->ir_nextln; } + // Mark the current macro line in the irept object + // This is probably overkill - a global variable + // would suffice here (it only gets used during + // error reporting anyway) + irept->lineno = irept->ir_nextln->lineno; // strcpy(irbuf, (char *)(irept->ir_nextln + 1)); strcpy(irbuf, irept->ir_nextln->line); @@ -791,7 +788,7 @@ int fpop(void) if (numUnmatched > 0) warn("missing %d .endif(s)", numUnmatched); - tok.u32 = inobj->in_otok; // Restore tok and otok + tok = inobj->in_otok; // Restore tok and otok etok = inobj->in_etok; switch (inobj->in_type) @@ -946,7 +943,7 @@ int TokenizeLine(void) { uint8_t * ln = NULL; // Ptr to current position in line uint8_t * p; // Random character ptr - TOKENPTR tk; // Token-deposit ptr + PTR tk; // Token-deposit ptr int state = 0; // State for keyword detector int j = 0; // Var for keyword detector uint8_t c; // Random char @@ -960,7 +957,7 @@ int TokenizeLine(void) retry: - if (cur_inobj == NULL) // Return EOF if input stack is empty + if (cur_inobj == NULL) // Return EOF if input stack is empty return TKEOF; // Get another line of input from the current input source: a file, a @@ -976,8 +973,8 @@ retry: if ((ln = GetNextLine()) == NULL) { DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); } - if (fpop() == 0) // Pop input level - goto retry; // Try for more lines + if (fpop() == 0) // Pop input level + goto retry; // Try for more lines else { ifent->if_prev = (IFENT *)-1; //Signal Assemble() that we have reached EOF with unbalanced if/endifs @@ -985,7 +982,7 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); } } } - curlineno++; // Bump line number + curlineno++; // Bump line number lntag = SPACE; if (as68_flag) @@ -1047,7 +1044,7 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); } strcpy(lnbuf, ln); // General housekeeping - tok.u32 = tokeol; // Set "tok" to EOL in case of error + tok = tokeol; // Set "tok" to EOL in case of error tk.u32 = etok; // Reset token ptr stuffnull = 0; // Don't stuff nulls totlines++; // Bump total #lines assembled @@ -1195,16 +1192,9 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); } if ((j < 0) || (state < 0)) { *tk.u32++ = SYMBOL; -//#warning -//problem here: nullspot is a char * but TOKEN is a uint32_t. On a 64-bit -//system, this will cause all kinds of mischief. -#if 0 - *tk++ = (TOKEN)nullspot; -#else string[stringNum] = nullspot; *tk.u32++ = stringNum; stringNum++; -#endif } else { @@ -1212,10 +1202,10 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); } stuffnull = 0; } - if (v) // Record attribute token (if any) + if (v) // Record attribute token (if any) *tk.u32++ = (TOKEN)v; - if (stuffnull) // Arrange for string termination on next pass + if (stuffnull) // Arrange for string termination on next pass nullspot = ln; continue; @@ -1593,20 +1583,8 @@ dostring: else if ((int)chrtab[*(ln + 1)] & DIGIT) { // Hey, more digits after the dot, so we assume it's a - // floating point number of some kind -#if 0 - double fract = 10; - ln++; - f = (double)v; - - while ((int)chrtab[*ln] & DIGIT) - { - f = f + (double)(*ln++ - '0') / fract; - fract *= 10; - } -#else - // Here we parse the whole floating point number -#include + // floating point number of some kind... numEnd will point + // to the first non-float character after it's done char * numEnd; errno = 0; double f = strtod(numStart, &numEnd); @@ -1614,11 +1592,14 @@ dostring: if (errno != 0) return error("floating point parse error"); -#endif + // N.B.: We use the C compiler's internal double + // representation for all internal float calcs and + // are reasonably sure that the size of said double + // is 8 bytes long (which we check for in fltpoint.c) *tk.u32++ = FCONST; -// Shamus: Well, this is all kinds of icky--not the least of which is that unlike uintNN_t types, we have no guarantees of any kind when it comes to the size of floating point numbers in C (as far as I know of). If there is, we need to use those kinds here, or else figure out at runtime what sizes we're dealing with and act accordingly. To be fair, this is OK as long as the double type is less than 64 bits wide, but again, there's no guarantee that it isn't. :-/ - *tk.u64++ = f; + *tk.dp = f; + tk.u64++; continue; } } @@ -1639,9 +1620,9 @@ dostring: // Terminate line of tokens and return "success." goteol: - tok.u32 = etok; // Set tok to beginning of line + tok = etok; // Set tok to beginning of line - if (stuffnull) // Terminate last SYMBOL + if (stuffnull) // Terminate last SYMBOL *nullspot = EOS; *tk.u32++ = EOL; @@ -1668,11 +1649,11 @@ goteol: int d_goto(WORD unused) { // Setup for the search - if (*tok.u32 != SYMBOL) + if (*tok != SYMBOL) return error("missing label"); - char * sym = string[tok.u32[1]]; - tok.u32 += 2; + char * sym = string[tok[1]]; + tok += 2; if (cur_inobj->in_type != SRC_IMACRO) return error("goto not in macro"); @@ -1721,6 +1702,8 @@ void DumpToken(TOKEN t) printf("[COLON]"); else if (t == CONST) printf("[CONST]"); + else if (t == FCONST) + printf("[FCONST]"); else if (t == ACONST) printf("[ACONST]"); else if (t == STRING) @@ -1804,8 +1787,16 @@ void DumpTokenBuffer(void) printf("[COLON]"); else if (*t == CONST) { - TOKENPTR tp = (TOKENPTR)(t + 1); - printf("[CONST: $%lX]", (uint64_t)(*tp.u64)); + PTR tp; + tp.u32 = t + 1; + printf("[CONST: $%lX]", *tp.u64); + t += 2; + } + else if (*t == FCONST) + { + PTR tp; + tp.u32 = t + 1; + printf("[FCONST: $%lX]", *tp.u64); t += 2; } else if (*t == ACONST)