Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase test coverage #1661

Merged
merged 1 commit into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions include/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
#include "gfx/main.hpp"

class File {
// Construct a `std::streambuf *` by default, since it's probably lighter than a `filebuf`.
Either<std::streambuf *, std::filebuf> _file;

public:
File() {}
~File() { close(); }
File() : _file(nullptr) {}

// This should only be called once, and before doing any `->` operations.
// Returns `nullptr` on error, and a non-null pointer otherwise.
Expand Down Expand Up @@ -61,20 +59,6 @@ class File {
return const_cast<File *>(this)->operator->();
}

File *close() {
if (_file.holds<std::filebuf>()) {
// This is called by the destructor, and an explicit `close` shouldn't close twice.
std::filebuf fileBuf = std::move(_file.get<std::filebuf>());
_file.emplace<std::streambuf *>(nullptr);
if (fileBuf.close() != nullptr) {
return this;
}
} else if (_file.get<std::streambuf *>() != nullptr) {
return this;
}
return nullptr;
}

char const *c_str(std::string const &path) const {
return _file.holds<std::filebuf>() ? path.c_str()
: _file.get<std::streambuf *>() == std::cin.rdbuf() ? "<stdin>"
Expand Down
6 changes: 4 additions & 2 deletions src/asm/rpn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ void Expression::makeUnaryOp(RPNCommand op, Expression &&src) {
case RPN_BIT_INDEX:
case RPN_CONST:
case RPN_SYM:
fatalerror("%d is not an unary operator\n", op);
// `makeUnaryOp` should never be called with a non-unary operator!
unreachable_();
}
} else if (op == RPN_LOGNOT && tryConstLogNot(src)) {
data = 0;
Expand Down Expand Up @@ -522,7 +523,8 @@ void Expression::makeBinaryOp(RPNCommand op, Expression &&src1, Expression const
case RPN_TZCOUNT:
case RPN_CONST:
case RPN_SYM:
fatalerror("%d is not a binary operator\n", op);
// `makeBinaryOp` should never be called with a non-binary operator!
unreachable_();
}
} else if (op == RPN_SUB && src1.isDiffConstant(src2.symbolOf())) {
data = src1.symbolOf()->getValue() - src2.symbolOf()->getValue();
Expand Down
3 changes: 3 additions & 0 deletions test/asm/const-and.asm
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ SECTION "Unaligned", ROM0

println @ & 0
println @ & 1 ; Nope

Floating:
println Floating & Aligned ; Neither defined
4 changes: 3 additions & 1 deletion test/asm/const-and.err
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ error: const-and.asm(11):
Expected constant expression: 'Aligned' is not constant at assembly time
error: const-and.asm(17):
Expected constant expression: PC is not constant at assembly time
error: Assembly aborted (3 errors)!
error: const-and.asm(20):
Expected constant expression: 'Floating' is not constant at assembly time
error: Assembly aborted (4 errors)!
1 change: 1 addition & 0 deletions test/asm/const-and.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ $0
$A
$0
$0
$0
Loading