Add a language.kl module which should contain builtin stuff
This commit is contained in:
33
ccodegen.cpp
33
ccodegen.cpp
@@ -672,21 +672,20 @@ insert_builtin_types_into_scope(Ast_Scope *p){
|
|||||||
|
|
||||||
global F64 parsing_time_begin;
|
global F64 parsing_time_begin;
|
||||||
global F64 parsing_time_end;
|
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
|
function void
|
||||||
parse_all_modules(){
|
parse_all_modules(){
|
||||||
parsing_time_begin = os_time();
|
parsing_time_begin = os_time();
|
||||||
for(S64 i = 0; i < pctx->modules.len; i++){
|
for(S64 i = 0; i < pctx->modules.len; i++){
|
||||||
Ast_Module *it = pctx->modules[i];
|
Ast_Module *module = pctx->modules[i];
|
||||||
parse_files(it);
|
|
||||||
it->implicit_imports.add(pctx->builtins);
|
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();
|
parsing_time_end = os_time();
|
||||||
}
|
}
|
||||||
@@ -713,11 +712,11 @@ function void
|
|||||||
resolve_everything_in_module(Ast_Module *module){
|
resolve_everything_in_module(Ast_Module *module){
|
||||||
resolving_time_begin = os_time();
|
resolving_time_begin = os_time();
|
||||||
for(S64 i = 0; i < module->all_loaded_files.len; i++){
|
for(S64 i = 0; i < module->all_loaded_files.len; i++){
|
||||||
Ast_File *it = module->all_loaded_files[i];
|
Ast_File *file = module->all_loaded_files[i];
|
||||||
For_Named(it->decls, jt){
|
For(file->decls){
|
||||||
resolve_name(it, jt->pos, jt->name);
|
resolve_name(file, it->pos, it->name);
|
||||||
if(jt->kind == AST_STRUCT){
|
if(it->kind == AST_STRUCT){
|
||||||
type_complete(jt->type_val);
|
type_complete(it->type_val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -824,7 +823,7 @@ typedef struct String{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
#if 0
|
||||||
gen("Type_Info *type_infos = (Type_Info[]){");
|
gen("Type_Info *type_infos = (Type_Info[]){");
|
||||||
global_indent++;
|
global_indent++;
|
||||||
For(pctx->all_types){
|
For(pctx->all_types){
|
||||||
|
|||||||
@@ -186,7 +186,8 @@ struct Parse_Ctx:Lexer{
|
|||||||
U64 unique_ids; // @Debug
|
U64 unique_ids; // @Debug
|
||||||
Map type_map;
|
Map type_map;
|
||||||
|
|
||||||
Ast_Module *builtins;
|
Ast_Module *language_base_module;
|
||||||
|
|
||||||
// Array<Ast_File *> files;
|
// Array<Ast_File *> files;
|
||||||
Array<Ast_Module *> modules;
|
Array<Ast_Module *> modules;
|
||||||
Array<Ast_Decl *> ordered_decls;
|
Array<Ast_Decl *> 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);
|
arena_init(&ctx->stage_arena, "Compiler stage arena"_s);
|
||||||
|
|
||||||
lex_init(ctx->perm, ctx->heap, ctx);
|
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();
|
init_type();
|
||||||
}
|
}
|
||||||
14
main.cpp
14
main.cpp
@@ -41,6 +41,11 @@ want to export all the symbols, we can namespace them optionally.
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
@todo
|
@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
|
[ ] - #test construct that would gather all tests and run them on start of program or something
|
||||||
[ ] - Foreign import that would link library
|
[ ] - Foreign import that would link library
|
||||||
[ ] - Builtin dynamic arrays
|
[ ] - 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. ?
|
[ ] - Disable ability to parse inner structs, functions, constants etc. ?
|
||||||
[ ] - Write up on order independent declarations
|
[ ] - Write up on order independent declarations
|
||||||
|
|
||||||
|
[ ] - Consider changing syntax of scopes to use braces { }
|
||||||
[ ] - Order independent declarations in structs ?
|
[ ] - Order independent declarations in structs ?
|
||||||
[ ] - constructor => thing :: (i: S32) -> {i = i, thing = 10}
|
[ ] - constructor => thing :: (i: S32) -> {i = i, thing = 10}
|
||||||
[ ] - Casting to basic types by call S64(x)
|
[ ] - 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 - {}
|
[ ] - Compound that zeros values - .{} , Compound that assumes defaults from struct definition - {}
|
||||||
[ ] - Inject stack traces into the program
|
[ ] - Inject stack traces into the program
|
||||||
[ ] - Conditional compilation #if
|
[ ] - 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
|
[ ] - 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
|
@donzo
|
||||||
@@ -177,6 +182,13 @@ int main(int argument_count, char **arguments){
|
|||||||
F64 total_time = os_time();
|
F64 total_time = os_time();
|
||||||
begin_compilation();
|
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));
|
Ast_Module *module = add_module(0, pctx->intern(program_name));
|
||||||
parse_all_modules();
|
parse_all_modules();
|
||||||
assert(module);
|
assert(module);
|
||||||
|
|||||||
@@ -670,6 +670,10 @@ add_implicit_import(Ast_Scope *scope, Ast_Scope *add){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum{
|
||||||
|
GLOBAL_IMPLICIT_LOAD = 1
|
||||||
|
};
|
||||||
|
|
||||||
function Ast_File *
|
function Ast_File *
|
||||||
register_ast_file(Token *pos, Intern_String filename, Ast_Module *module, B32 global_implicit_load){
|
register_ast_file(Token *pos, Intern_String filename, Ast_Module *module, B32 global_implicit_load){
|
||||||
Ast_File *file = 0;
|
Ast_File *file = 0;
|
||||||
|
|||||||
67
programs/language.kl
Normal file
67
programs/language.kl
Normal file
@@ -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
|
||||||
@@ -14,63 +14,6 @@ Windows_Bitmap :: struct
|
|||||||
hdc: HDC
|
hdc: HDC
|
||||||
dib: HBITMAP
|
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
|
Bitmap :: struct
|
||||||
size: Vec2I
|
size: Vec2I
|
||||||
data: *U32
|
data: *U32
|
||||||
|
|||||||
Reference in New Issue
Block a user