Add static and runtime assert
This commit is contained in:
22
ast.cpp
22
ast.cpp
@@ -20,6 +20,8 @@ enum Ast_Kind: U32{
|
||||
AST_CALL_ITEM,
|
||||
AST_CALL,
|
||||
|
||||
AST_CONSTANT_ASSERT,
|
||||
AST_RUNTIME_ASSERT,
|
||||
AST_SIZE_OF,
|
||||
AST_LENGTH_OF,
|
||||
AST_ALIGN_OF,
|
||||
@@ -119,7 +121,8 @@ struct Ast_Binary: Ast_Expr{
|
||||
|
||||
struct Ast_Builtin: Ast_Expr{
|
||||
Ast_Expr *expr;
|
||||
U64 padding[3]; // For folding constants into atoms
|
||||
Intern_String assert_message;
|
||||
U64 padding[1]; // For folding constants into atoms
|
||||
};
|
||||
|
||||
// Problem: We are parsing out of order, in the middle of parsing a function
|
||||
@@ -197,7 +200,6 @@ struct Ast_Scope: Ast{
|
||||
Ast_Module *module;
|
||||
};
|
||||
|
||||
|
||||
struct Ast_Module: Ast_Scope{
|
||||
Array<Ast_File *> all_loaded_files;
|
||||
};
|
||||
@@ -507,6 +509,22 @@ ast_module(Intern_String filename){
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Builtin *
|
||||
ast_runtime_assert(Token *pos, Ast_Expr *expr, Intern_String message){
|
||||
AST_NEW(Builtin, RUNTIME_ASSERT, pos, AST_EXPR);
|
||||
result->expr = expr;
|
||||
result->assert_message = message;
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Builtin *
|
||||
ast_constant_assert(Token *pos, Ast_Expr *expr, Intern_String message){
|
||||
AST_NEW(Builtin, CONSTANT_ASSERT, pos, AST_EXPR);
|
||||
result->expr = expr;
|
||||
result->assert_message = message;
|
||||
return result;
|
||||
}
|
||||
|
||||
function Ast_Builtin *
|
||||
ast_sizeof(Token *pos, Ast_Expr *expr){
|
||||
AST_NEW(Builtin, SIZE_OF, pos, AST_EXPR);
|
||||
|
||||
Reference in New Issue
Block a user