mirror of
https://github.com/gbdev/rgbds.git
synced 2026-01-04 23:51:52 +00:00
Implement compact file stacks in object files
Gets rid of `open_memstream`, enabling Windows compatibility again Also fixes #491 as a nice bonus!
This commit is contained in:
@@ -21,26 +21,44 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
struct MacroArgs;
|
||||
struct FileStackNode {
|
||||
struct FileStackNode *parent; /* Pointer to parent node, for error reporting */
|
||||
/* Line at which the parent context was exited; meaningless for the root level */
|
||||
uint32_t lineNo;
|
||||
|
||||
struct sContext {
|
||||
struct LexerState *lexerState;
|
||||
struct Symbol const *pMacro;
|
||||
struct sContext *next;
|
||||
char tzFileName[_MAX_PATH + 1];
|
||||
struct MacroArgs *macroArgs;
|
||||
uint32_t uniqueID;
|
||||
int32_t nLine;
|
||||
uint32_t nStatus;
|
||||
char const *pREPTBlock;
|
||||
uint32_t nREPTBlockCount;
|
||||
uint32_t nREPTBlockSize;
|
||||
int32_t nREPTBodyFirstLine;
|
||||
int32_t nREPTBodyLastLine;
|
||||
struct FileStackNode *next; /* Next node in the output linked list */
|
||||
bool referenced; /* If referenced, don't free! */
|
||||
uint32_t ID; /* Set only if referenced: ID within the object file, -1 if not output yet */
|
||||
|
||||
enum {
|
||||
NODE_REPT,
|
||||
NODE_FILE,
|
||||
NODE_MACRO,
|
||||
} type;
|
||||
};
|
||||
|
||||
struct FileStackReptNode { /* NODE_REPT */
|
||||
struct FileStackNode node;
|
||||
uint32_t reptDepth;
|
||||
/* WARNING: if changing this type, change overflow check in `fstk_Init` */
|
||||
uint32_t iters[]; /* REPT iteration counts since last named node, in reverse depth order */
|
||||
};
|
||||
|
||||
struct FileStackNamedNode { /* NODE_FILE, NODE_MACRO */
|
||||
struct FileStackNode node;
|
||||
char name[]; /* File name for files, file::macro name for macros */
|
||||
};
|
||||
|
||||
extern size_t nMaxRecursionDepth;
|
||||
|
||||
struct MacroArgs;
|
||||
|
||||
void fstk_Dump(struct FileStackNode const *node, uint32_t lineNo);
|
||||
void fstk_DumpCurrent(void);
|
||||
struct FileStackNode *fstk_GetFileStack(void);
|
||||
/* The lifetime of the returned chars is until reaching the end of that file */
|
||||
char const *fstk_GetFileName(void);
|
||||
|
||||
void fstk_AddIncludePath(char const *s);
|
||||
/**
|
||||
* @param path The user-provided file name
|
||||
@@ -53,14 +71,9 @@ bool fstk_FindFile(char const *path, char **fullPath, size_t *size);
|
||||
|
||||
bool yywrap(void);
|
||||
void fstk_RunInclude(char const *path);
|
||||
void fstk_RunMacro(char *macroName, struct MacroArgs *args);
|
||||
void fstk_RunMacro(char const *macroName, struct MacroArgs *args);
|
||||
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, size_t maxRecursionDepth);
|
||||
void fstk_Init(char const *mainPath, size_t maxRecursionDepth);
|
||||
|
||||
#endif /* RGBDS_ASM_FSTACK_H */
|
||||
|
||||
@@ -43,6 +43,9 @@ static inline void lexer_SetGfxDigits(char const *digits)
|
||||
gfxDigits = digits;
|
||||
}
|
||||
|
||||
/*
|
||||
* `path` is referenced, but not held onto..!
|
||||
*/
|
||||
struct LexerState *lexer_OpenFile(char const *path);
|
||||
struct LexerState *lexer_OpenFileView(char *buf, size_t size, uint32_t lineNo);
|
||||
void lexer_RestartRept(uint32_t lineNo);
|
||||
|
||||
@@ -18,6 +18,8 @@ struct Expression;
|
||||
extern char *tzObjectname;
|
||||
extern struct Section *pSectionList, *pCurrentSection;
|
||||
|
||||
void out_RegisterNode(struct FileStackNode *node);
|
||||
void out_ReplaceNode(struct FileStackNode *node);
|
||||
void out_SetFileName(char *s);
|
||||
void out_CreatePatch(uint32_t type, struct Expression const *expr,
|
||||
uint32_t ofs);
|
||||
|
||||
@@ -35,8 +35,8 @@ struct Symbol {
|
||||
bool isExported; /* Whether the symbol is to be exported */
|
||||
bool isBuiltin; /* Whether the symbol is a built-in */
|
||||
struct Section *section;
|
||||
char fileName[_MAX_PATH + 1]; /* File where the symbol was defined. */
|
||||
uint32_t fileLine; /* Line where the symbol was defined. */
|
||||
struct FileStackNode *src; /* Where the symbol was defined */
|
||||
uint32_t fileLine; /* Line where the symbol was defined */
|
||||
|
||||
bool hasCallback;
|
||||
union {
|
||||
|
||||
Reference in New Issue
Block a user