summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib94/warrior.cpp36
1 files changed, 32 insertions, 4 deletions
diff --git a/lib94/warrior.cpp b/lib94/warrior.cpp
index adcf34e..48a5b57 100644
--- a/lib94/warrior.cpp
+++ b/lib94/warrior.cpp
@@ -345,7 +345,7 @@ namespace lib94 {
};
struct info_from_preprocessor {
- std::vector<std::unique_ptr<assert_expr>> assertions;
+ std::vector<assertion> assertions;
std::optional<std::string> name;
std::optional<std::string> author;
};
@@ -374,10 +374,10 @@ namespace lib94 {
line = line.substr(0, semicolon);
if (comment.starts_with("assert ")) {
- std::unique_ptr<assert_expr> assertion;
+ std::unique_ptr<assert_expr> expr;
try {
- assertion = std::move(to_assert_expr(comment.substr(7)));
+ expr = std::move(to_assert_expr(comment.substr(7)));
}
catch (const assert_expr_exception &iex) {
compiler_exception ex;
@@ -385,7 +385,11 @@ namespace lib94 {
ex.message = iex.message;
}
- info.assertions.push_back(std::move(assertion));
+ info.assertions.push_back((assertion){
+ .source_line = line_number,
+ .expr = std::move(expr),
+ .offset = (number_t)into.size()
+ });
}
else if (comment.starts_with("name ")) {
@@ -825,6 +829,30 @@ namespace lib94 {
}
}
+ for (const assertion &a : info.assertions) {
+
+ bool success;
+
+ try {
+ success = a.expr->is_true(a.offset, inline_macros, labels);
+ }
+
+ catch (const number_expr_exception &iex) {
+ compiler_exception ex;
+ ex.line_number = a.source_line;
+ ex.message = iex.message;
+ throw ex;
+ }
+
+ if (!success) {
+ compiler_exception ex;
+ ex.line_number = a.source_line;
+ ex.message = "failed assertion";
+ throw ex;
+ }
+
+ }
+
return new warrior {
.name = info.name.value(),
.author = info.author.value(),