Implement __FILE__ symbol

Also clean up built-in symbol creation
This is not great, but currently okay.
Should be fixed later, like the rest...
This commit is contained in:
ISSOtm
2020-08-16 13:33:06 +02:00
parent 62ecdce0b0
commit fd02ffb7bd
5 changed files with 90 additions and 34 deletions

View File

@@ -58,6 +58,7 @@ void fstk_RunRept(uint32_t count, int32_t nReptLineNo, char *body, size_t size);
void fstk_Dump(void);
char *fstk_DumpToStr(void);
char const *fstk_GetFileName(void);
uint32_t fstk_GetLine(void);
void fstk_Init(char *mainPath, uint32_t maxRecursionDepth);

View File

@@ -38,14 +38,19 @@ struct Symbol {
char fileName[_MAX_PATH + 1]; /* File where the symbol was defined. */
uint32_t fileLine; /* Line where the symbol was defined. */
bool hasCallback;
union {
struct { /* If sym_IsNumeric */
union { /* Otherwise */
/* If sym_IsNumeric */
int32_t value;
int32_t (*callback)(void);
};
struct { /* For SYM_MACRO */
size_t macroSize;
char *macro;
int32_t (*numCallback)(void);
/* For SYM_MACRO */
struct {
size_t macroSize;
char *macro;
};
/* For SYM_EQUS, TODO: separate "base" fields from SYM_MACRO */
char const *(*strCallback)(void); /* For SYM_EQUS */
};
};
@@ -101,6 +106,8 @@ static inline bool sym_IsExported(struct Symbol const *sym)
*/
static inline char const *sym_GetStringValue(struct Symbol const *sym)
{
if (sym->hasCallback)
return sym->strCallback();
return sym->macro;
}