mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Improve RGBASM test coverage
This commit is contained in:
@@ -624,7 +624,7 @@ static uint32_t readBracketedMacroArgNum() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (c >= '0' && c <= '9') {
|
if (c >= '0' && c <= '9') {
|
||||||
uint32_t n = readDecimalNumber(0);
|
uint32_t n = readDecimalNumber(bumpChar());
|
||||||
if (n > INT32_MAX) {
|
if (n > INT32_MAX) {
|
||||||
error("Number in bracketed macro argument is too large");
|
error("Number in bracketed macro argument is too large");
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1165,11 +1165,11 @@ static uint32_t readOctalNumber() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t readDecimalNumber(int initial) {
|
static uint32_t readDecimalNumber(int initial) {
|
||||||
uint32_t value = initial ? initial - '0' : 0;
|
assume(initial >= '0' && initial <= '9');
|
||||||
bool empty = !initial;
|
uint32_t value = initial - '0';
|
||||||
|
|
||||||
for (int c = peek();; c = nextChar()) {
|
for (int c = peek();; c = nextChar()) {
|
||||||
if (c == '_' && !empty) {
|
if (c == '_') {
|
||||||
continue;
|
continue;
|
||||||
} else if (c >= '0' && c <= '9') {
|
} else if (c >= '0' && c <= '9') {
|
||||||
c = c - '0';
|
c = c - '0';
|
||||||
@@ -1181,12 +1181,6 @@ static uint32_t readDecimalNumber(int initial) {
|
|||||||
warning(WARNING_LARGE_CONSTANT, "Integer constant is too large");
|
warning(WARNING_LARGE_CONSTANT, "Integer constant is too large");
|
||||||
}
|
}
|
||||||
value = value * 10 + c;
|
value = value * 10 + c;
|
||||||
|
|
||||||
empty = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty) {
|
|
||||||
error("Invalid integer constant, no digits");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
@@ -1393,9 +1387,9 @@ static void appendExpandedString(std::string &str, std::string const &expanded)
|
|||||||
case '\n':
|
case '\n':
|
||||||
str += "\\n";
|
str += "\\n";
|
||||||
break;
|
break;
|
||||||
|
// LCOV_EXCL_START
|
||||||
case '\r':
|
case '\r':
|
||||||
// A literal CR in a string may get treated as a LF, so '\r' is not tested.
|
// A literal CR in a string may get treated as a LF, so '\r' is not tested.
|
||||||
// LCOV_EXCL_START
|
|
||||||
str += "\\r";
|
str += "\\r";
|
||||||
break;
|
break;
|
||||||
// LCOV_EXCL_STOP
|
// LCOV_EXCL_STOP
|
||||||
@@ -1637,16 +1631,9 @@ static bool isGarbageCharacter(int c) {
|
|||||||
&& (c == '\0' || !strchr("; \t~[](),+-*/|^=!<>:&%`\"\r\n\\", c));
|
&& (c == '\0' || !strchr("; \t~[](),+-*/|^=!<>:&%`\"\r\n\\", c));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void skipGarbageCharacters(int c) {
|
static void reportGarbageCharacters(int c) {
|
||||||
// '#' can be garbage if it doesn't start a raw string or identifier
|
// '#' can be garbage if it doesn't start a raw string or identifier
|
||||||
assume(isGarbageCharacter(c) || c == '#');
|
assume(isGarbageCharacter(c) || c == '#');
|
||||||
|
|
||||||
// Do not report weird characters when capturing, it'll be done later
|
|
||||||
if (lexerState->capturing) {
|
|
||||||
skipChars(isGarbageCharacter);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isGarbageCharacter(peek())) {
|
if (isGarbageCharacter(peek())) {
|
||||||
// At least two characters are garbage; group them into one error report
|
// At least two characters are garbage; group them into one error report
|
||||||
std::string garbage = printChar(c);
|
std::string garbage = printChar(c);
|
||||||
@@ -1966,7 +1953,7 @@ static Token yylex_NORMAL() {
|
|||||||
if (raw && startsIdentifier(peek())) {
|
if (raw && startsIdentifier(peek())) {
|
||||||
c = bumpChar();
|
c = bumpChar();
|
||||||
} else if (!startsIdentifier(c)) {
|
} else if (!startsIdentifier(c)) {
|
||||||
skipGarbageCharacters(c);
|
reportGarbageCharacters(c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "helpers.hpp" // assume
|
||||||
|
|
||||||
#include "asm/fixpoint.hpp"
|
#include "asm/fixpoint.hpp"
|
||||||
#include "asm/fstack.hpp"
|
#include "asm/fstack.hpp"
|
||||||
#include "asm/lexer.hpp"
|
#include "asm/lexer.hpp"
|
||||||
@@ -77,9 +79,9 @@ void opt_Parse(char const *s) {
|
|||||||
result = sscanf(&s[1], "%x", &padByte);
|
result = sscanf(&s[1], "%x", &padByte);
|
||||||
if (result != 1) {
|
if (result != 1) {
|
||||||
error("Invalid argument for option 'p'");
|
error("Invalid argument for option 'p'");
|
||||||
} else if (padByte > 0xFF) {
|
|
||||||
error("Argument for option 'p' must be between 0 and 0xFF");
|
|
||||||
} else {
|
} else {
|
||||||
|
// Two characters cannot be scanned as a hex number greater than 0xFF
|
||||||
|
assume(padByte <= 0xFF);
|
||||||
opt_P(padByte);
|
opt_P(padByte);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -325,9 +325,9 @@ void Expression::makeUnaryOp(RPNCommand op, Expression &&src) {
|
|||||||
case RPN_TZCOUNT:
|
case RPN_TZCOUNT:
|
||||||
data = val != 0 ? ctz(uval) : 32;
|
data = val != 0 ? ctz(uval) : 32;
|
||||||
break;
|
break;
|
||||||
|
// LCOV_EXCL_START
|
||||||
default:
|
default:
|
||||||
// `makeUnaryOp` should never be called with a non-unary operator!
|
// `makeUnaryOp` should never be called with a non-unary operator!
|
||||||
// LCOV_EXCL_START
|
|
||||||
unreachable_();
|
unreachable_();
|
||||||
}
|
}
|
||||||
// LCOV_EXCL_STOP
|
// LCOV_EXCL_STOP
|
||||||
@@ -467,9 +467,9 @@ void Expression::makeBinaryOp(RPNCommand op, Expression &&src1, Expression const
|
|||||||
|
|
||||||
data = op_exponent(lval, rval);
|
data = op_exponent(lval, rval);
|
||||||
break;
|
break;
|
||||||
|
// LCOV_EXCL_START
|
||||||
default:
|
default:
|
||||||
// `makeBinaryOp` should never be called with a non-binary operator!
|
// `makeBinaryOp` should never be called with a non-binary operator!
|
||||||
// LCOV_EXCL_START
|
|
||||||
unreachable_();
|
unreachable_();
|
||||||
}
|
}
|
||||||
// LCOV_EXCL_STOP
|
// LCOV_EXCL_STOP
|
||||||
|
|||||||
@@ -32,3 +32,4 @@ char '?', $3f ; ASCII
|
|||||||
char 'F', 0
|
char 'F', 0
|
||||||
char 'ABF', 0
|
char 'ABF', 0
|
||||||
char '\n\r\t', 0
|
char '\n\r\t', 0
|
||||||
|
assert 0 == '
|
||||||
|
|||||||
@@ -12,4 +12,8 @@ warning: character-literals.asm(34) -> character-literals.asm::char(13): [-Wunma
|
|||||||
Unmapped character '\t'
|
Unmapped character '\t'
|
||||||
error: character-literals.asm(34) -> character-literals.asm::char(13):
|
error: character-literals.asm(34) -> character-literals.asm::char(13):
|
||||||
Character literals must be a single charmap unit
|
Character literals must be a single charmap unit
|
||||||
Assembly aborted with 3 errors!
|
error: character-literals.asm(35):
|
||||||
|
Unterminated character
|
||||||
|
error: character-literals.asm(35):
|
||||||
|
Character literals must be a single charmap unit
|
||||||
|
Assembly aborted with 5 errors!
|
||||||
|
|||||||
1
test/asm/include-slash.asm
Normal file
1
test/asm/include-slash.asm
Normal file
@@ -0,0 +1 @@
|
|||||||
|
println x
|
||||||
3
test/asm/include-slash.err
Normal file
3
test/asm/include-slash.err
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
error: include-slash.asm(0):
|
||||||
|
Error reading pre-included file 'include-slash-nonexist.inc': No such file or directory
|
||||||
|
Assembly aborted with 1 error!
|
||||||
1
test/asm/include-slash.flags
Normal file
1
test/asm/include-slash.flags
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-Weverything -P include-slash.inc -I include -P include-slash-nonexist.inc
|
||||||
1
test/asm/include-slash.out
Normal file
1
test/asm/include-slash.out
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$2A
|
||||||
1
test/asm/include/include-slash.inc
Normal file
1
test/asm/include/include-slash.inc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
def x = 42
|
||||||
@@ -12,7 +12,7 @@ def variable += 1
|
|||||||
|
|
||||||
def con2 equ -1
|
def con2 equ -1
|
||||||
def var2 = variable**2
|
def var2 = variable**2
|
||||||
def str2 equs strcat("{string}", "\0\n\t\r")
|
def str2 equs strcat("{string}", "\0\n\t\r\\\"\{")
|
||||||
charmap "c2", 10, -11, 987654321
|
charmap "c2", 10, -11, 987654321
|
||||||
|
|
||||||
PURGE polo
|
PURGE polo
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ def var2 = $9
|
|||||||
|
|
||||||
; String constants
|
; String constants
|
||||||
def string equs "goodbye~"
|
def string equs "goodbye~"
|
||||||
def str2 equs "hello!\0\n\t\r"
|
def str2 equs "hello!\0\n\t\r\\\"\{"
|
||||||
|
|
||||||
; Character maps
|
; Character maps
|
||||||
newcharmap main
|
newcharmap main
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
fname=$(mktemp)
|
|
||||||
|
|
||||||
for i in *.asm; do
|
|
||||||
../../rgbasm $i >$fname 2>&1
|
|
||||||
mv -f $fname ${i%.asm}.out
|
|
||||||
done
|
|
||||||
|
|
||||||
rm -f $fname
|
|
||||||
exit 0
|
|
||||||
Reference in New Issue
Block a user