Fix BANK(@) discrepancy within LOAD blocks (#2149)

RGBASM and RGBLINK disagreed on which section to consider `@` to be in;
we have decided that the latter is correct.

The `assume` change is known to be suspicious; for more discussion, see
https://github.com/gbdev/rgbds/pull/2149#discussion_r4106902830
This commit is contained in:
Rangi authored and GitHub committed 2026-09-25 19:18:52 +02:00
1 parent dc701294f8
commit 646cb05faf
6 files changed
+35 -10

No files matched your search

-2
View File
@@ -5,7 +5,6 @@
#include <deque>
#include <memory>
#include <optional>
#include <stddef.h>
#include <stdint.h>
#include <string>
@@ -78,7 +77,6 @@ void sect_CheckLoadClosed();
Section *sect_GetSymbolSection();
uint32_t sect_GetSymbolOffset();
uint32_t sect_GetOutputOffset();
std::optional<uint32_t> sect_GetOutputBank();
Patch *sect_AddOutputPatch();
+1 -1
View File
@@ -148,7 +148,7 @@ static void initPatch(Patch &patch, uint32_t type, Expression const &expr, uint3
void out_CreatePatch(uint32_t type, Expression const &expr, uint32_t ofs, uint32_t pcShift) {
// Add the patch to the list
assume(sect_GetOutputBank().has_value());
assume(sect_GetSymbolSection() != nullptr);
Patch &patch = *sect_AddOutputPatch();
initPatch(patch, type, expr, ofs);
+3 -3
View File
@@ -83,14 +83,14 @@ void Expression::makeBankSymbol(InternedStr symName) {
assume(rpn.empty());
if (Symbol const *sym = sym_FindScopedSymbol(symName); sym_IsPC(sym)) {
// The @ symbol is treated differently.
if (std::optional<uint32_t> outputBank = sect_GetOutputBank(); !outputBank) {
if (Section *section = sect_GetSymbolSection(); !section) {
error("PC has no bank outside of a section");
data = 1;
} else if (*outputBank == UINT32_MAX) {
} else if (section->bank == UINT32_MAX) {
data = "Current section's bank is not known";
rpn.emplace_back(RPN_BANK_SELF);
} else {
data = static_cast<int32_t>(*outputBank);
data = static_cast<int32_t>(section->bank);
}
} else if (sym && !sym->isLabel()) {
error("`BANK` argument must be a label");
-4
View File
@@ -644,10 +644,6 @@ uint32_t sect_GetOutputOffset() {
return curOffset + loadOffset;
}
std::optional<uint32_t> sect_GetOutputBank() {
return currentSection ? std::optional<uint32_t>(currentSection->bank) : std::nullopt;
}
Patch *sect_AddOutputPatch() {
return currentSection ? &currentSection->patches.emplace_front() : nullptr;
}
+31
View File
@@ -0,0 +1,31 @@
SECTION "rom", ROMX, BANK[1]
xLabel:
assert @ == xLabel
static_assert BANK(@) == BANK(xLabel)
static_assert SECTION(@) === SECTION(xLabel)
ds $3000, $42
LOAD "ram", WRAMX, BANK[2]
wLabel::
assert @ == wLabel
static_assert BANK(@) == BANK(wLabel)
static_assert SECTION(@) === SECTION(wLabel)
ds $1000, $42
ENDL
SECTION "floating rom", ROMX
xLabel2:
assert @ == xLabel2
assert BANK(@) == BANK(xLabel2)
static_assert SECTION(@) === SECTION(xLabel2)
ds $3000, $42
LOAD "floating ram", WRAMX
wLabel2::
assert @ == wLabel2
assert BANK(@) == BANK(wLabel2)
static_assert SECTION(@) === SECTION(wLabel2)
ds $1000, $42
ENDL
Binary file not shown.