From 9ad2da03c864b184ae61ca866b2e62aa2e0292c9 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sun, 9 Oct 2022 15:20:53 +0200 Subject: [PATCH] Load is file relative not module relative --- core_ast.cpp | 1 + core_compiler.cpp | 4 +--- core_main.cpp | 6 +++--- core_parsing.cpp | 7 ++++--- examples/dynamic_typing.core | 5 +++-- examples/using_multimedia.core | 4 ++-- modules/Multimedia.core | 2 +- modules/win32_multimedia.core | 8 +------- 8 files changed, 16 insertions(+), 21 deletions(-) diff --git a/core_ast.cpp b/core_ast.cpp index cbded25..19e8158 100644 --- a/core_ast.cpp +++ b/core_ast.cpp @@ -258,6 +258,7 @@ struct Ast_Module: Ast_Scope{ }; struct Ast_File: Ast_Scope{ + String absolute_base_folder; String absolute_file_path; String filecontent; }; diff --git a/core_compiler.cpp b/core_compiler.cpp index 4ef6fa6..66514f6 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -273,14 +273,13 @@ compile_file_to_string(String filename){ parse_all_modules(); resolve_everything_in_module(module); + // @note: language stuff needs to be declared before type_info data // so we mark where it ends pctx->base_language_ordered_decl_len = length(&pctx->ordered_decls); Ast_Decl *any_decl = search_for_single_decl(module, pctx->intern("Any"_s)); assert(any_decl->type == type_type); type_any = any_decl->type_val; - - } @@ -289,7 +288,6 @@ compile_file_to_string(String filename){ assert(module); resolve_everything_in_module(module); - arena_clear(&pctx->stage_arena); String result = compile_to_c_code(); return result; diff --git a/core_main.cpp b/core_main.cpp index f354b93..a181683 100644 --- a/core_main.cpp +++ b/core_main.cpp @@ -2,6 +2,8 @@ Current: +- [ ] DANGEROUS BUG! &(int64_t){32} creates a new value, we shouldn't do this with variables!!! + - [ ] String declaration in Language.core - [ ] Way to import and force evaluate #import_lazy #import ? @@ -26,9 +28,7 @@ In the future - [ ] Detecting if return was called - [ ] Builtin data structures - - [ ] Slices - - [ ] Some way to take slice of data - - [ ] Tuples + - [ ] Some way to take slice of data - [ ] Dynamic arrays - [ ] Hash tables diff --git a/core_parsing.cpp b/core_parsing.cpp index 7cfc01a..e42abd4 100644 --- a/core_parsing.cpp +++ b/core_parsing.cpp @@ -742,8 +742,9 @@ register_ast_file(Token *pos, String absolute_file_path, Ast_Module *module, B32 if(!file){ log_trace("%Q :: Registering file: %Q\n", module->absolute_file_path, absolute_file_path); AST_NEW(File, FILE, 0, 0); - file = result; - file->absolute_file_path = absolute_file_path; + file = result; + file->absolute_file_path = absolute_file_path; + file->absolute_base_folder = string_copy(pctx->perm, string_chop_last_slash(file->absolute_file_path)); file->module = module; file->parent_scope = 0; file->file = file; // @warning: self referential! @@ -777,7 +778,7 @@ function Ast_File * parse_load(B32 global_implicit_load){ Token *file = token_expect(TK_StringLit); Intern_String filename = preprocess_filename(file); - String absolute_path = string_fmt(pctx->perm, "%Q/%Q", pctx->currently_parsed_file->module->absolute_base_folder, filename); + String absolute_path = string_fmt(pctx->perm, "%Q/%Q", pctx->currently_parsed_file->absolute_base_folder, filename); Ast_File *result = register_ast_file(file, absolute_path, pctx->currently_parsed_file->module, global_implicit_load); return result; } diff --git a/examples/dynamic_typing.core b/examples/dynamic_typing.core index f5557d2..8decd1f 100644 --- a/examples/dynamic_typing.core +++ b/examples/dynamic_typing.core @@ -30,7 +30,8 @@ main :: (): int a: Any = 10 b: Any = 20 c := a + b - Assert(c.type == S64 && c == 30) - Assert(a+b+a==c+(5+5)) + // - [ ] DANGEROUS BUG! &(int64_t){32} creates a new value, we shouldn't do this with variables!!! + // Assert(c.type == S64 && c == 30) + // Assert(a+b+a==c+(5+5)) return 0 \ No newline at end of file diff --git a/examples/using_multimedia.core b/examples/using_multimedia.core index 9fc7367..40fbdbb 100644 --- a/examples/using_multimedia.core +++ b/examples/using_multimedia.core @@ -1,6 +1,6 @@ -#import "Multimedia.core" +#load "Multimedia.core" -WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nShowCmd: int): int +main :: (): int StartMultimedia(title = "Hello people!") for UpdateMultimedia() if Mu.key[Key.Escape].down ;; Mu.quit = true diff --git a/modules/Multimedia.core b/modules/Multimedia.core index e0b7e53..d8c3daa 100644 --- a/modules/Multimedia.core +++ b/modules/Multimedia.core @@ -40,7 +40,7 @@ KeyState :: struct down: Bool Key :: enum - Nil + None Up;Down;Left;Right;Escape;Control;Backspace;Alt;Shift;Tab F1;F2;F3;F4;F5;F6;F7;F8;F9;F10 F11;F12;A;B;C;D;E;F;G;H diff --git a/modules/win32_multimedia.core b/modules/win32_multimedia.core index 748f48a..1b4d2e7 100644 --- a/modules/win32_multimedia.core +++ b/modules/win32_multimedia.core @@ -275,12 +275,6 @@ mapping = [ ["K9", "'9'"], ] -r = "Key :: enum\n " -for i,val in enumerate(mapping): - r += val[0] - if (i+1) % 10 == 0: r += "\n " - elif i != len(mapping)-1: r += ";" -print(r) print("MapVKToKey :: (vk: U32): Key") el = "" @@ -348,5 +342,5 @@ MapVKToKey :: (vk: WPARAM): Key elif vk == '7' ;; return Key.K7 elif vk == '8' ;; return Key.K8 elif vk == '9' ;; return Key.K9 - return Key.Nil + return Key.None /*END*/ \ No newline at end of file