From 0010b92ef10258c88083a15ee5f076b96a90e7a3 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Thu, 6 Oct 2022 14:24:29 +0200 Subject: [PATCH] Load cannot be namespaced anymore due to weird namespace behaviour that this creates. I need to add a way to import but force evaluation of everything in the future to make that up. --- core_compiler.cpp | 1 + core_parsing.cpp | 5 ----- core_typechecking.cpp | 13 +++++++++++-- core_typechecking.h | 1 + examples/any_and_variadic_args.core | 1 - examples/using_multimedia.core | 2 +- modules/Base.core | 2 +- modules/Multimedia.core | 6 ++---- modules/win32_multimedia.core | 4 ++-- 9 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core_compiler.cpp b/core_compiler.cpp index ad9fbaa..9ad9a02 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -233,6 +233,7 @@ resolve_everything_in_module(Ast_Module *module){ Iter_Named(&module->all_loaded_files, file){ For(file.item[0]->decls){ resolve_name(file.item[0], it->pos, it->name); + if(it->kind == AST_STRUCT){ type_complete(it->type_val); } diff --git a/core_parsing.cpp b/core_parsing.cpp index 0d2a06b..309a829 100644 --- a/core_parsing.cpp +++ b/core_parsing.cpp @@ -821,11 +821,6 @@ parse_decl(B32 is_global){ result = parse_enum(tname); } - else if(token_match_pound(pctx->intern("load"_s))){ - Ast_File *file = parse_load(false); - result = ast_file_namespace(tname, file, tname->intern_val); - } - else if(token_match_pound(pctx->intern("import"_s))){ Ast_Module *module = parse_import(false); result = ast_module_namespace(tname, module, tname->intern_val); diff --git a/core_typechecking.cpp b/core_typechecking.cpp index 3b02d89..fe8921b 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -492,7 +492,7 @@ make_scope_search(Arena *arena, Ast_Scope *scope, Intern_String name){ result.scope_visit_id = ++pctx->scope_visit_id; result.scopes = {arena}; result.scopes.add(scope); - result.exit_on_find = true; + result.exit_on_find = false; return result; } @@ -523,6 +523,15 @@ resolve_name(Ast_Scope *scope, Token *pos, Intern_String name, Search_Flag searc compiler_error(pos, "Unidentified name [%s]", name.str); } if(search.results.len > 1){ + if(is_flag_set(search.results[0]->flags, AST_OPERATOR_OVERLOAD)){ + if(is_flag_set(search_flags, RESOLVE_NAME_MAKE_SURE_OPERATOR_OVERLOAD_IS_NOT_EVER_CALLED)){ + compiler_error(pos, "Internal compiler error: somehow we found %Q which is an operator to be also an identifier and we started resolving it using resolve_name", name); + } + For(search.results){ + resolve_decl(it); + } + return 0; + } compiler_error(pos, "Found multiple definitions of name [%s]", name.str); } @@ -1108,7 +1117,7 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str Ast_Scope *scope = field_access_scope ? field_access_scope : node->parent_scope; Search_Flag flag = field_access_scope ? SEARCH_ONLY_CURRENT_SCOPE : 0; - Ast_Decl *decl = resolve_name(scope, node->pos, node->intern_val, flag); + Ast_Decl *decl = resolve_name(scope, node->pos, node->intern_val, flag | RESOLVE_NAME_MAKE_SURE_OPERATOR_OVERLOAD_IS_NOT_EVER_CALLED); // Substitute lambda alias if(decl->kind == AST_CONST && decl->resolved_decl && decl->resolved_decl->kind == AST_LAMBDA){ diff --git a/core_typechecking.h b/core_typechecking.h index 8eb7804..293b789 100644 --- a/core_typechecking.h +++ b/core_typechecking.h @@ -37,6 +37,7 @@ enum{ typedef U32 Search_Flag; enum{ SEARCH_ONLY_CURRENT_SCOPE = bit_flag(1), + RESOLVE_NAME_MAKE_SURE_OPERATOR_OVERLOAD_IS_NOT_EVER_CALLED = bit_flag(2), }; function Operand resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context, Ast_Scope *field_access_scope); diff --git a/examples/any_and_variadic_args.core b/examples/any_and_variadic_args.core index 3e666dc..171d597 100644 --- a/examples/any_and_variadic_args.core +++ b/examples/any_and_variadic_args.core @@ -57,7 +57,6 @@ StringToDouble :: (s: String): F64 return 0 FormatString :: (buffer: *U8, buffer_len: U64, string: String, args: ..) - // @todo(krzosa): Add consideration of buffer SIZE! Add some function to handle this OutStr or something arg_counter := 0 out_buffer_len := 0 diff --git a/examples/using_multimedia.core b/examples/using_multimedia.core index 80ec3f7..0c3a152 100644 --- a/examples/using_multimedia.core +++ b/examples/using_multimedia.core @@ -8,5 +8,5 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS for y := 0, y < Mu.window.y, y+=1 for x := 0, x < Mu.window.x, x+=1 Mu.screen[x + y*Mu.window.x] = 0xFFFFFF00 - + return 0 \ No newline at end of file diff --git a/modules/Base.core b/modules/Base.core index a793969..0682ec0 100644 --- a/modules/Base.core +++ b/modules/Base.core @@ -1,5 +1,5 @@ -OS :: #import "Windows.core" #import "Arena.core" +OS :: #import "Windows.core" SizeU :: U64 ClampTopSizeU :: (val: SizeU, max: SizeU): SizeU diff --git a/modules/Multimedia.core b/modules/Multimedia.core index 4e3e487..c56f5b4 100644 --- a/modules/Multimedia.core +++ b/modules/Multimedia.core @@ -10,8 +10,6 @@ https://www.youtube.com/watch?v=NG_mUhc8LRw&list=PLU94OURih-CjrtFuazwZ5GYzTrupOM All of his channel is recommended watch for programmers. */ -StartMultimedia :: W32.StartMultimedia -UpdateMultimedia :: W32.UpdateMultimedia Mu: MU MU :: struct @@ -25,7 +23,7 @@ MU :: struct quit: Bool frame_arena: Arena - os: W32.OS + os: Platform MUWindow :: struct x: S64 @@ -61,4 +59,4 @@ Mouse :: struct #import "Base.core" #import "Math.core" #import "Arena.core" -W32 :: #load "win32_multimedia.core" +#load "win32_multimedia.core" diff --git a/modules/win32_multimedia.core b/modules/win32_multimedia.core index 1a0e14c..748f48a 100644 --- a/modules/win32_multimedia.core +++ b/modules/win32_multimedia.core @@ -4,7 +4,7 @@ #import "WINMM.core" #import "Windows.core" -OS :: struct +Platform :: struct bitmap: Bitmap window_dc: HDC window: HWND @@ -130,7 +130,7 @@ StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!" Assert(size.x == x && size.y == y) Mu.os.window_dc = GetDC(Mu.os.window) - Mu.os.bitmap = W32.CreateBitmap(Mu.os.window_dc, size) + Mu.os.bitmap = CreateBitmap(Mu.os.window_dc, size) Mu.screen = Mu.os.bitmap.data Mu.window.x = size.x