Core: #compiler_breakpoint

This commit is contained in:
Krzosa Karol
2023-04-21 15:34:59 +02:00
parent 07dcb418dd
commit 108ec6121e
10 changed files with 27 additions and 15 deletions

View File

@@ -160,7 +160,7 @@ ast_break(Token *pos) {
CORE_Static Ast_Break * CORE_Static Ast_Break *
ast_compiler_breakpoint(Token *pos) { ast_compiler_breakpoint(Token *pos) {
AST_NEW(Break, COMPILER_BREAKPOINT, pos, AST_STMT); AST_NEW(Break, COMPILER_BREAKPOINT_STMT, pos, AST_STMT);
return result; return result;
} }
@@ -566,7 +566,7 @@ void next(Ast_Iter *iter) {
case AST_BREAK: case AST_BREAK:
case AST_PASS: case AST_PASS:
case AST_CONTINUE: case AST_CONTINUE:
case AST_COMPILER_BREAKPOINT: { case AST_COMPILER_BREAKPOINT_STMT: {
Ast *node = (Ast *)ast; Ast *node = (Ast *)ast;
} break; } break;

View File

@@ -667,7 +667,7 @@ gen_ast(Ast *ast) {
BREAK(); BREAK();
} }
CASE(COMPILER_BREAKPOINT, Break) { CASE(COMPILER_BREAKPOINT_STMT, Break) {
unused(node); unused(node);
__debugbreak(); __debugbreak();
BREAK(); BREAK();

View File

@@ -81,6 +81,7 @@ for i in meta.token_simple_expr:
pctx->intern_load = pctx->intern("load"_s); pctx->intern_load = pctx->intern("load"_s);
pctx->intern_import = pctx->intern("import"_s); pctx->intern_import = pctx->intern("import"_s);
pctx->intern_link = pctx->intern("link"_s); pctx->intern_link = pctx->intern("link"_s);
pctx->intern_compiler_breakpoint = pctx->intern("compiler_breakpoint"_s);
pctx->op_info_table[0] = {pctx->intern("*"_s), "MUL"_s, TK_Mul, 1, 0}; pctx->op_info_table[0] = {pctx->intern("*"_s), "MUL"_s, TK_Mul, 1, 0};
pctx->op_info_table[1] = {pctx->intern("/"_s), "DIV"_s, TK_Div, 1, 0}; pctx->op_info_table[1] = {pctx->intern("/"_s), "DIV"_s, TK_Div, 1, 0};
pctx->op_info_table[2] = {pctx->intern("%"_s), "MOD"_s, TK_Mod, 1, 0}; pctx->op_info_table[2] = {pctx->intern("%"_s), "MOD"_s, TK_Mod, 1, 0};

View File

@@ -120,6 +120,7 @@ for i in meta.interns: print(f'Intern_String intern_{i.lower()};')
Intern_String intern_load; Intern_String intern_load;
Intern_String intern_import; Intern_String intern_import;
Intern_String intern_link; Intern_String intern_link;
Intern_String intern_compiler_breakpoint;
/*END*/ /*END*/
/*#import meta /*#import meta

View File

@@ -339,7 +339,7 @@ enum Ast_Kind : uint32_t {
AST_SWITCH_CASE, AST_SWITCH_CASE,
AST_VAR_UNPACK, AST_VAR_UNPACK,
AST_BREAK, AST_BREAK,
AST_COMPILER_BREAKPOINT, AST_COMPILER_BREAKPOINT_STMT,
AST_CONTINUE, AST_CONTINUE,
AST_COMPOUND, AST_COMPOUND,
AST_TYPE, AST_TYPE,
@@ -380,7 +380,8 @@ enum {
AST_PARENT_POLYMORPH = 1 << 17, AST_PARENT_POLYMORPH = 1 << 17,
AST_POLYMORPH_INSTANCE = 1 << 18, AST_POLYMORPH_INSTANCE = 1 << 18,
AST_TYPESPEC = 1 << 18, AST_TYPESPEC = 1 << 19,
AST_COMPILER_BREAKPOINT = 1 << 20,
}; };
struct Ast { struct Ast {

View File

@@ -904,12 +904,11 @@ parse_decl(B32 is_global) {
Ast_Flag flags = 0; Ast_Flag flags = 0;
Token *tname = token_get(); Token *tname = token_get();
if (token_match(TK_Identifier, TK_DoubleColon)) { if (token_match(TK_Identifier, TK_DoubleColon)) {
for (;;) {
if (token_match_pound(pctx->intern_foreign)) { if (token_match_pound(pctx->intern_foreign)) set_flag(flags, AST_FOREIGN);
set_flag(flags, AST_FOREIGN); else if (token_match_pound(pctx->intern_strict)) set_flag(flags, AST_STRICT);
} else if (token_match_pound(pctx->intern_compiler_breakpoint)) set_flag(flags, AST_COMPILER_BREAKPOINT);
else if (token_match_pound(pctx->intern_strict)) { else break;
set_flag(flags, AST_STRICT);
} }
if (token_match_keyword(pctx->keyword_struct)) { if (token_match_keyword(pctx->keyword_struct)) {
@@ -973,6 +972,7 @@ parse_decl(B32 is_global) {
} }
} }
else if (token_match(TK_StringLit, TK_DoubleColon)) { else if (token_match(TK_StringLit, TK_DoubleColon)) {
if (token_match_pound(pctx->intern_compiler_breakpoint)) set_flag(flags, AST_COMPILER_BREAKPOINT);
// @cleanup: consider simplifying lambdas, removing AST_LAMBDA_EXPR and // @cleanup: consider simplifying lambdas, removing AST_LAMBDA_EXPR and
// implementing actual parse_lambda or something. // implementing actual parse_lambda or something.
@@ -1013,13 +1013,17 @@ parse_decl(B32 is_global) {
set_flag_typespec(typespec); set_flag_typespec(typespec);
Ast_Expr *expr = parse_assign_expr(); Ast_Expr *expr = parse_assign_expr();
if (token_match_pound(pctx->intern_foreign)) for (;;) {
set_flag(flags, AST_FOREIGN); if (token_match_pound(pctx->intern_foreign)) set_flag(flags, AST_FOREIGN);
else if (token_match_pound(pctx->intern_compiler_breakpoint)) set_flag(flags, AST_COMPILER_BREAKPOINT);
else break;
}
result = ast_var(tname, typespec, tname->intern_val, expr); result = ast_var(tname, typespec, tname->intern_val, expr);
} }
else if (token_match(TK_Identifier, TK_ColonAssign)) { else if (token_match(TK_Identifier, TK_ColonAssign)) {
if (token_match_pound(pctx->intern_compiler_breakpoint)) set_flag(flags, AST_COMPILER_BREAKPOINT);
Ast_Expr *expr = parse_expr(); Ast_Expr *expr = parse_expr();
result = ast_var(tname, 0, tname->intern_val, expr); result = ast_var(tname, 0, tname->intern_val, expr);
} }

View File

@@ -326,7 +326,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope, Array<Poly_Replacement> *repl)
case AST_BREAK: case AST_BREAK:
case AST_PASS: case AST_PASS:
case AST_CONTINUE: case AST_CONTINUE:
case AST_COMPILER_BREAKPOINT: { case AST_COMPILER_BREAKPOINT_STMT: {
Ast *src = (Ast *)ast; Ast *src = (Ast *)ast;
Ast *dst = ast_create_copy(parent_scope, Ast, ast); Ast *dst = ast_create_copy(parent_scope, Ast, ast);
result = dst; result = dst;

View File

@@ -729,6 +729,7 @@ CORE_Static void
resolve_stmt(Ast *ast, Ast_Type *ret) { resolve_stmt(Ast *ast, Ast_Type *ret) {
if (!ast) return; if (!ast) return;
assert(ast->parent_scope->kind == AST_SCOPE); assert(ast->parent_scope->kind == AST_SCOPE);
if (ast->flags & AST_COMPILER_BREAKPOINT) Breakpoint;
switch (ast->kind) { switch (ast->kind) {
CASE(RETURN, Return) { // @todo: need to check if all paths return a value CASE(RETURN, Return) { // @todo: need to check if all paths return a value
@@ -776,7 +777,7 @@ resolve_stmt(Ast *ast, Ast_Type *ret) {
BREAK(); BREAK();
} }
case AST_COMPILER_BREAKPOINT: { case AST_COMPILER_BREAKPOINT_STMT: {
__debugbreak(); __debugbreak();
} break; } break;
@@ -1167,6 +1168,7 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str
if (!ast && is_flag_set(flags, AST_CAN_BE_NULL)) return {}; if (!ast && is_flag_set(flags, AST_CAN_BE_NULL)) return {};
assert(is_flag_set(ast->flags, AST_EXPR)); assert(is_flag_set(ast->flags, AST_EXPR));
assert(ast->parent_scope->kind == AST_SCOPE || ast->parent_scope->kind == AST_FILE); assert(ast->parent_scope->kind == AST_SCOPE || ast->parent_scope->kind == AST_FILE);
if (ast->flags & AST_COMPILER_BREAKPOINT) Breakpoint;
switch (ast->kind) { switch (ast->kind) {
@@ -1849,6 +1851,7 @@ resolve_decl(Ast_Decl *ast) {
ast->state = DECL_RESOLVING; ast->state = DECL_RESOLVING;
Ast_Decl *node = (Ast_Decl *)ast; Ast_Decl *node = (Ast_Decl *)ast;
node->unique_name = node->name; node->unique_name = node->name;
if (ast->flags & AST_COMPILER_BREAKPOINT) Breakpoint;
{ {
switch (ast->kind) { switch (ast->kind) {
case AST_LAMBDA: { case AST_LAMBDA: {

View File

@@ -243,6 +243,7 @@ CORE_Static void type_complete(Ast_Type *type);
CORE_Static void CORE_Static void
type_struct_complete(Ast_Type *type, Ast_Decl *node) { type_struct_complete(Ast_Type *type, Ast_Decl *node) {
assert(node->kind == AST_STRUCT || node->kind == AST_UNION); assert(node->kind == AST_STRUCT || node->kind == AST_UNION);
if (is_flag_set(node->flags, AST_COMPILER_BREAKPOINT)) Breakpoint;
Scoped_Arena scratch(pctx->scratch); Scoped_Arena scratch(pctx->scratch);
if (node->kind == AST_STRUCT) { if (node->kind == AST_STRUCT) {

View File

@@ -131,6 +131,7 @@ interns = [
"load", "load",
"import", "import",
"link", "link",
"compiler_breakpoint",
] ]