Load is file relative not module relative

This commit is contained in:
Krzosa Karol
2022-10-09 15:20:53 +02:00
parent 54426fdd69
commit 9ad2da03c8
8 changed files with 16 additions and 21 deletions

View File

@@ -258,6 +258,7 @@ struct Ast_Module: Ast_Scope{
}; };
struct Ast_File: Ast_Scope{ struct Ast_File: Ast_Scope{
String absolute_base_folder;
String absolute_file_path; String absolute_file_path;
String filecontent; String filecontent;
}; };

View File

@@ -273,14 +273,13 @@ compile_file_to_string(String filename){
parse_all_modules(); parse_all_modules();
resolve_everything_in_module(module); resolve_everything_in_module(module);
// @note: language stuff needs to be declared before type_info data // @note: language stuff needs to be declared before type_info data
// so we mark where it ends // so we mark where it ends
pctx->base_language_ordered_decl_len = length(&pctx->ordered_decls); pctx->base_language_ordered_decl_len = length(&pctx->ordered_decls);
Ast_Decl *any_decl = search_for_single_decl(module, pctx->intern("Any"_s)); Ast_Decl *any_decl = search_for_single_decl(module, pctx->intern("Any"_s));
assert(any_decl->type == type_type); assert(any_decl->type == type_type);
type_any = any_decl->type_val; type_any = any_decl->type_val;
} }
@@ -289,7 +288,6 @@ compile_file_to_string(String filename){
assert(module); assert(module);
resolve_everything_in_module(module); resolve_everything_in_module(module);
arena_clear(&pctx->stage_arena); arena_clear(&pctx->stage_arena);
String result = compile_to_c_code(); String result = compile_to_c_code();
return result; return result;

View File

@@ -2,6 +2,8 @@
Current: Current:
- [ ] DANGEROUS BUG! &(int64_t){32} creates a new value, we shouldn't do this with variables!!!
- [ ] String declaration in Language.core - [ ] String declaration in Language.core
- [ ] Way to import and force evaluate #import_lazy #import ? - [ ] Way to import and force evaluate #import_lazy #import ?
@@ -26,9 +28,7 @@ In the future
- [ ] Detecting if return was called - [ ] Detecting if return was called
- [ ] Builtin data structures - [ ] Builtin data structures
- [ ] Slices
- [ ] Some way to take slice of data - [ ] Some way to take slice of data
- [ ] Tuples
- [ ] Dynamic arrays - [ ] Dynamic arrays
- [ ] Hash tables - [ ] Hash tables

View File

@@ -744,6 +744,7 @@ register_ast_file(Token *pos, String absolute_file_path, Ast_Module *module, B32
AST_NEW(File, FILE, 0, 0); AST_NEW(File, FILE, 0, 0);
file = result; file = result;
file->absolute_file_path = absolute_file_path; 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->module = module;
file->parent_scope = 0; file->parent_scope = 0;
file->file = file; // @warning: self referential! file->file = file; // @warning: self referential!
@@ -777,7 +778,7 @@ function Ast_File *
parse_load(B32 global_implicit_load){ parse_load(B32 global_implicit_load){
Token *file = token_expect(TK_StringLit); Token *file = token_expect(TK_StringLit);
Intern_String filename = preprocess_filename(file); 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); Ast_File *result = register_ast_file(file, absolute_path, pctx->currently_parsed_file->module, global_implicit_load);
return result; return result;
} }

View File

@@ -30,7 +30,8 @@ main :: (): int
a: Any = 10 a: Any = 10
b: Any = 20 b: Any = 20
c := a + b c := a + b
Assert(c.type == S64 && c == 30) // - [ ] DANGEROUS BUG! &(int64_t){32} creates a new value, we shouldn't do this with variables!!!
Assert(a+b+a==c+(5+5)) // Assert(c.type == S64 && c == 30)
// Assert(a+b+a==c+(5+5))
return 0 return 0

View File

@@ -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!") StartMultimedia(title = "Hello people!")
for UpdateMultimedia() for UpdateMultimedia()
if Mu.key[Key.Escape].down ;; Mu.quit = true if Mu.key[Key.Escape].down ;; Mu.quit = true

View File

@@ -40,7 +40,7 @@ KeyState :: struct
down: Bool down: Bool
Key :: enum Key :: enum
Nil None
Up;Down;Left;Right;Escape;Control;Backspace;Alt;Shift;Tab Up;Down;Left;Right;Escape;Control;Backspace;Alt;Shift;Tab
F1;F2;F3;F4;F5;F6;F7;F8;F9;F10 F1;F2;F3;F4;F5;F6;F7;F8;F9;F10
F11;F12;A;B;C;D;E;F;G;H F11;F12;A;B;C;D;E;F;G;H

View File

@@ -275,12 +275,6 @@ mapping = [
["K9", "'9'"], ["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") print("MapVKToKey :: (vk: U32): Key")
el = "" el = ""
@@ -348,5 +342,5 @@ MapVKToKey :: (vk: WPARAM): Key
elif vk == '7' ;; return Key.K7 elif vk == '7' ;; return Key.K7
elif vk == '8' ;; return Key.K8 elif vk == '8' ;; return Key.K8
elif vk == '9' ;; return Key.K9 elif vk == '9' ;; return Key.K9
return Key.Nil return Key.None
/*END*/ /*END*/