From fb3800a43ab43e0171fcf981505e4fa078fefb5f Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Thu, 20 Apr 2023 22:29:31 +0200 Subject: [PATCH] Core: Change lookup rules, 2x speedup --- build.bat | 2 +- build/examples/any_and_variadic_args.core | 24 +++++++++--------- build/rtsgame/main.core | 9 ++++--- core_compiler.cpp | 5 +++- core_typechecking.cpp | 31 ++++++++++++++--------- 5 files changed, 42 insertions(+), 29 deletions(-) diff --git a/build.bat b/build.bat index 690841b..8e18089 100644 --- a/build.bat +++ b/build.bat @@ -1,7 +1,7 @@ @echo off call "..\misc\compile_setup.bat" -rem bld --dont_compile_core +bld --dont_compile_core cd build core_main.exe rtsgame/main.core bld --dont_compile_core --link=vendor/raylib/windows/raylibdll.lib diff --git a/build/examples/any_and_variadic_args.core b/build/examples/any_and_variadic_args.core index c4ed756..77070ba 100644 --- a/build/examples/any_and_variadic_args.core +++ b/build/examples/any_and_variadic_args.core @@ -4,16 +4,16 @@ VariadicArguments :: (string: *char, args: []Any): Any AnyArguments :: (values: []Any) for values - Assert(it.type == S64) - Assert(*(values[0].data->*S64) == 10) - Assert(*(values[1].data->*S64) == 20) + Assert(it.type == int) + Assert(*(values[0].data->*int) == 10) + Assert(*(values[1].data->*int) == 20) /** * C++ version 0.4 char* style "itoa": * Written by Lukás Chmela * Released under GPLv3. */ -IntegerToString :: (value: S64, result: *U8, base: S64): *U8 +IntegerToString :: (value: int, result: *U8, base: int): *U8 // check that the base if valid if (base < 2) || (base > 36) *result = 0 // ' @@ -22,7 +22,7 @@ IntegerToString :: (value: S64, result: *U8, base: S64): *U8 ptr := result ptr1 := result tmp_char: U8 - tmp_value: S64 + tmp_value: int for value != 0 tmp_value = value @@ -63,8 +63,8 @@ FormatString :: (buffer: *U8, buffer_len: U64, string: String, args: []Any) Assert(arg_counter < Len(args), "Passed too many [%] to the string formating function") arg := args[arg_counter++] - if arg.type == S64 - value := *(arg.data->*S64) + if arg.type == int + value := *(arg.data->*int) itoa_buff: [64]U8 p := IntegerToString(value, &itoa_buff[0], 10) @@ -81,15 +81,15 @@ main :: (): int values := []Any{a, b} for values - Assert(it.type == S64) + Assert(it.type == int) AnyArguments({a,b}) c := VariadicArguments("Test", args = {a+b,b}) - Assert(*(c.data->*S64) == 30) + Assert(*(c.data->*int) == 30) d := VariadicArguments("Test", {b,a}) - Assert(*(d.data->*S64) == b) + Assert(*(d.data->*int) == b) - Assert(*(values[0].data->*S64) == 10) - Assert(*(values[1].data->*S64) == 20) + Assert(*(values[0].data->*int) == 10) + Assert(*(values[1].data->*int) == 20) buf: [128]U8 FormatString(&buf[0], Len(buf), "Test % %", {32, 156}) diff --git a/build/rtsgame/main.core b/build/rtsgame/main.core index 257c086..61d9b90 100644 --- a/build/rtsgame/main.core +++ b/build/rtsgame/main.core @@ -1,5 +1,5 @@ -/*@feature_idea: labeled block +/*@language_todo: labeled block It acts just like a scope in C. BUT it can be turned into a goto label by adding another semicolon @@ -18,9 +18,11 @@ thing := 1 thing2 := thing :goto_block: for -*/ -/* +@language_todo: Bring back named loads +A :: #load "array.core" + + @reproduction: This kills the compiler due to referencing slice data @@ -131,6 +133,7 @@ main :: (): int target_color.a = 255/2 for !WindowShouldClose() + WinX = GetScreenWidth() WinY = GetScreenHeight() MouseX = GetMouseX() diff --git a/core_compiler.cpp b/core_compiler.cpp index 75a7973..7b7f2d0 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -420,7 +420,10 @@ GetTypeInfo :: (type: Type): *Type_Info } { - Ast_Scope *scope = ast_decl_scope(&pctx->null_token, pctx->perm, get(&module->all_loaded_files, 0)); + Ast_File *file = get(&module->all_loaded_files, 0); + Ast_Scope *scope = ast_decl_scope(&pctx->null_token, pctx->perm, file); + scope->parent_scope = file; + scope->module = module; Ast_Decl *decl = ast_namespace(&pctx->null_token, scope, pctx->intern("Const"_s)); decl->state = DECL_RESOLVED; diff --git a/core_typechecking.cpp b/core_typechecking.cpp index 35143d5..40b3520 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -539,24 +539,31 @@ resolve_name(Ast_Scope *scope, Token *pos, Intern_String name, Search_Flag searc Scoped_Arena scratch(pctx->scratch); Scope_Search search = make_scope_search(scratch.arena, scope, name); search.search_only_current_scope = search_flags & SEARCH_ONLY_CURRENT_SCOPE; + search.exit_on_find = true; // @test(asd): not sure if this change will be ok, 2x typecheck speedup though scope_search(&search); if (search.results.len == 0) { 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); + + if (is_flag_set(search.results[0]->flags, AST_OPERATOR_OVERLOAD)) { + compiler_error(pos, "Internal compiler error: resolve_name got an overload"); } + // @test(asd): not sure if this change will be ok + // 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); + // } + Ast_Decl *decl = *search.results.data; resolve_decl(decl); return decl; @@ -605,7 +612,7 @@ insert_into_scope(Ast_Scope *scope, Ast_Decl *decl) { // as such we probably don't want to call any resolve stuff here Scoped_Arena scratch(pctx->scratch); Scope_Search search = make_scope_search(scratch.arena, scope, decl->name); - search.search_only_current_scope = true; + // search.search_only_current_scope = true; scope_search(&search); if (search.results.len != 0) { if (!is_flag_set(decl->flags, AST_OPERATOR_OVERLOAD)) {