//
// 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-2020 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
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;
// to choke on legitimate code... Need to investigate this further
// before changing anything else here!
case CONST:
- sprintf(numbuf, "$%lx", (uint64_t)*tk++);
+// sprintf(numbuf, "$%lx", (uint64_t)*tk++);
+ sprintf(numbuf, "$%" PRIX64, (uint64_t)*tk++);
tk++;
d = numbuf;
break;
case CR_ABSCOUNT:
d = "^^abscount";
break;
+ case CR_FILESIZE:
+ d = "^^filesize";
+ break;
case CR_DATE:
d = "^^date";
break;
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;
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
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
}
}
- curlineno++; // Bump line number
+ curlineno++; // Bump line number
lntag = SPACE;
if (as68_flag)
// 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
+ 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
// 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++;
}
// Make j = -1 if user tries to use a RISC register while in 68K mode
- if (!(rgpu || rdsp) && ((TOKEN)j >= KW_R0 && (TOKEN)j <= KW_R31))
+ if (!(rgpu || rdsp || dsp56001) && ((TOKEN)j >= KW_R0 && (TOKEN)j <= KW_R31))
{
j = -1;
}
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
{
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;
case '\\':
c = '\\';
break;
+ case '{':
+ // If we're evaluating a macro
+ // this is valid because it's
+ // a parameter expansion
case '!':
// If we're evaluating a macro
// this is valid and expands to
while (hextab[*ln] >= 0)
v = (v << 4) + (int)hextab[*ln++];
- if (*ln == '.')
- {
- if (obj_format == BSD)
- {
- if ((*(ln + 1) & 0xDF) == 'B')
- {
- v &= 0x000000FF;
- ln += 2;
- }
- else if ((*(ln + 1) & 0xDF) == 'W')
- {
- v &= 0x0000FFFF;
- ln += 2;
- }
- else if ((*(ln + 1) & 0xDF) == 'L')
- {
- v &= 0xFFFFFFFF;
- ln += 2;
- }
- }
- }
-
*tk.u32++ = CONST;
*tk.u64++ = v;
- if (obj_format == ALCYON)
+ if (*ln == '.')
{
- if (*ln == '.')
+ if ((*(ln + 1) == 'w') || (*(ln + 1) == 'W'))
{
- if ((*(ln + 1) == 'w') || (*(ln + 1) == 'W'))
- {
- *tk.u32++ = DOTW;
- ln += 2;
- }
- else if ((*(ln + 1) == 'l') || (*(ln + 1) == 'L'))
- {
- *tk.u32++ = DOTL;
- ln += 2;
- }
+ *tk.u32++ = DOTW;
+ ln += 2;
+ }
+ else if ((*(ln + 1) == 'l') || (*(ln + 1) == 'L'))
+ {
+ *tk.u32++ = DOTL;
+ ln += 2;
}
}
}
// Terminate line of tokens and return "success."
goteol:
- tok = 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;
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)