Implement almost all functionality

Add keywords and identifiers
Add comments
Add number literals
Add strings
Add a lot of new tokens
Add (and clean up) IF etc.
Improve reporting of unexpected chars / garbage bytes
Fix bug with and improved error messages when failing to open file
Add verbose-level messages about how files are opened
Enforce that files finish with a newline
Fix chars returned not being cast to unsigned char (may conflict w/ EOF)
Return null path when no file is open, rather than crash
Unify and improve error printing slightly

Known to be missing: macro expansion, REPT blocks, EQUS expansions
This commit is contained in:
ISSOtm
2020-07-28 22:06:03 +02:00
parent 71f8871702
commit 4c9a929a14
12 changed files with 1139 additions and 235 deletions

View File

@@ -210,8 +210,6 @@ void sym_Purge(char const *symName)
labelScope = NULL;
hash_RemoveElement(symbols, symbol->name);
if (symbol->type == SYM_MACRO)
free(symbol->macro);
free(symbol);
}
}
@@ -230,7 +228,22 @@ uint32_t sym_GetPCValue(void)
}
/*
* Return a constant symbols value
* Return a constant symbol's value, assuming it's defined
*/
uint32_t sym_GetConstantSymValue(struct Symbol const *sym)
{
if (sym == PCSymbol)
return sym_GetPCValue();
else if (!sym_IsConstant(sym))
error("\"%s\" does not have a constant value\n", sym->name);
else
return sym_GetValue(sym);
return 0;
}
/*
* Return a constant symbol's value
*/
uint32_t sym_GetConstantValue(char const *s)
{
@@ -238,12 +251,8 @@ uint32_t sym_GetConstantValue(char const *s)
if (sym == NULL)
error("'%s' not defined\n", s);
else if (sym == PCSymbol)
return sym_GetPCValue();
else if (!sym_IsConstant(sym))
error("\"%s\" does not have a constant value\n", s);
else
return sym_GetValue(sym);
return sym_GetConstantSymValue(sym);
return 0;
}
@@ -468,13 +477,13 @@ void sym_Export(char const *symName)
/*
* Add a macro definition
*/
struct Symbol *sym_AddMacro(char const *symName, int32_t defLineNo)
struct Symbol *sym_AddMacro(char const *symName, int32_t defLineNo, char const *body, size_t size)
{
struct Symbol *sym = createNonrelocSymbol(symName);
sym->type = SYM_MACRO;
sym->macroSize = ulNewMacroSize;
sym->macro = tzNewMacro;
sym->macroSize = size;
sym->macro = body;
updateSymbolFilename(sym);
/*
* The symbol is created at the line after the `endm`,