shithub: rgbds

Download patch

ref: c135e2c6a0ec8db1fe0380d9c4cb84a5ef74eea1
parent: 12693081c993af55a6bd6009f18bc08efaed0b70
author: ISSOtm <[email protected]>
date: Sun May 3 15:06:48 EDT 2020

Fix local sym names not being expanded by `PURGE`

And an additional bug that broke the attached test

--- a/include/hashmap.h
+++ b/include/hashmap.h
@@ -11,6 +11,7 @@
 #define RGBDS_LINK_HASHMAP_H
 
 #include <assert.h>
+#include <stdbool.h>
 
 #define HASH_NB_BITS 32
 #define HALF_HASH_NB_BITS 16
--- a/src/asm/symbol.c
+++ b/src/asm/symbol.c
@@ -208,7 +208,7 @@
 		yyerror("Symbol \"%s\" is referenced and thus cannot be purged",
 			symName);
 	} else {
-		hash_RemoveElement(symbols, symName);
+		hash_RemoveElement(symbols, symbol->name);
 		if (symbol->type == SYM_MACRO)
 			free(symbol->macro);
 		free(symbol);
@@ -476,11 +476,14 @@
 
 	if (nsym == NULL) {
 		char fullname[MAXSYMLEN + 1];
+		struct Symbol const *scope = NULL;
 
-		if (*symName == '.') {
+		if (symName[0] == '.') {
 			if (!symbolScope)
 				fatalerror("Local label reference '%s' in main scope",
 					   symName);
+			scope = symbolScope->scope ? symbolScope->scope
+						   : symbolScope;
 			fullSymbolName(fullname, sizeof(fullname), symName,
 				       symbolScope);
 			symName = fullname;
@@ -488,6 +491,7 @@
 
 		nsym = createsymbol(symName);
 		nsym->type = SYM_REF;
+		nsym->scope = scope;
 	}
 
 	return nsym;
--- /dev/null
+++ b/test/asm/local-purge.asm
@@ -1,0 +1,8 @@
+; At some point, the name of the local label was passed *unexpanded* to the
+; function doing the removal. Ensure that this is fixed.
+
+SECTION "Test", ROM0[0]
+Glob:
+.loc
+	PURGE .loc
+	PRINTT "{.loc}\n" ; This should fail because the label doesn't exist anymore
--- /dev/null
+++ b/test/asm/local-purge.err
@@ -1,0 +1,3 @@
+ERROR: local-purge.asm(8):
+    '.loc' not defined
+error: Assembly aborted (1 errors)!
--- /dev/null
+++ b/test/asm/local-purge.out
@@ -1,0 +1,1 @@
+$0