mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
@@ -659,12 +659,18 @@ static void makeAssertStmt(Toy_Bucket** bucketHandle, Toy_Parser* parser, Toy_As
|
||||
Toy_Ast* ast = NULL; //assert's emit function is a bit different
|
||||
makeExpr(bucketHandle, parser, &ast);
|
||||
|
||||
//NOTE: if it's a compound, then it's got a second arg
|
||||
if (ast->type == TOY_AST_COMPOUND) {
|
||||
Toy_private_emitAstAssert(bucketHandle, rootHandle, ast->compound.left, ast->compound.right);
|
||||
//if assert is disabled, don't emit the assert
|
||||
if (parser->removeAssert) {
|
||||
Toy_private_emitAstPass(bucketHandle, rootHandle);
|
||||
}
|
||||
else {
|
||||
Toy_private_emitAstAssert(bucketHandle, rootHandle, ast, NULL);
|
||||
//NOTE: if it's a compound, then it's got a second arg
|
||||
if (ast->type == TOY_AST_COMPOUND) {
|
||||
Toy_private_emitAstAssert(bucketHandle, rootHandle, ast->compound.left, ast->compound.right);
|
||||
}
|
||||
else {
|
||||
Toy_private_emitAstAssert(bucketHandle, rootHandle, ast, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
consume(parser, TOY_TOKEN_OPERATOR_SEMICOLON, "Expected ';' at the end of assert statement");
|
||||
@@ -836,4 +842,10 @@ void Toy_resetParser(Toy_Parser* parser) {
|
||||
|
||||
parser->error = false;
|
||||
parser->panic = false;
|
||||
|
||||
parser->removeAssert = false;
|
||||
}
|
||||
|
||||
void Toy_configureParser(Toy_Parser* parser, bool removeAssert) {
|
||||
parser->removeAssert = removeAssert;
|
||||
}
|
||||
@@ -14,9 +14,14 @@ typedef struct Toy_Parser {
|
||||
|
||||
bool error;
|
||||
bool panic; //currently processing an error
|
||||
|
||||
//configs
|
||||
bool removeAssert;
|
||||
} Toy_Parser;
|
||||
|
||||
TOY_API void Toy_bindParser(Toy_Parser* parser, Toy_Lexer* lexer);
|
||||
TOY_API Toy_Ast* Toy_scanParser(Toy_Bucket** bucketHandle, Toy_Parser* parser);
|
||||
TOY_API void Toy_resetParser(Toy_Parser* parser);
|
||||
|
||||
//configure certain options
|
||||
TOY_API void Toy_configureParser(Toy_Parser* parser, bool removeAssert);
|
||||
|
||||
@@ -372,7 +372,7 @@ static void processAssert(Toy_VM* vm) {
|
||||
//do the check
|
||||
if (TOY_VALUE_IS_NULL(value) || Toy_checkValueIsTruthy(value) == false) {
|
||||
//on a failure, print the message
|
||||
Toy_stringifyValue(message, Toy_error);
|
||||
Toy_stringifyValue(message, Toy_assertFailure);
|
||||
}
|
||||
|
||||
//cleanup
|
||||
|
||||
Reference in New Issue
Block a user