diff --git a/G.globals.kl b/G.globals.kl index d332f37..79e7ce5 100644 --- a/G.globals.kl +++ b/G.globals.kl @@ -62,3 +62,10 @@ thing0 :: 10 thing1 :: thing0 + 11 thing2 :: thing1 + 20 combin :: thing0 + thing1 + thing2 + +Some :: struct + len: S64 + cap: S64 + +some := Some{3, 2} +other := Some{len = 1, cap = 3} \ No newline at end of file diff --git a/main.cpp b/main.cpp index 26a7717..15f62ab 100644 --- a/main.cpp +++ b/main.cpp @@ -203,12 +203,12 @@ int main(int argument_count, char **arguments){ #endif Scratch scratch; Array files = {scratch}; - files.add("lambdas.kl"_s); - files.add("order1.kl"_s); - files.add("order2.kl"_s); - files.add("new_types.kl"_s); - files.add("enums.kl"_s); - // files.add("G.globals.kl"_s); + // files.add("lambdas.kl"_s); + // files.add("order1.kl"_s); + // files.add("order2.kl"_s); + // files.add("new_types.kl"_s); + // files.add("enums.kl"_s); + files.add("G.globals.kl"_s); // files.add("euler.kl"_s); String result = compile_files(files); printf("%s", result.str); diff --git a/typechecking.cpp b/typechecking.cpp index 090e1cc..c29f0a1 100644 --- a/typechecking.cpp +++ b/typechecking.cpp @@ -614,7 +614,38 @@ resolve_compound_array(Ast_Call *node, Ast_Type *type){ function void resolve_compound_struct(Ast_Call *node, Ast_Type *type){ + // type->agg.members + S64 default_counter = 0; + For(node->exprs){ + if(it->index) + compiler_error(it->pos, "Struct cant be indexed"); + Ast_Type *item_type = 0; + if(it->name){ + For_It(type->agg.members, m){ + if(it->name->intern_val == m.name){ + item_type = m.type; + if(m.visited){ + compiler_error(it->pos, "Field already initialized"); + } else m.visited = true; + break; + } + } + if(!item_type) + compiler_error(it->pos, "No member with that name"); + } + else{ + if(default_counter == -1) + compiler_error(it->pos, "Cant mix named fields and normal fields"); + if(default_counter >= type->agg.members.len) + compiler_error(it->pos, "Too many struct initializers"); + item_type = type->agg.members[default_counter++].type; + } + + assert(item_type); + Operand item = resolve_expr(it->item, AST_CANT_BE_NULL); + make_sure_value_is_compatible_with_type(it->pos, &item, item_type, TYPE_AND_EXPR_REQUIRED); + } } function Operand diff --git a/types.h b/types.h index 4cdebe2..12994e6 100644 --- a/types.h +++ b/types.h @@ -86,6 +86,7 @@ struct Ast_Resolved_Member{ Ast_Type *type; Intern_String name; U64 offset; + B32 visited; }; #define ARRAY_SIZE_INFERRED (-1)