mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Some miscellaneous refactoring and copy-editing
This commit is contained in:
@@ -20,7 +20,7 @@ void charmap_Push();
|
||||
void charmap_Pop();
|
||||
void charmap_CheckStack();
|
||||
void charmap_Add(std::string const &mapping, std::vector<int32_t> &&value);
|
||||
bool charmap_HasChar(std::string const &input);
|
||||
bool charmap_HasChar(std::string const &mapping);
|
||||
std::vector<int32_t> charmap_Convert(std::string const &input);
|
||||
size_t charmap_ConvertNext(std::string_view &input, std::vector<int32_t> *output);
|
||||
|
||||
|
||||
@@ -1052,7 +1052,7 @@ and
|
||||
.Ic WRAMX
|
||||
types are still considered different.
|
||||
.It
|
||||
Different constraints (alignment, bank, etc.) can be specified for each unionized section declaration, but they must all be compatible.
|
||||
Different constraints (alignment, bank, etc.) can be specified for each section fragment declaration, but they must all be compatible.
|
||||
For example, alignment must be compatible with any fixed address, all specified banks must be the same, etc.
|
||||
.It
|
||||
A section fragment may not be unionized; after all, that wouldn't make much sense.
|
||||
|
||||
@@ -163,11 +163,11 @@ void charmap_Add(std::string const &mapping, std::vector<int32_t> &&value) {
|
||||
std::swap(node.value, value);
|
||||
}
|
||||
|
||||
bool charmap_HasChar(std::string const &input) {
|
||||
bool charmap_HasChar(std::string const &mapping) {
|
||||
Charmap const &charmap = *currentCharmap;
|
||||
size_t nodeIdx = 0;
|
||||
|
||||
for (char c : input) {
|
||||
for (char c : mapping) {
|
||||
nodeIdx = charmap.nodes[nodeIdx].next[static_cast<uint8_t>(c)];
|
||||
|
||||
if (!nodeIdx) {
|
||||
|
||||
@@ -239,16 +239,16 @@ static std::unordered_map<std::string, int, CaseInsensitive, CaseInsensitive> ke
|
||||
{"BITWIDTH", T_(OP_BITWIDTH) },
|
||||
{"TZCOUNT", T_(OP_TZCOUNT) },
|
||||
|
||||
{"STRCMP", T_(OP_STRCMP) },
|
||||
{"STRIN", T_(OP_STRIN) },
|
||||
{"STRRIN", T_(OP_STRRIN) },
|
||||
{"STRSUB", T_(OP_STRSUB) },
|
||||
{"STRLEN", T_(OP_STRLEN) },
|
||||
{"STRCAT", T_(OP_STRCAT) },
|
||||
{"STRUPR", T_(OP_STRUPR) },
|
||||
{"STRLWR", T_(OP_STRLWR) },
|
||||
{"STRRPL", T_(OP_STRRPL) },
|
||||
{"STRCMP", T_(OP_STRCMP) },
|
||||
{"STRFMT", T_(OP_STRFMT) },
|
||||
{"STRIN", T_(OP_STRIN) },
|
||||
{"STRLEN", T_(OP_STRLEN) },
|
||||
{"STRLWR", T_(OP_STRLWR) },
|
||||
{"STRRIN", T_(OP_STRRIN) },
|
||||
{"STRRPL", T_(OP_STRRPL) },
|
||||
{"STRSUB", T_(OP_STRSUB) },
|
||||
{"STRUPR", T_(OP_STRUPR) },
|
||||
|
||||
{"CHARLEN", T_(OP_CHARLEN) },
|
||||
{"CHARSUB", T_(OP_CHARSUB) },
|
||||
|
||||
@@ -1474,13 +1474,11 @@ relocexpr_no_str:
|
||||
$$.makeNumber($3.compare($5));
|
||||
}
|
||||
| OP_STRIN LPAREN string COMMA string RPAREN {
|
||||
auto pos = $3.find($5);
|
||||
|
||||
size_t pos = $3.find($5);
|
||||
$$.makeNumber(pos != std::string::npos ? pos + 1 : 0);
|
||||
}
|
||||
| OP_STRRIN LPAREN string COMMA string RPAREN {
|
||||
auto pos = $3.rfind($5);
|
||||
|
||||
size_t pos = $3.rfind($5);
|
||||
$$.makeNumber(pos != std::string::npos ? pos + 1 : 0);
|
||||
}
|
||||
| OP_STRLEN LPAREN string RPAREN {
|
||||
@@ -1532,19 +1530,16 @@ string:
|
||||
| OP_STRSUB LPAREN string COMMA iconst COMMA uconst RPAREN {
|
||||
size_t len = strlenUTF8($3, false);
|
||||
uint32_t pos = adjustNegativePos($5, len, "STRSUB");
|
||||
|
||||
$$ = strsubUTF8($3, pos, $7);
|
||||
}
|
||||
| OP_STRSUB LPAREN string COMMA iconst RPAREN {
|
||||
size_t len = strlenUTF8($3, false);
|
||||
uint32_t pos = adjustNegativePos($5, len, "STRSUB");
|
||||
|
||||
$$ = strsubUTF8($3, pos, pos > len ? 0 : len + 1 - pos);
|
||||
}
|
||||
| OP_CHARSUB LPAREN string COMMA iconst RPAREN {
|
||||
size_t len = charlenUTF8($3);
|
||||
uint32_t pos = adjustNegativePos($5, len, "CHARSUB");
|
||||
|
||||
$$ = charsubUTF8($3, pos);
|
||||
}
|
||||
| OP_STRCAT LPAREN RPAREN {
|
||||
@@ -2520,7 +2515,7 @@ static std::string strsubUTF8(std::string const &str, uint32_t pos, uint32_t len
|
||||
size_t index = 0;
|
||||
uint32_t state = 0;
|
||||
uint32_t codepoint = 0;
|
||||
uint32_t curPos = 1; // RGBASM strings are 1-indexed!
|
||||
uint32_t curPos = 1;
|
||||
|
||||
// Advance to starting position in source string.
|
||||
while (ptr[index] && curPos < pos) {
|
||||
@@ -2607,7 +2602,7 @@ static std::string charsubUTF8(std::string const &str, uint32_t pos) {
|
||||
}
|
||||
|
||||
static uint32_t adjustNegativePos(int32_t pos, size_t len, char const *functionName) {
|
||||
// STRSUB and CHARSUB adjust negative `pos` arguments the same way,
|
||||
// STRSUB and CHARSUB adjust negative position arguments the same way,
|
||||
// such that position -1 is the last character of a string.
|
||||
if (pos < 0) {
|
||||
pos += len + 1;
|
||||
|
||||
@@ -566,9 +566,7 @@ std::string sym_MakeAnonLabelName(uint32_t ofs, bool neg) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string anon("!");
|
||||
anon += std::to_string(id);
|
||||
return anon;
|
||||
return "!"s + std::to_string(id);
|
||||
}
|
||||
|
||||
void sym_Export(std::string const &symName) {
|
||||
|
||||
Reference in New Issue
Block a user