From 108ec6121e6bd8bf300885f848c3e1196b04a0f6 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Fri, 21 Apr 2023 15:34:59 +0200 Subject: [PATCH] Core: #compiler_breakpoint --- core_ast.cpp | 4 ++-- core_codegen_c_language.cpp | 2 +- core_compiler.cpp | 1 + core_compiler.h | 1 + core_compiler_interface.hpp | 5 +++-- core_parsing.cpp | 20 ++++++++++++-------- core_polymorph.cpp | 2 +- core_typechecking.cpp | 5 ++++- core_types.cpp | 1 + meta.py | 1 + 10 files changed, 27 insertions(+), 15 deletions(-) diff --git a/core_ast.cpp b/core_ast.cpp index 9afe036..c8a141b 100644 --- a/core_ast.cpp +++ b/core_ast.cpp @@ -160,7 +160,7 @@ ast_break(Token *pos) { CORE_Static Ast_Break * ast_compiler_breakpoint(Token *pos) { - AST_NEW(Break, COMPILER_BREAKPOINT, pos, AST_STMT); + AST_NEW(Break, COMPILER_BREAKPOINT_STMT, pos, AST_STMT); return result; } @@ -566,7 +566,7 @@ void next(Ast_Iter *iter) { case AST_BREAK: case AST_PASS: case AST_CONTINUE: - case AST_COMPILER_BREAKPOINT: { + case AST_COMPILER_BREAKPOINT_STMT: { Ast *node = (Ast *)ast; } break; diff --git a/core_codegen_c_language.cpp b/core_codegen_c_language.cpp index f0ef90d..0df825d 100644 --- a/core_codegen_c_language.cpp +++ b/core_codegen_c_language.cpp @@ -667,7 +667,7 @@ gen_ast(Ast *ast) { BREAK(); } - CASE(COMPILER_BREAKPOINT, Break) { + CASE(COMPILER_BREAKPOINT_STMT, Break) { unused(node); __debugbreak(); BREAK(); diff --git a/core_compiler.cpp b/core_compiler.cpp index c816049..6c9dbab 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -81,6 +81,7 @@ for i in meta.token_simple_expr: pctx->intern_load = pctx->intern("load"_s); pctx->intern_import = pctx->intern("import"_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[1] = {pctx->intern("/"_s), "DIV"_s, TK_Div, 1, 0}; pctx->op_info_table[2] = {pctx->intern("%"_s), "MOD"_s, TK_Mod, 1, 0}; diff --git a/core_compiler.h b/core_compiler.h index 39d23fc..44bf617 100644 --- a/core_compiler.h +++ b/core_compiler.h @@ -120,6 +120,7 @@ for i in meta.interns: print(f'Intern_String intern_{i.lower()};') Intern_String intern_load; Intern_String intern_import; Intern_String intern_link; + Intern_String intern_compiler_breakpoint; /*END*/ /*#import meta diff --git a/core_compiler_interface.hpp b/core_compiler_interface.hpp index 8aacfa9..b1cbdd9 100644 --- a/core_compiler_interface.hpp +++ b/core_compiler_interface.hpp @@ -339,7 +339,7 @@ enum Ast_Kind : uint32_t { AST_SWITCH_CASE, AST_VAR_UNPACK, AST_BREAK, - AST_COMPILER_BREAKPOINT, + AST_COMPILER_BREAKPOINT_STMT, AST_CONTINUE, AST_COMPOUND, AST_TYPE, @@ -380,7 +380,8 @@ enum { AST_PARENT_POLYMORPH = 1 << 17, AST_POLYMORPH_INSTANCE = 1 << 18, - AST_TYPESPEC = 1 << 18, + AST_TYPESPEC = 1 << 19, + AST_COMPILER_BREAKPOINT = 1 << 20, }; struct Ast { diff --git a/core_parsing.cpp b/core_parsing.cpp index 23fbc41..2f584c6 100644 --- a/core_parsing.cpp +++ b/core_parsing.cpp @@ -904,12 +904,11 @@ parse_decl(B32 is_global) { Ast_Flag flags = 0; Token *tname = token_get(); if (token_match(TK_Identifier, TK_DoubleColon)) { - - if (token_match_pound(pctx->intern_foreign)) { - set_flag(flags, AST_FOREIGN); - } - else if (token_match_pound(pctx->intern_strict)) { - set_flag(flags, AST_STRICT); + for (;;) { + if (token_match_pound(pctx->intern_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 break; } if (token_match_keyword(pctx->keyword_struct)) { @@ -973,6 +972,7 @@ parse_decl(B32 is_global) { } } 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 // implementing actual parse_lambda or something. @@ -1013,13 +1013,17 @@ parse_decl(B32 is_global) { set_flag_typespec(typespec); Ast_Expr *expr = parse_assign_expr(); - if (token_match_pound(pctx->intern_foreign)) - set_flag(flags, AST_FOREIGN); + for (;;) { + 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); } 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(); result = ast_var(tname, 0, tname->intern_val, expr); } diff --git a/core_polymorph.cpp b/core_polymorph.cpp index 5041d2a..fbb236b 100644 --- a/core_polymorph.cpp +++ b/core_polymorph.cpp @@ -326,7 +326,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope, Array *repl) case AST_BREAK: case AST_PASS: case AST_CONTINUE: - case AST_COMPILER_BREAKPOINT: { + case AST_COMPILER_BREAKPOINT_STMT: { Ast *src = (Ast *)ast; Ast *dst = ast_create_copy(parent_scope, Ast, ast); result = dst; diff --git a/core_typechecking.cpp b/core_typechecking.cpp index ee78c1a..623977a 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -729,6 +729,7 @@ CORE_Static void resolve_stmt(Ast *ast, Ast_Type *ret) { if (!ast) return; assert(ast->parent_scope->kind == AST_SCOPE); + if (ast->flags & AST_COMPILER_BREAKPOINT) Breakpoint; switch (ast->kind) { 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(); } - case AST_COMPILER_BREAKPOINT: { + case AST_COMPILER_BREAKPOINT_STMT: { __debugbreak(); } 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 {}; assert(is_flag_set(ast->flags, AST_EXPR)); assert(ast->parent_scope->kind == AST_SCOPE || ast->parent_scope->kind == AST_FILE); + if (ast->flags & AST_COMPILER_BREAKPOINT) Breakpoint; switch (ast->kind) { @@ -1849,6 +1851,7 @@ resolve_decl(Ast_Decl *ast) { ast->state = DECL_RESOLVING; Ast_Decl *node = (Ast_Decl *)ast; node->unique_name = node->name; + if (ast->flags & AST_COMPILER_BREAKPOINT) Breakpoint; { switch (ast->kind) { case AST_LAMBDA: { diff --git a/core_types.cpp b/core_types.cpp index 10e8379..e478eef 100644 --- a/core_types.cpp +++ b/core_types.cpp @@ -243,6 +243,7 @@ CORE_Static void type_complete(Ast_Type *type); CORE_Static void type_struct_complete(Ast_Type *type, Ast_Decl *node) { assert(node->kind == AST_STRUCT || node->kind == AST_UNION); + if (is_flag_set(node->flags, AST_COMPILER_BREAKPOINT)) Breakpoint; Scoped_Arena scratch(pctx->scratch); if (node->kind == AST_STRUCT) { diff --git a/meta.py b/meta.py index 15bbf58..b9de3f0 100644 --- a/meta.py +++ b/meta.py @@ -131,6 +131,7 @@ interns = [ "load", "import", "link", + "compiler_breakpoint", ]