Added assert function. Resolves #123
This commit is contained in:
parent
c5d023822d
commit
e54dbcf574
@ -98,6 +98,8 @@ namespace hex::lang {
|
|||||||
BUILTIN_FUNCTION(readUnsigned);
|
BUILTIN_FUNCTION(readUnsigned);
|
||||||
BUILTIN_FUNCTION(readSigned);
|
BUILTIN_FUNCTION(readSigned);
|
||||||
|
|
||||||
|
BUILTIN_FUNCTION(assert);
|
||||||
|
|
||||||
#undef BUILTIN_FUNCTION
|
#undef BUILTIN_FUNCTION
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -86,6 +86,16 @@ namespace hex::lang {
|
|||||||
}, address, size);
|
}, 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
|
#undef BUILTIN_FUNCTION
|
||||||
|
|
||||||
|
@ -24,6 +24,10 @@ namespace hex::lang {
|
|||||||
this->addFunction("readSigned", 2, [this](auto params) {
|
this->addFunction("readSigned", 2, [this](auto params) {
|
||||||
return this->builtin_readSigned(params);
|
return this->builtin_readSigned(params);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this->addFunction("assert", 2, [this](auto params) {
|
||||||
|
return this->builtin_assert(params);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTNodeIntegerLiteral* Evaluator::evaluateScopeResolution(ASTNodeScopeResolution *node) {
|
ASTNodeIntegerLiteral* Evaluator::evaluateScopeResolution(ASTNodeScopeResolution *node) {
|
||||||
|
Loading…
Reference in New Issue
Block a user