1
0
mirror of synced 2024-11-12 02:00:52 +01:00

Added assert function. Resolves #123

This commit is contained in:
WerWolv 2021-01-09 21:47:46 +01:00
parent c5d023822d
commit e54dbcf574
3 changed files with 16 additions and 0 deletions

View File

@ -98,6 +98,8 @@ namespace hex::lang {
BUILTIN_FUNCTION(readUnsigned);
BUILTIN_FUNCTION(readSigned);
BUILTIN_FUNCTION(assert);
#undef BUILTIN_FUNCTION
};

View File

@ -86,6 +86,16 @@ namespace hex::lang {
}, address, size);
}
BUILTIN_FUNCTION(assert) {
auto condition = asType<ASTNodeIntegerLiteral>(params[0])->getValue();
auto error = asType<ASTNodeStringLiteral>(params[1])->getString();
if (LITERAL_COMPARE(condition, condition == 0))
throwEvaluateError(hex::format("assertion failed: '%s'", error.data()), 1);
return nullptr;
}
#undef BUILTIN_FUNCTION

View File

@ -24,6 +24,10 @@ namespace hex::lang {
this->addFunction("readSigned", 2, [this](auto params) {
return this->builtin_readSigned(params);
});
this->addFunction("assert", 2, [this](auto params) {
return this->builtin_assert(params);
});
}
ASTNodeIntegerLiteral* Evaluator::evaluateScopeResolution(ASTNodeScopeResolution *node) {