//
-// RMAC - Reboot's Macro Assembler for all Atari computers
+// RMAC - Renamed Macro Assembler for all Atari computers
// TOKEN.C - Token Handling
-// Copyright (C) 199x Landon Dyer, 2011-2019 Reboot and Friends
+// Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends
// RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
// Source utilised with the kind permission of Landon Dyer
//
int lnsave; // 1; strcpy() text of current line
-uint16_t curlineno; // Current line number (64K max currently)
+uint32_t curlineno; // Current line number (64K max currently)
int totlines; // Total # of lines
int mjump_align = 0; // mjump alignment flag
char lntag; // Line tag
char * string[TOKBUFSIZE*2];// Token buffer string pointer storage
int optimizeOff; // Optimization override flag
-// File record, used to maintain a list of every include file ever visited
-#define FILEREC struct _filerec
-FILEREC
-{
- FILEREC * frec_next;
- char * frec_name;
-};
FILEREC * filerec;
FILEREC * last_fr;
case CR_ABSCOUNT:
d = "^^abscount";
break;
+ case CR_FILESIZE:
+ d = "^^filesize";
+ break;
case CR_DATE:
d = "^^date";
break;
char * GetNextMacroLine(void)
{
IMACRO * imacro = cur_inobj->inobj.imacro;
-// LONG * strp = imacro->im_nextln;
LLIST * strp = imacro->im_nextln;
if (strp == NULL) // End-of-macro
DEBUG { printf("end-repeat-block\n"); }
return NULL;
}
-
+ reptuniq++;
// strp = irept->ir_nextln;
}
// Mark the current macro line in the irept object
// error reporting anyway)
irept->lineno = irept->ir_nextln->lineno;
-// strcpy(irbuf, (char *)(irept->ir_nextln + 1));
- strcpy(irbuf, irept->ir_nextln->line);
+ // Copy the rept lines verbatim, unless we're in nest level 0.
+ // Then, expand any \~ labels to unique numbers (Rn)
+ if (rptlevel)
+ {
+ strcpy(irbuf, irept->ir_nextln->line);
+ }
+ else
+ {
+ uint32_t linelen = strlen(irept->ir_nextln->line);
+ uint8_t *p_line = irept->ir_nextln->line;
+ char *irbufwrite = irbuf;
+ for (int i = 0; i <= linelen; i++)
+ {
+ uint8_t c;
+ c = *p_line++;
+ if (c == '\\' && *p_line == '~')
+ {
+ p_line++;
+ irbufwrite += sprintf(irbufwrite, "R%u", reptuniq);
+ }
+ else
+ {
+ *irbufwrite++ = c;
+ }
+ }
+ }
+
DEBUG { printf("repeat line='%s'\n", irbuf); }
// irept->ir_nextln = (LONG *)*strp;
irept->ir_nextln = irept->ir_nextln->next;
if (numUnmatched > 0)
warn("missing %d .endif(s)", numUnmatched);
- tok = inobj->in_otok; // Restore tok and otok
+ tok = inobj->in_otok; // Restore tok and etok
etok = inobj->in_etok;
switch (inobj->in_type)
uint8_t c; // Random char
uint64_t v; // Random value
uint32_t cursize = 0; // Current line's size (.b, .w, .l, .s, .q, .d)
- double f; // Random float
uint8_t * nullspot = NULL; // Spot to clobber for SYMBOL termination
int stuffnull; // 1:terminate SYMBOL '\0' at *nullspot
uint8_t c1;
int stringNum = 0; // Pointer to string locations in tokenized line
+ SYM* sy; // For looking up symbols (.equr)
+ int equrundef = 0; // Flag for equrundef scanning
retry:
curlineno++; // Bump line number
lntag = SPACE;
- if (as68_flag)
- {
- // AS68 compatibility, throw away all lines starting with
- // back-quotes, tildes, or '*'
- // On other lines, turn the first '*' into a semi-colon.
- if (*ln == '`' || *ln == '~' || *ln == '*')
- *ln = ';';
- else
- {
- for(p=ln; *p!=EOS; p++)
- {
- if (*p == '*')
- {
- *p = ';';
- break;
- }
- }
- }
- }
-
break;
// Macro-block:
// macro-type blocks, since it is expensive to unconditionally copy every
// line.
if (lnsave)
+ {
+ // Sanity check
+ if (strlen(ln) > LNSIZ)
+ return error("line too long (%d, max %d)", strlen(ln), LNSIZ);
+
strcpy(lnbuf, ln);
+ }
// General housekeeping
tok = tokeol; // Set "tok" to EOL in case of error
// o handle multiple-character tokens (constants, strings, etc.).
for(; *ln!=EOS;)
{
+ // Check to see if there's enough space in the token buffer
+ if (tk.cp >= ((uint8_t *)(&tokbuf[TOKBUFSIZE])) - 20)
+ {
+ return error("token buffer overrun");
+ }
+
// Skip whitespace, handle EOL
while (chrtab[*ln] & WHITE)
ln++;
case 121: // date
j = -1;
}
+
+ // If we detected equrundef/regundef set relevant flag
+ if (j == KW_EQURUNDEF)
+ {
+ equrundef = 1;
+ j = -1;
+ //printf("line %d, equrundef found\n", curlineno);
+ }
// If not tokenized keyword OR token was not found
if ((j < 0) || (state < 0))
{
+ // Only proceed if no equrundef has been detected. In that case we need to store the symbol
+ // because the directive handler (d_equrundef) will run outside this loop, further into procln.c
+ if (!equrundef)
+ {
+ // Last attempt: let's see if this is an equated register
+ char temp = *ln;
+ *ln = 0;
+ sy = lookup(nullspot, LABEL, 0);
+ *ln = temp;
+ if (sy)
+ {
+ if (sy->sattre & EQUATEDREG)
+ {
+ uint32_t register_token = sy->svalue;
+ if (rgpu || rdsp)
+ {
+ // If we are in GPU or DSP mode then mark the register bank.
+ // We will use it during EvaluateRegisterFromTokenStream()
+ // when we check if we can use the equated register with the currently
+ // selected bank.
+ // Note (ggn): I find all this superfluous. Do we really want to be so
+ // protective? Plus, the current implementation happily skips
+ // these checks on .equr that are set during fixups - oops!
+ register_token |= 0x80000000; // Mark that this is an .equr
+ if (sy->sattre & BANK_1)
+ {
+ register_token |= 0x40000000; // Mark bank 1
+ }
+ }
+ *tk.u32++ = register_token;
+ stuffnull = 0;
+ continue;
+ }
+ }
+ }
+ // Ok, that failed, let's store the symbol instead
*tk.u32++ = SYMBOL;
string[stringNum] = nullspot;
*tk.u32++ = stringNum;
{
// Compare names (sleazo string compare)
char * s1 = sym;
- char * s2 = defln->line;
+ char * s2 = defln->line + 1;
// Either we will match the strings to EOS on both, or we will
// match EOS on string 1 to whitespace on string 2. Otherwise, we
printf("[ENDEXPR]");
else if (t == CR_ABSCOUNT)
printf("[CR_ABSCOUNT]");
+ else if (t == CR_FILESIZE)
+ printf("[CR_FILESIZE]");
else if (t == CR_DEFINED)
printf("[CR_DEFINED]");
else if (t == CR_REFERENCED)
printf("[ENDEXPR]");
else if (*t == CR_ABSCOUNT)
printf("[CR_ABSCOUNT]");
+ else if (*t == CR_FILESIZE)
+ printf("[CR_FILESIZE]");
else if (*t == CR_DEFINED)
printf("[CR_DEFINED]");
else if (*t == CR_REFERENCED)