Initialize maxRecursionDepth with other options

This commit is contained in:
Rangi42
2025-07-21 19:58:37 -04:00
parent ee0f311c10
commit 8d268e8a8a
5 changed files with 12 additions and 17 deletions

View File

@@ -75,6 +75,6 @@ void fstk_RunFor(
bool fstk_Break(); bool fstk_Break();
void fstk_NewRecursionDepth(size_t newDepth); void fstk_NewRecursionDepth(size_t newDepth);
void fstk_Init(std::string const &mainPath, size_t maxDepth); void fstk_Init(std::string const &mainPath);
#endif // RGBDS_ASM_FSTACK_HPP #endif // RGBDS_ASM_FSTACK_HPP

View File

@@ -15,7 +15,7 @@ enum MissingInclude {
struct Options { struct Options {
uint8_t fixPrecision = 16; // -Q uint8_t fixPrecision = 16; // -Q
size_t maxRecursionDepth; // -r size_t maxRecursionDepth = 64; // -r
char binDigits[2] = {'0', '1'}; // -b char binDigits[2] = {'0', '1'}; // -b
char gfxDigits[4] = {'0', '1', '2', '3'}; // -g char gfxDigits[4] = {'0', '1', '2', '3'}; // -g
bool verbose = false; // -v bool verbose = false; // -v

View File

@@ -410,11 +410,9 @@ void fstk_NewRecursionDepth(size_t newDepth) {
options.maxRecursionDepth = newDepth; options.maxRecursionDepth = newDepth;
} }
void fstk_Init(std::string const &mainPath, size_t maxDepth) { void fstk_Init(std::string const &mainPath) {
newFileContext(mainPath, true); newFileContext(mainPath, true);
options.maxRecursionDepth = maxDepth;
for (std::string const &name : preIncludeNames) { for (std::string const &name : preIncludeNames) {
if (std::optional<std::string> fullPath = fstk_FindFile(name); fullPath) { if (std::optional<std::string> fullPath = fstk_FindFile(name); fullPath) {
newFileContext(*fullPath, false); newFileContext(*fullPath, false);

View File

@@ -165,26 +165,23 @@ static std::vector<StateFeature> parseStateFeatures(char *str) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
time_t now = time(nullptr);
// Support SOURCE_DATE_EPOCH for reproducible builds // Support SOURCE_DATE_EPOCH for reproducible builds
// https://reproducible-builds.org/docs/source-date-epoch/ // https://reproducible-builds.org/docs/source-date-epoch/
time_t now = time(nullptr);
if (char const *sourceDateEpoch = getenv("SOURCE_DATE_EPOCH"); sourceDateEpoch) { if (char const *sourceDateEpoch = getenv("SOURCE_DATE_EPOCH"); sourceDateEpoch) {
now = static_cast<time_t>(strtoul(sourceDateEpoch, nullptr, 0)); now = static_cast<time_t>(strtoul(sourceDateEpoch, nullptr, 0));
} }
// Perform some init for below
sym_Init(now); sym_Init(now);
// Set defaults // Maximum of 100 errors only applies if rgbasm is printing errors to a terminal
sym_SetExportAll(false);
uint32_t maxDepth = 64;
char const *dependFileName = nullptr;
std::unordered_map<std::string, std::vector<StateFeature>> stateFileSpecs;
// Maximum of 100 errors only applies if rgbasm is printing errors to a terminal.
if (isatty(STDERR_FILENO)) { if (isatty(STDERR_FILENO)) {
options.maxErrors = 100; options.maxErrors = 100;
} }
// Local options
char const *dependFileName = nullptr; // -M
std::unordered_map<std::string, std::vector<StateFeature>> stateFileSpecs; // -s
for (int ch; (ch = musl_getopt_long_only(argc, argv, optstring, longopts, nullptr)) != -1;) { for (int ch; (ch = musl_getopt_long_only(argc, argv, optstring, longopts, nullptr)) != -1;) {
switch (ch) { switch (ch) {
char *endptr; char *endptr;
@@ -295,7 +292,7 @@ int main(int argc, char *argv[]) {
} }
case 'r': case 'r':
maxDepth = strtoul(musl_optarg, &endptr, 0); options.maxRecursionDepth = strtoul(musl_optarg, &endptr, 0);
if (musl_optarg[0] == '\0' || *endptr != '\0') { if (musl_optarg[0] == '\0' || *endptr != '\0') {
fatal("Invalid argument for option 'r'"); fatal("Invalid argument for option 'r'");
@@ -415,7 +412,7 @@ int main(int argc, char *argv[]) {
charmap_New(DEFAULT_CHARMAP_NAME, nullptr); charmap_New(DEFAULT_CHARMAP_NAME, nullptr);
// Init lexer and file stack, providing file info // Init lexer and file stack, providing file info
fstk_Init(mainFileName, maxDepth); fstk_Init(mainFileName);
// Perform parse (`yy::parser` is auto-generated from `parser.y`) // Perform parse (`yy::parser` is auto-generated from `parser.y`)
if (yy::parser parser; parser.parse() != 0) { if (yy::parser parser; parser.parse() != 0) {

View File

@@ -36,7 +36,7 @@ static char savedTIME[256];
static char savedDATE[256]; static char savedDATE[256];
static char savedTIMESTAMP_ISO8601_LOCAL[256]; static char savedTIMESTAMP_ISO8601_LOCAL[256];
static char savedTIMESTAMP_ISO8601_UTC[256]; static char savedTIMESTAMP_ISO8601_UTC[256];
static bool exportAll; // -E static bool exportAll = false; // -E
bool sym_IsPC(Symbol const *sym) { bool sym_IsPC(Symbol const *sym) {
return sym == PCSymbol; return sym == PCSymbol;