Skip to content

Commit

Permalink
Some miscellaneous refactoring and copy-editing
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 committed Feb 10, 2025
1 parent 177a3ab commit 48412e9
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion include/asm/charmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion man/rgbasm.5
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/asm/charmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/asm/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,16 @@ static std::unordered_map<std::string, int, CaseInsensitive, CaseInsensitive> ke
{"BITWIDTH", T_(OP_BITWIDTH) },
{"TZCOUNT", T_(OP_TZCOUNT) },

{"STRCAT", T_(OP_STRCAT) },
{"STRCMP", T_(OP_STRCMP) },
{"STRFMT", T_(OP_STRFMT) },
{"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) },
{"STRRIN", T_(OP_STRRIN) },
{"STRRPL", T_(OP_STRRPL) },
{"STRFMT", T_(OP_STRFMT) },
{"STRSUB", T_(OP_STRSUB) },
{"STRUPR", T_(OP_STRUPR) },

{"CHARLEN", T_(OP_CHARLEN) },
{"CHARSUB", T_(OP_CHARSUB) },
Expand Down
13 changes: 4 additions & 9 deletions src/asm/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/asm/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 48412e9

Please sign in to comment.