Compounds for structs
This commit is contained in:
@@ -62,3 +62,10 @@ thing0 :: 10
|
|||||||
thing1 :: thing0 + 11
|
thing1 :: thing0 + 11
|
||||||
thing2 :: thing1 + 20
|
thing2 :: thing1 + 20
|
||||||
combin :: thing0 + thing1 + thing2
|
combin :: thing0 + thing1 + thing2
|
||||||
|
|
||||||
|
Some :: struct
|
||||||
|
len: S64
|
||||||
|
cap: S64
|
||||||
|
|
||||||
|
some := Some{3, 2}
|
||||||
|
other := Some{len = 1, cap = 3}
|
||||||
12
main.cpp
12
main.cpp
@@ -203,12 +203,12 @@ int main(int argument_count, char **arguments){
|
|||||||
#endif
|
#endif
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
Array<String> files = {scratch};
|
Array<String> files = {scratch};
|
||||||
files.add("lambdas.kl"_s);
|
// files.add("lambdas.kl"_s);
|
||||||
files.add("order1.kl"_s);
|
// files.add("order1.kl"_s);
|
||||||
files.add("order2.kl"_s);
|
// files.add("order2.kl"_s);
|
||||||
files.add("new_types.kl"_s);
|
// files.add("new_types.kl"_s);
|
||||||
files.add("enums.kl"_s);
|
// files.add("enums.kl"_s);
|
||||||
// files.add("G.globals.kl"_s);
|
files.add("G.globals.kl"_s);
|
||||||
// files.add("euler.kl"_s);
|
// files.add("euler.kl"_s);
|
||||||
String result = compile_files(files);
|
String result = compile_files(files);
|
||||||
printf("%s", result.str);
|
printf("%s", result.str);
|
||||||
|
|||||||
@@ -614,7 +614,38 @@ resolve_compound_array(Ast_Call *node, Ast_Type *type){
|
|||||||
|
|
||||||
function void
|
function void
|
||||||
resolve_compound_struct(Ast_Call *node, Ast_Type *type){
|
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
|
function Operand
|
||||||
|
|||||||
Reference in New Issue
Block a user