diff --git a/ccodegen.cpp b/ccodegen.cpp index 6082b67..61acc58 100644 --- a/ccodegen.cpp +++ b/ccodegen.cpp @@ -672,21 +672,20 @@ insert_builtin_types_into_scope(Ast_Scope *p){ global F64 parsing_time_begin; global F64 parsing_time_end; -function void -parse_files(Ast_Module *module){ - for(S64 i = 0; i < module->all_loaded_files.len; i++){ - auto it = module->all_loaded_files.data[i]; - parse_file(it); - } -} - function void parse_all_modules(){ parsing_time_begin = os_time(); for(S64 i = 0; i < pctx->modules.len; i++){ - Ast_Module *it = pctx->modules[i]; - parse_files(it); - it->implicit_imports.add(pctx->builtins); + Ast_Module *module = pctx->modules[i]; + + for(S64 j = 0; j < module->all_loaded_files.len; j++){ + Ast_File *file = module->all_loaded_files.data[j]; + parse_file(file); + } + + if(module != pctx->language_base_module) + module->implicit_imports.add(pctx->language_base_module); + } parsing_time_end = os_time(); } @@ -713,11 +712,11 @@ function void resolve_everything_in_module(Ast_Module *module){ resolving_time_begin = os_time(); for(S64 i = 0; i < module->all_loaded_files.len; i++){ - Ast_File *it = module->all_loaded_files[i]; - For_Named(it->decls, jt){ - resolve_name(it, jt->pos, jt->name); - if(jt->kind == AST_STRUCT){ - type_complete(jt->type_val); + Ast_File *file = module->all_loaded_files[i]; + For(file->decls){ + resolve_name(file, it->pos, it->name); + if(it->kind == AST_STRUCT){ + type_complete(it->type_val); } } } @@ -824,7 +823,7 @@ typedef struct String{ } } -#if 1 +#if 0 gen("Type_Info *type_infos = (Type_Info[]){"); global_indent++; For(pctx->all_types){ diff --git a/compiler.h b/compiler.h index 9a69571..0e182e4 100644 --- a/compiler.h +++ b/compiler.h @@ -186,7 +186,8 @@ struct Parse_Ctx:Lexer{ U64 unique_ids; // @Debug Map type_map; - Ast_Module *builtins; + Ast_Module *language_base_module; + // Array files; Array modules; Array ordered_decls; @@ -251,8 +252,6 @@ parse_init(Parse_Ctx *ctx, Allocator *perm_allocator, Allocator *heap_allocator) arena_init(&ctx->stage_arena, "Compiler stage arena"_s); lex_init(ctx->perm, ctx->heap, ctx); - ctx->builtins = ast_module(0, ctx->intern("builtins"_s)); - insert_builtin_types_into_scope((Ast_Scope *)ctx->builtins); init_type(); } \ No newline at end of file diff --git a/main.cpp b/main.cpp index f812643..1f4d218 100644 --- a/main.cpp +++ b/main.cpp @@ -41,6 +41,11 @@ want to export all the symbols, we can namespace them optionally. ------------------------------------------------------------------------------- @todo +[ ] - I would love for String, slice, Any etc. to have their struct declarations in source files, I also would want for stuff like string.str to work without weird special cases +[ ] - Implementing type Any +[ ] - Runtime TypeInfo +[ ] - Proper type Type support + [ ] - #test construct that would gather all tests and run them on start of program or something [ ] - Foreign import that would link library [ ] - Builtin dynamic arrays @@ -61,6 +66,7 @@ want to export all the symbols, we can namespace them optionally. [ ] - Disable ability to parse inner structs, functions, constants etc. ? [ ] - Write up on order independent declarations +[ ] - Consider changing syntax of scopes to use braces { } [ ] - Order independent declarations in structs ? [ ] - constructor => thing :: (i: S32) -> {i = i, thing = 10} [ ] - Casting to basic types by call S64(x) @@ -74,7 +80,6 @@ want to export all the symbols, we can namespace them optionally. [ ] - Compound that zeros values - .{} , Compound that assumes defaults from struct definition - {} [ ] - Inject stack traces into the program [ ] - Conditional compilation #if -[ ] - I would love for String, slice, Any etc. to have their struct declarations in source files, I also would want for stuff like string.str to work without weird special cases [ ] - Polymorphism - create declaration of a polymorphic thing, when it's called just copy it, replace types and typecheck normally, when someone calls again you just search for the instantiation again @donzo @@ -177,6 +182,13 @@ int main(int argument_count, char **arguments){ F64 total_time = os_time(); begin_compilation(); + { + Ast_Module *module = ast_module(0, pctx->intern("language.kl"_s)); + pctx->language_base_module = module; + register_ast_file(0, module->name, module, GLOBAL_IMPLICIT_LOAD); + insert_builtin_types_into_scope(module); + } + Ast_Module *module = add_module(0, pctx->intern(program_name)); parse_all_modules(); assert(module); diff --git a/parsing.cpp b/parsing.cpp index 3f93b94..6fe7e09 100644 --- a/parsing.cpp +++ b/parsing.cpp @@ -670,6 +670,10 @@ add_implicit_import(Ast_Scope *scope, Ast_Scope *add){ } } +enum{ + GLOBAL_IMPLICIT_LOAD = 1 +}; + function Ast_File * register_ast_file(Token *pos, Intern_String filename, Ast_Module *module, B32 global_implicit_load){ Ast_File *file = 0; diff --git a/programs/language.kl b/programs/language.kl new file mode 100644 index 0000000..bdfc110 --- /dev/null +++ b/programs/language.kl @@ -0,0 +1,67 @@ + +/* +String :: struct + str: *U8 + len: S64 + +Slice :: struct + data: *void + len : S64 + +Any :: struct + data: *void + type: Type_ID + +*/ + +Type_ID :: S32 +Type_Info_Kind :: enum + TYPE_NONE + TYPE_S64 :: 7 // FIRST_NUMERIC + TYPE_S32 + TYPE_S16 + TYPE_S8 + TYPE_INT + TYPE_CHAR + TYPE_U64 + TYPE_U32 + TYPE_U16 + TYPE_U8 + TYPE_F32 + TYPE_F64 + TYPE_POINTER + TYPE_BOOL // LAST_NUMERIC + TYPE_STRING + TYPE_VOID + TYPE_ARRAY + TYPE_LAMBDA + TYPE_STRUCT + TYPE_UNION + TYPE_ENUM + TYPE_TYPE + TYPE_SLICE + TYPE_TUPLE + TYPE_ANY + +Type_Info_Struct_Member :: struct + name: String + type_id: Type_ID + offset: S32 + +Type_Info :: struct + kind: Type_Info_Kind + size: S32 + align: S32 + is_unsigned: Bool + type_id: Type_ID + + base_type: Type_ID + array_size: S32 + struct_member_count: S32 + struct_members: *Type_Info_Struct_Member + lambda_argument_count: S32 + lambda_arguments: *Type_Info + lambda_return: Type_ID + +type_infos_len: U32 #foreign +type_infos : *Type_Info #foreign diff --git a/programs/main.kl b/programs/main.kl index 720f04d..5a8d313 100644 --- a/programs/main.kl +++ b/programs/main.kl @@ -14,63 +14,6 @@ Windows_Bitmap :: struct hdc: HDC dib: HBITMAP -Type_ID :: S32 -Type_Info_Kind :: enum - TYPE_NONE - TYPE_S64 :: 7 // FIRST_NUMERIC - TYPE_S32 - TYPE_S16 - TYPE_S8 - TYPE_INT - TYPE_CHAR - TYPE_U64 - TYPE_U32 - TYPE_U16 - TYPE_U8 - TYPE_F32 - TYPE_F64 - TYPE_POINTER - TYPE_BOOL // LAST_NUMERIC - TYPE_STRING - TYPE_VOID - TYPE_ARRAY - TYPE_LAMBDA - TYPE_STRUCT - TYPE_UNION - TYPE_ENUM - TYPE_TYPE - TYPE_SLICE - TYPE_TUPLE - TYPE_ANY - -Any :: struct - data: *void - type: Type_ID - -Type_Info_Struct_Member :: struct - name: String - type_id: Type_ID - offset: S32 - -Type_Info :: struct - kind: Type_Info_Kind - size: S32 - align: S32 - is_unsigned: Bool - type_id: Type_ID - - base_type: Type_ID - array_size: S32 - struct_member_count: S32 - struct_members: *Type_Info_Struct_Member - lambda_argument_count: S32 - lambda_arguments: *Type_Info - lambda_return: Type_ID - -type_infos_len: U32 #foreign -type_infos : *Type_Info #foreign - - Bitmap :: struct size: Vec2I data: *U32