From 48412e9c568820b152ccf6af0602b88ac604cb86 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Mon, 10 Feb 2025 16:51:51 +0100 Subject: [PATCH] Some miscellaneous refactoring and copy-editing --- include/asm/charmap.hpp | 2 +- man/rgbasm.5 | 2 +- src/asm/charmap.cpp | 4 ++-- src/asm/lexer.cpp | 10 +++++----- src/asm/parser.y | 13 ++++--------- src/asm/symbol.cpp | 4 +--- 6 files changed, 14 insertions(+), 21 deletions(-) diff --git a/include/asm/charmap.hpp b/include/asm/charmap.hpp index 8c0415cff..f861903f8 100644 --- a/include/asm/charmap.hpp +++ b/include/asm/charmap.hpp @@ -20,7 +20,7 @@ void charmap_Push(); void charmap_Pop(); void charmap_CheckStack(); void charmap_Add(std::string const &mapping, std::vector &&value); -bool charmap_HasChar(std::string const &input); +bool charmap_HasChar(std::string const &mapping); std::vector charmap_Convert(std::string const &input); size_t charmap_ConvertNext(std::string_view &input, std::vector *output); diff --git a/man/rgbasm.5 b/man/rgbasm.5 index e8b7e291e..ed5509174 100644 --- a/man/rgbasm.5 +++ b/man/rgbasm.5 @@ -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. diff --git a/src/asm/charmap.cpp b/src/asm/charmap.cpp index 3b7583023..53aabb8f1 100644 --- a/src/asm/charmap.cpp +++ b/src/asm/charmap.cpp @@ -163,11 +163,11 @@ void charmap_Add(std::string const &mapping, std::vector &&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(c)]; if (!nodeIdx) { diff --git a/src/asm/lexer.cpp b/src/asm/lexer.cpp index 2cfa72986..2f3e66a4b 100644 --- a/src/asm/lexer.cpp +++ b/src/asm/lexer.cpp @@ -239,16 +239,16 @@ static std::unordered_map 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) }, diff --git a/src/asm/parser.y b/src/asm/parser.y index 746f6279d..789701a5d 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -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; diff --git a/src/asm/symbol.cpp b/src/asm/symbol.cpp index 0d81f3312..47b022db6 100644 --- a/src/asm/symbol.cpp +++ b/src/asm/symbol.cpp @@ -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) {