More code to List
This commit is contained in:
@@ -765,9 +765,9 @@ typedef struct String{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate slice and tuple types
|
// Generate slice and tuple types
|
||||||
For(pctx->all_types){
|
Iter(&pctx->all_types){
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
Ast_Type *type = it;
|
Ast_Type *type = it.item[0];
|
||||||
|
|
||||||
if(type->kind == TYPE_SLICE){
|
if(type->kind == TYPE_SLICE){
|
||||||
genln("typedef struct Slice%llu{", type->type_id);
|
genln("typedef struct Slice%llu{", type->type_id);
|
||||||
@@ -831,34 +831,35 @@ typedef struct String{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate type info
|
// 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[]){");
|
genln("Type_Info *type_infos = (Type_Info[]){");
|
||||||
global_indent++;
|
global_indent++;
|
||||||
For(pctx->all_types){
|
Iter(&pctx->all_types){
|
||||||
genln("{/*%Q*/.kind = %d, .size = %d, .align = %d, .is_unsigned = %s, .type = %d, ", typestring(it),
|
Ast_Type *t = it.item[0];
|
||||||
(S32)it->kind, (S32)it->size, (S32)it->align, it->is_unsigned ? "true" : "false", it->type_id);
|
genln("{/*%Q*/.kind = %d, .size = %d, .align = %d, .is_unsigned = %s, .type = %d, ", typestring(t),
|
||||||
switch(it->kind){
|
(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_POINTER:
|
||||||
case TYPE_SLICE: {
|
case TYPE_SLICE: {
|
||||||
gen(".base_type = %d", it->base->type_id);
|
gen(".base_type = %d", t->base->type_id);
|
||||||
} break;
|
} break;
|
||||||
case TYPE_ARRAY: {
|
case TYPE_ARRAY: {
|
||||||
gen(".base_type = %d, ", it->base->type_id);
|
gen(".base_type = %d, ", t->base->type_id);
|
||||||
gen(".array_size = %d", it->arr.size);
|
gen(".array_size = %d", t->arr.size);
|
||||||
}break;
|
}break;
|
||||||
case TYPE_LAMBDA: {
|
case TYPE_LAMBDA: {
|
||||||
gen(".lambda_return = %d, ", it->func.ret->type_id);
|
gen(".lambda_return = %d, ", t->func.ret->type_id);
|
||||||
gen(".lambda_argument_count = %d, ", it->func.args.len);
|
gen(".lambda_argument_count = %d, ", t->func.args.len);
|
||||||
gen(".lambda_arguments = (Type_Info[%d]){", it->func.args.len);
|
gen(".lambda_arguments = (Type_Info[%d]){", t->func.args.len);
|
||||||
For_Named(it->func.args, arg){
|
For_Named(t->func.args, arg){
|
||||||
gen("{.type = %d}, ", arg->type_id);
|
gen("{.type = %d}, ", arg->type_id);
|
||||||
}
|
}
|
||||||
gen("}");
|
gen("}");
|
||||||
} break;
|
} break;
|
||||||
case TYPE_STRUCT:{
|
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[]){");
|
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);
|
gen("{.name = (String){(U8 *)\"%Q\", %d}, .type = %d, .offset = %d}, ", m.name, m.name.len, m.type->type_id, m.offset);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ parse_init(Parse_Ctx *ctx, Arena *perm_allocator, Allocator *heap_allocator){
|
|||||||
ctx->heap = heap_allocator;
|
ctx->heap = heap_allocator;
|
||||||
ctx->gen = {ctx->heap};
|
ctx->gen = {ctx->heap};
|
||||||
ctx->type_map = {ctx->heap};
|
ctx->type_map = {ctx->heap};
|
||||||
ctx->all_types = {ctx->heap};
|
|
||||||
ctx->helper_builder= {ctx->heap};
|
ctx->helper_builder= {ctx->heap};
|
||||||
ctx->scope_ids = 1;
|
ctx->scope_ids = 1;
|
||||||
bigint_allocator = ctx->perm;
|
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->parent_scope = p;
|
||||||
decl->state = DECL_RESOLVED;
|
decl->state = DECL_RESOLVED;
|
||||||
insert_into_scope(p, decl);
|
insert_into_scope(p, decl);
|
||||||
pctx->all_types.add(type);
|
add(pctx->perm, &pctx->all_types, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ struct Parse_Ctx:Lexer{
|
|||||||
Allocator *heap;
|
Allocator *heap;
|
||||||
Arena stage_arena;
|
Arena stage_arena;
|
||||||
|
|
||||||
Array<Ast_Type *> all_types;
|
List<Ast_Type *> all_types;
|
||||||
S32 type_ids;
|
S32 type_ids;
|
||||||
int lambda_ids;
|
int lambda_ids;
|
||||||
U64 unique_ids; // @Debug
|
U64 unique_ids; // @Debug
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ type_new(Allocator *allocator, Ast_Type_Kind kind, SizeU size, SizeU align){
|
|||||||
result->size = size;
|
result->size = size;
|
||||||
result->align = align;
|
result->align = align;
|
||||||
result->type_id = pctx->type_ids++;
|
result->type_id = pctx->type_ids++;
|
||||||
pctx->all_types.add(result);
|
add(pctx->perm, &pctx->all_types, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ type_copy(Allocator *a, Ast_Type *type){
|
|||||||
Ast_Type *result = exp_alloc_type(a, Ast_Type);
|
Ast_Type *result = exp_alloc_type(a, Ast_Type);
|
||||||
memory_copy(result, type, sizeof(Ast_Type));
|
memory_copy(result, type, sizeof(Ast_Type));
|
||||||
result->type_id = pctx->type_ids++;
|
result->type_id = pctx->type_ids++;
|
||||||
pctx->all_types.add(result);
|
add(pctx->perm, &pctx->all_types, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user