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.
This commit is contained in:
Ben Hetherington
2019-08-16 13:20:15 +01:00
parent b019b03946
commit 16111f46ef
10 changed files with 23 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
/* /*
* This file is part of RGBDS. * 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 * SPDX-License-Identifier: MIT
*/ */
@@ -655,7 +655,7 @@ void out_SetCurrentSection(struct Section *pSect)
fatalerror("Cannot change the section within a UNION"); fatalerror("Cannot change the section within a UNION");
pCurrentSection = pSect; pCurrentSection = pSect;
nPC = pSect->nPC; nPC = (pSect != NULL) ? pSect->nPC : 0;
pPCSymbol->nValue = nPC; pPCSymbol->nValue = nPC;
pPCSymbol->pSection = pCurrentSection; pPCSymbol->pSection = pCurrentSection;

View File

@@ -0,0 +1 @@
POPS

View File

@@ -0,0 +1,2 @@
ERROR: pops-no-pushed-sections.asm(1):
No entries in the section stack

View File

@@ -0,0 +1,2 @@
ERROR: -(1):
No entries in the section stack

View File

@@ -0,0 +1,10 @@
PUSHS
SECTION "Test", ROM0
SomeContent:
db 1, 2, 3, 4, 5, 6, 7, 8, 9
POPS
DisallowedContent:
db 0

View File

@@ -0,0 +1,2 @@
ERROR: pops-restore-no-section.asm(10):
Code generation before SECTION directive

View File

@@ -0,0 +1,2 @@
ERROR: -(10):
Code generation before SECTION directive

View File

@@ -0,0 +1,2 @@
PUSHS
POPS

View File

View File