Add static and runtime assert

This commit is contained in:
Krzosa Karol
2022-06-15 10:30:33 +02:00
parent e984049429
commit aab89ffada
6 changed files with 76 additions and 10 deletions

View File

@@ -224,6 +224,30 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0){
scope->stmts.add(ast_pass(token));
}
else if(token_match_keyword(keyword_assert)){
token_expect(TK_OpenParen);
Ast_Expr *expr = parse_expr();
Intern_String message = {};
if(token_match(TK_Comma)){
Token *t = token_expect(TK_StringLit);
message = t->intern_val;
}
token_expect(TK_CloseParen);
scope->stmts.add(ast_runtime_assert(token, expr, message));
}
else if(token_match_pound(keyword_assert)){
token_expect(TK_OpenParen);
Ast_Expr *expr = parse_expr();
Intern_String message = {};
if(token_match(TK_Comma)){
Token *t = token_expect(TK_StringLit);
message = t->intern_val;
}
token_expect(TK_CloseParen);
scope->stmts.add(ast_constant_assert(token, expr, message));
}
else if(token_match_keyword(keyword_for)){
Ast_Scope *for_scope = begin_stmt_scope(scratch, token_get());
Ast_Expr *init = 0;