More code to List

This commit is contained in:
Krzosa Karol
2022-09-30 09:56:12 +02:00
parent 0a7fe8caad
commit 91b7b8090f
4 changed files with 21 additions and 21 deletions

View File

@@ -765,9 +765,9 @@ typedef struct String{
}
// Generate slice and tuple types
For(pctx->all_types){
Iter(&pctx->all_types){
Scratch scratch;
Ast_Type *type = it;
Ast_Type *type = it.item[0];
if(type->kind == TYPE_SLICE){
genln("typedef struct Slice%llu{", type->type_id);
@@ -831,34 +831,35 @@ typedef struct String{
}
// Generate type info
genln("S64 type_infos_len = %d;", pctx->all_types.len);
genln("S64 type_infos_len = %d;", length(&pctx->all_types));
genln("Type_Info *type_infos = (Type_Info[]){");
global_indent++;
For(pctx->all_types){
genln("{/*%Q*/.kind = %d, .size = %d, .align = %d, .is_unsigned = %s, .type = %d, ", typestring(it),
(S32)it->kind, (S32)it->size, (S32)it->align, it->is_unsigned ? "true" : "false", it->type_id);
switch(it->kind){
Iter(&pctx->all_types){
Ast_Type *t = it.item[0];
genln("{/*%Q*/.kind = %d, .size = %d, .align = %d, .is_unsigned = %s, .type = %d, ", typestring(t),
(S32)t->kind, (S32)t->size, (S32)t->align, t->is_unsigned ? "true" : "false", t->type_id);
switch(t->kind){
case TYPE_POINTER:
case TYPE_SLICE: {
gen(".base_type = %d", it->base->type_id);
gen(".base_type = %d", t->base->type_id);
} break;
case TYPE_ARRAY: {
gen(".base_type = %d, ", it->base->type_id);
gen(".array_size = %d", it->arr.size);
gen(".base_type = %d, ", t->base->type_id);
gen(".array_size = %d", t->arr.size);
}break;
case TYPE_LAMBDA: {
gen(".lambda_return = %d, ", it->func.ret->type_id);
gen(".lambda_argument_count = %d, ", it->func.args.len);
gen(".lambda_arguments = (Type_Info[%d]){", it->func.args.len);
For_Named(it->func.args, arg){
gen(".lambda_return = %d, ", t->func.ret->type_id);
gen(".lambda_argument_count = %d, ", t->func.args.len);
gen(".lambda_arguments = (Type_Info[%d]){", t->func.args.len);
For_Named(t->func.args, arg){
gen("{.type = %d}, ", arg->type_id);
}
gen("}");
} break;
case TYPE_STRUCT:{
gen(".struct_member_count = %d, ", it->agg.members.len);
gen(".struct_member_count = %d, ", t->agg.members.len);
gen(".struct_members = (Type_Info_Struct_Member[]){");
For_Named(it->agg.members, m){
For_Named(t->agg.members, m){
gen("{.name = (String){(U8 *)\"%Q\", %d}, .type = %d, .offset = %d}, ", m.name, m.name.len, m.type->type_id, m.offset);
}

View File

@@ -85,7 +85,6 @@ parse_init(Parse_Ctx *ctx, Arena *perm_allocator, Allocator *heap_allocator){
ctx->heap = heap_allocator;
ctx->gen = {ctx->heap};
ctx->type_map = {ctx->heap};
ctx->all_types = {ctx->heap};
ctx->helper_builder= {ctx->heap};
ctx->scope_ids = 1;
bigint_allocator = ctx->perm;
@@ -128,7 +127,7 @@ insert_builtin_into_scope(Ast_Scope *p, String name, Ast_Type *type){
decl->parent_scope = p;
decl->state = DECL_RESOLVED;
insert_into_scope(p, decl);
pctx->all_types.add(type);
add(pctx->perm, &pctx->all_types, type);
}
function void

View File

@@ -161,7 +161,7 @@ struct Parse_Ctx:Lexer{
Allocator *heap;
Arena stage_arena;
Array<Ast_Type *> all_types;
List<Ast_Type *> all_types;
S32 type_ids;
int lambda_ids;
U64 unique_ids; // @Debug

View File

@@ -153,7 +153,7 @@ type_new(Allocator *allocator, Ast_Type_Kind kind, SizeU size, SizeU align){
result->size = size;
result->align = align;
result->type_id = pctx->type_ids++;
pctx->all_types.add(result);
add(pctx->perm, &pctx->all_types, result);
return result;
}
@@ -163,7 +163,7 @@ type_copy(Allocator *a, Ast_Type *type){
Ast_Type *result = exp_alloc_type(a, Ast_Type);
memory_copy(result, type, sizeof(Ast_Type));
result->type_id = pctx->type_ids++;
pctx->all_types.add(result);
add(pctx->perm, &pctx->all_types, result);
return result;
}