Cleanup iterators

This commit is contained in:
Krzosa Karol
2023-01-01 17:44:27 +01:00
parent d120d05eee
commit d6a5df8d95
9 changed files with 86 additions and 108 deletions

View File

@@ -679,9 +679,9 @@ gen_ast(Ast *ast){
gen("%Q{", node->unique_name);
global_indent++;
is_inside_struct++;
Iter(&node->scope->decls){
For(node->scope->decls){
genln("");
gen_ast(it.item[0]);
gen_ast(it);
}
is_inside_struct--;
@@ -694,10 +694,10 @@ gen_ast(Ast *ast){
gen("/*enum %Q{", node->name);
// @todo add typespec
global_indent++;
Iter(&node->scope->decls){
genln("%Q", it.item[0]->name);
For(node->scope->decls){
genln("%Q", it->name);
gen(" = ");
gen_value(it.item[0]->pos, it.item[0]->value);
gen_value(it->pos, it->value);
gen(",");
}
global_indent--;
@@ -836,20 +836,17 @@ typedef struct String{
)");
// Generate struct forward decls
Iter(&pctx->ordered_decls){
auto i = it.item[0];
if(i->kind == AST_STRUCT){
genln("typedef struct %Q %Q;", i->unique_name, i->unique_name);
For(pctx->ordered_decls){
if(it->kind == AST_STRUCT){
genln("typedef struct %Q %Q;", it->unique_name, it->unique_name);
}
}
// Generate slice and tuple types
Iter(&pctx->all_types){
For_Named(pctx->all_types, type){
Scratch_Arena *scratch = pctx->scratch;
Scratch_Scope _scope(scratch);
Ast_Type *type = it.item[0];
if(type->kind == TYPE_SLICE){
genln("typedef struct Slice%llu{", type->type_id);
global_indent++;
@@ -883,21 +880,21 @@ typedef struct String{
Ast_Decl *win_main = 0;
// Generate lambda forward decls
Iter(&pctx->ordered_decls){
if(it.item[0]->kind == AST_LAMBDA){
if(it.item[0]->name == intern_main){
main = it.item[0];
it.item[0]->unique_name = it.item[0]->name;
For(pctx->ordered_decls){
if(it->kind == AST_LAMBDA){
if(it->name == intern_main){
main = it;
it->unique_name = it->name;
}
if(it.item[0]->name == intern_win_main){
win_main = it.item[0];
it.item[0]->unique_name = it.item[0]->name;
if(it->name == intern_win_main){
win_main = it;
it->unique_name = it->name;
}
genln("");
gen_lambda(it.item[0]->unique_name, it.item[0]->lambda, false);
gen_lambda(it->unique_name, it->lambda, false);
}
}
@@ -918,8 +915,7 @@ typedef struct String{
genln("int64_t type_infos_len = %d;", length(&pctx->all_types));
genln("Type_Info *type_infos = (Type_Info[]){");
global_indent++;
Iter(&pctx->all_types){
Ast_Type *t = it.item[0];
For_Named(pctx->all_types, t){
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){
@@ -965,11 +961,13 @@ typedef struct String{
}
// Generate actual code
Iter(&pctx->ordered_decls){
if(it.index >= pctx->base_language_ordered_decl_len){
int index = 0;
For(pctx->ordered_decls){
if(index >= pctx->base_language_ordered_decl_len){
genln("");
gen_ast(it.item[0]);
gen_ast(it);
}
index += 1;
}