SECTION(symbol) returns the name of a symbol's section (#1066)

Fixes #963

Co-authored-by: Eldred Habert <eldredhabert0@gmail.com>
This commit is contained in:
Rangi
2022-09-29 19:59:33 -04:00
committed by GitHub
parent c35cb6ac32
commit dec4133e84
13 changed files with 60 additions and 0 deletions

View File

@@ -1589,6 +1589,19 @@ string : T_STRING
strfmt($$, sizeof($$), $3.format, $3.nbArgs, $3.args);
freeStrFmtArgList(&$3);
}
| T_POP_SECTION T_LPAREN scoped_anon_id T_RPAREN {
struct Symbol *sym = sym_FindScopedSymbol($3);
if (!sym)
fatalerror("Unknown symbol \"%s\"\n", $3);
struct Section const *section = sym_GetSection(sym);
if (!section)
fatalerror("\"%s\" does not belong to any section\n", sym->name);
// Section names are capped by rgbasm's maximum string length,
// so this currently can't overflow.
strcpy($$, section->name);
}
;
strcat_args : string