From 91b7b8090f9f091fd174c0d5624d4d205d76019c Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Fri, 30 Sep 2022 09:56:12 +0200 Subject: [PATCH] More code to List --- core_codegen_c_language.cpp | 33 +++++++++++++++++---------------- core_compiler.cpp | 3 +-- core_compiler.h | 2 +- core_typechecking.cpp | 4 ++-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/core_codegen_c_language.cpp b/core_codegen_c_language.cpp index 9236740..bc9ebd5 100644 --- a/core_codegen_c_language.cpp +++ b/core_codegen_c_language.cpp @@ -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); } diff --git a/core_compiler.cpp b/core_compiler.cpp index afa0632..51a6977 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -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 diff --git a/core_compiler.h b/core_compiler.h index 94132ce..5eb5d7b 100644 --- a/core_compiler.h +++ b/core_compiler.h @@ -161,7 +161,7 @@ struct Parse_Ctx:Lexer{ Allocator *heap; Arena stage_arena; - Array all_types; + List all_types; S32 type_ids; int lambda_ids; U64 unique_ids; // @Debug diff --git a/core_typechecking.cpp b/core_typechecking.cpp index fa93579..d9f6b69 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -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; }