Cleanup Slice and Tuple generation

This commit is contained in:
Krzosa Karol
2022-06-16 12:16:15 +02:00
parent c604b44458
commit 5345894e3e
6 changed files with 48 additions and 28 deletions

View File

@@ -65,7 +65,7 @@ string_simple_decl_prefix(Allocator *a, Ast_Type *ast, bool scope_names){
}break;
case TYPE_SLICE:{
String string = string_simple_decl_prefix(a, ast->base, true);
string = string_fmt(a, "SliceOf%Q", string);
string = string_fmt(a, "Slice%llu ", ast->type_id);
return string;
}break;
case TYPE_STRUCT: {
@@ -727,6 +727,36 @@ typedef struct String{
}
}
for(S64 i = 0; i < pctx->type_map.cap; i++){
Map_Key_Value *it = pctx->type_map.data + i;
if(!it->occupied) continue;
Ast_Type *type = (Ast_Type *)it->value;
if(type->kind == TYPE_SLICE){
genln("typedef struct Slice%llu{", type->type_id);
global_indent++;
genln("S64 len;");
genln("");
gen_simple_decl(type->base);
gen(" data;");
global_indent--;
genln("} Slice%llu;", type->type_id);
}
else if(type->kind == TYPE_TUPLE){
genln("typedef struct Tuple%llu{", type->type_id);
global_indent++;
For(type->agg.members){
genln("");
gen_simple_decl(it.type);
gen(" m%llu;", type->agg.members.get_index(&it));
}
global_indent--;
genln("} Tuple%llu;", type->type_id);
}
}
For(pctx->ordered_decls){
genln("");
gen_ast(it);