shithub: rgbds

Download patch

ref: 16111f46ef95c45603d3929f1174cb7f8e916aee
parent: b019b0394621c130f53c0db03372ea036700270f
author: Ben Hetherington <dev@ben-h.uk>
date: Fri Aug 16 09:20:15 EDT 2019

Allow PUSHS to be used before a section

Previously, a PUSHS before a SECTION directive would cause rgbasm to crash when encountering a subsequent POPS.

This is because the subsequently-called out_setCurrentSection() expected the new section to be non-null, which wasn’t the case in this situation. This has been addressed by allowing the ‘null’ section to be set in this function, and only dereferencing it (to set nPC) if a non-null section is to be set.

In practice, this means that PUSHS/POPS can now be used to push/restore a context without a section.

--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -1,7 +1,7 @@
 /*
  * This file is part of RGBDS.
  *
- * Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
+ * Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors.
  *
  * SPDX-License-Identifier: MIT
  */
@@ -655,7 +655,7 @@
 		fatalerror("Cannot change the section within a UNION");
 
 	pCurrentSection = pSect;
-	nPC = pSect->nPC;
+	nPC = (pSect != NULL) ? pSect->nPC : 0;
 
 	pPCSymbol->nValue = nPC;
 	pPCSymbol->pSection = pCurrentSection;
--- /dev/null
+++ b/test/asm/pops-no-pushed-sections.asm
@@ -1,0 +1,1 @@
+POPS
--- /dev/null
+++ b/test/asm/pops-no-pushed-sections.out
@@ -1,0 +1,2 @@
+ERROR: pops-no-pushed-sections.asm(1):
+    No entries in the section stack
--- /dev/null
+++ b/test/asm/pops-no-pushed-sections.out.pipe
@@ -1,0 +1,2 @@
+ERROR: -(1):
+    No entries in the section stack
--- /dev/null
+++ b/test/asm/pops-restore-no-section.asm
@@ -1,0 +1,10 @@
+PUSHS
+
+SECTION "Test", ROM0
+SomeContent:
+	db 1, 2, 3, 4, 5, 6, 7, 8, 9
+
+POPS
+
+DisallowedContent:
+	db 0
--- /dev/null
+++ b/test/asm/pops-restore-no-section.out
@@ -1,0 +1,2 @@
+ERROR: pops-restore-no-section.asm(10):
+    Code generation before SECTION directive
--- /dev/null
+++ b/test/asm/pops-restore-no-section.out.pipe
@@ -1,0 +1,2 @@
+ERROR: -(10):
+    Code generation before SECTION directive
--- /dev/null
+++ b/test/asm/pushs-outside-section.asm
@@ -1,0 +1,2 @@
+PUSHS
+POPS