diff --git a/README.md b/README.md index d35e6db..75bb880 100644 --- a/README.md +++ b/README.md @@ -76,9 +76,7 @@ Dot :: (a: Vec3, b: Vec3): F32 ;; return a.x*b.x + a.y*b.y + a.z*b.z - [x] Constant evaluation and constant folding - Folding and precomputing every expression that can be calculated at compile time. Which allows to check if a given constant expression is actually something that can be computed at compile time - [x] Untyped types - Context dependent type assignment of constant expressions, this is a feature I really loved in Go, it makes constants work very well with a very strict type system and it makes errors like overflow of constants in C due to bad size specifier impossible - - [x] Infinite precision integers in constants - - [x] Resolution of all untyped types in the typechecking stage - - [x] Special case of booleans and their type propagation + - [x] Infinite precision integers in constants using big ints! No more overflows or underflows (at least at compile time). - [x] Module system - [x] Lazy evaluation of modules (unused code is not compiled or typechecked) @@ -98,7 +96,11 @@ Dot :: (a: Vec3, b: Vec3): F32 ;; return a.x*b.x + a.y*b.y + a.z*b.z - [ ] Casting might need a redesign not sure from '->' to 'cast' - [x] Runtime reflection - - [x] Dumping info + - [x] Package of type and pointer which enables dynamic typing + - [x] Types are values holding type ids, this way we can do if TypeOf(value) == S64 ;; blah + - [x] Typesafe variadic arguments using []Any slice (no more var args!) + - [x] Any semantics that make it easy to use (automatic unpacking to pointer and type) + - [x] Optional type information dump - [ ] Is the design of this correct? That's a lot of data. - [ ] Builtin data structures @@ -123,11 +125,14 @@ Dot :: (a: Vec3, b: Vec3): F32 ;; return a.x*b.x + a.y*b.y + a.z*b.z - [x] Platforms - [x] Conditional compilation - [x] Windows + - [x] Fully working + - [x] Multimedia library - [x] Linux (Only tested on ubuntu) - [x] Paths - [x] Reading files - [x] Listing files - [x] Virtual memory + - [ ] Multimedia library (maybe using SDL) - [ ] Language constructs - [x] Standard constructs like if, for loop etc. diff --git a/base.cpp b/base.cpp index dbdb6bf..786deac 100644 --- a/base.cpp +++ b/base.cpp @@ -50,12 +50,15 @@ #endif #if OS_WINDOWS + #define OS_EXE ".exe" #define OS_NAME "Win32"_s #define OS_NAME_LOWER "win32"_s #elif OS_LINUX + #define OS_EXE ".out" #define OS_NAME "Linux"_s #define OS_NAME_LOWER "linux"_s #elif OS_MAC + #define OS_EXE ".out" #define OS_NAME "Mac"_s #define OS_NAME_LOWER "mac"_s #else diff --git a/core_compiler.cpp b/core_compiler.cpp index af2bfc4..4ef6fa6 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -46,6 +46,9 @@ intern_strict = l->intern("strict"_s); intern_void = l->intern("void"_s); intern_flag = l->intern("flag"_s); intern_it = l->intern("it"_s); +intern_load = l->intern("load"_s); +intern_import = l->intern("import"_s); +intern_link = l->intern("link"_s); op_info_table[0].op = l->intern("*"_s); op_info_table[1].op = l->intern("/"_s); op_info_table[2].op = l->intern("%"_s); @@ -309,12 +312,13 @@ compile_file(String filename, U32 compile_flags = COMPILE_NULL){ Scratch scratch; F64 begin = os_time(); -#if OS_WINDOWS - String compiler_call = string_fmt(scratch, "clang.exe program.c -Wall -Wno-unused-function -Wno-parentheses-equality -g -o a.exe -lgdi32 -luser32 -lwinmm"); -#else - String compiler_call = string_fmt(scratch, "clang program.c -std=c99 -Wall -Wno-unused-function -Wno-parentheses-equality -g -o a.out"); - // String compiler_call = string_fmt(scratch, "tcc program.c -Wall -g -o a.out"); -#endif + String_Builder builder = {scratch}; + builder.addf("clang program.c -Wall -Wno-unused-function -Wno-parentheses-equality -g -o a" OS_EXE " "); + Iter(&pctx->files_to_link){ + builder.addf("-l%Q ", it.item[0]->intern_val); + } + String compiler_call = string_flatten(scratch, &builder); + log_trace("%Q", compiler_call); system((const char *)compiler_call.str); F64 end = os_time(); diff --git a/core_compiler.h b/core_compiler.h index f44c0cb..7985260 100644 --- a/core_compiler.h +++ b/core_compiler.h @@ -179,6 +179,7 @@ struct Parse_Ctx:Lexer{ String module_folder; String exe_folder; String working_folder; + List files_to_link; S64 indent; String_Builder gen; diff --git a/core_globals.cpp b/core_globals.cpp index 8a41ebf..07d7cda 100644 --- a/core_globals.cpp +++ b/core_globals.cpp @@ -40,6 +40,9 @@ Intern_String intern_strict; Intern_String intern_void; Intern_String intern_flag; Intern_String intern_it; +Intern_String intern_load; +Intern_String intern_import; +Intern_String intern_link; /*END*/ //----------------------------------------------------------------------------- diff --git a/core_parsing.cpp b/core_parsing.cpp index c3a5f7e..5b3a669 100644 --- a/core_parsing.cpp +++ b/core_parsing.cpp @@ -924,13 +924,17 @@ parse_file(Ast_File *file){ pctx->currently_parsed_file = file; pctx->currently_parsed_scope = file; lex_restream(pctx, file->filecontent, file->absolute_file_path); - while(token_expect(SAME_SCOPE)){ - if(token_match_pound(pctx->intern("load"_s))){ + while (token_expect(SAME_SCOPE)) { + if (token_match_pound(intern_load)) { parse_load(true); continue; - } else if(token_match_pound(pctx->intern("import"_s))){ + } else if (token_match_pound(intern_import)) { parse_import(true); continue; + } else if (token_match_pound(intern_link)) { + Token *file = token_expect(TK_StringLit); + add(pctx->perm, &pctx->files_to_link, file); + continue; } if(!file->pos){ diff --git a/core_typechecking.cpp b/core_typechecking.cpp index 2793ebe..5b9726f 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -507,7 +507,7 @@ search_for_single_decl(Ast_Scope *scope, Intern_String name){ compiler_error(0, "Unidentified name [%s]", name.str); } if(search.results.len > 1){ - compiler_error(0, "Found multiple definitions of name [%s]", name.str); + compiler_error(search.results.data[0]->pos, search.results.data[1]->pos, "Found multiple definitions of name [%s]", name.str); } return search.results.data[0]; diff --git a/meta.py b/meta.py index c9082bc..98a50ec 100644 --- a/meta.py +++ b/meta.py @@ -124,4 +124,7 @@ interns = [ "void", "flag", "it", + "load", + "import", + "link", ] \ No newline at end of file diff --git a/modules/GDI32.core b/modules/GDI32.core index f7e5807..43ef442 100644 --- a/modules/GDI32.core +++ b/modules/GDI32.core @@ -1,4 +1,5 @@ #import "KERNEL32.core" +#link "gdi32.lib" RBGQUAD :: struct;; rgbBlue: BYTE; rgbGreen: BYTE; rgbRed: BYTE; rgbReserved: BYTE BITMAPINFOHEADER :: struct;; biSize: DWORD; biWidth: LONG; biHeight: LONG; biPlanes: WORD; biBitCount: WORD; biCompression: DWORD; biSizeImage: DWORD; biXPelsPerMeter: LONG; biYPelsPerMeter: LONG; biClrUsed: DWORD; biClrImportant: DWORD BITMAPINFO :: struct;; bmiHeader: BITMAPINFOHEADER; bmiColors: [1]RBGQUAD diff --git a/modules/KERNEL32.core b/modules/KERNEL32.core index 9ebb3aa..1abe617 100644 --- a/modules/KERNEL32.core +++ b/modules/KERNEL32.core @@ -1,3 +1,5 @@ +#link "kernel32.lib" + DWORD :: U32 LPCSTR :: *char LPSTR :: *char diff --git a/modules/USER32.core b/modules/USER32.core index 19428b8..24b60f3 100644 --- a/modules/USER32.core +++ b/modules/USER32.core @@ -1,4 +1,5 @@ #import "KERNEL32.core" +#link "user32.lib" WNDPROC :: (hwnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM): LRESULT WNDCLASSW :: struct;; style: UINT; lpfnWndProc: WNDPROC; cbClsExtra: int; cbWndExtra: int; hInstance: HINSTANCE; hIcon: HICON; hCursor: HCURSOR; hbrBackground: HBRUSH; lpszMenuName: LPCWSTR; lpszClassName: LPCWSTR MSG :: struct;; hwnd: HWND; message: UINT; wParam: WPARAM; lParam: LPARAM; time: DWORD; pt: POINT; lPrivate: DWORD diff --git a/modules/WINMM.core b/modules/WINMM.core index 3ff15e0..36d03fc 100644 --- a/modules/WINMM.core +++ b/modules/WINMM.core @@ -1,4 +1,5 @@ #import "KERNEL32.core" +#link "winmm.lib" MMRESULT :: UINT TIMERR_NOERROR :: 0