Using For from Array
This commit is contained in:
2
base.cpp
2
base.cpp
@@ -440,5 +440,3 @@ operator!=(Intern_String a, Intern_String b) {
|
|||||||
|
|
||||||
#define For_Linked_List_Named(a, it) for (auto *it = (a); it; it = it->next) // @todo: reference?
|
#define For_Linked_List_Named(a, it) for (auto *it = (a); it; it = it->next) // @todo: reference?
|
||||||
#define For_Linked_List(a) For_Linked_List_Named(a, it)
|
#define For_Linked_List(a) For_Linked_List_Named(a, it)
|
||||||
#define For_Named(a, it) for (auto &it : (a))
|
|
||||||
#define For(a) For_Named((a), it)
|
|
||||||
|
|||||||
@@ -755,7 +755,7 @@ gen_ast(Ast *ast) {
|
|||||||
global_indent++;
|
global_indent++;
|
||||||
|
|
||||||
For(node->cases) {
|
For(node->cases) {
|
||||||
For_Named(it->labels, label) {
|
For2(it->labels, label) {
|
||||||
gen_line(it);
|
gen_line(it);
|
||||||
genln("");
|
genln("");
|
||||||
gen("case ");
|
gen("case ");
|
||||||
@@ -951,7 +951,7 @@ compile_to_c_code() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate slice and tuple types
|
// Generate slice and tuple types
|
||||||
For_Named(pctx->all_types, type) {
|
For2(pctx->all_types, type) {
|
||||||
Scoped_Arena scratch(pctx->scratch);
|
Scoped_Arena scratch(pctx->scratch);
|
||||||
|
|
||||||
if (type->kind == TYPE_SLICE) {
|
if (type->kind == TYPE_SLICE) {
|
||||||
@@ -1021,7 +1021,7 @@ compile_to_c_code() {
|
|||||||
genln("int64_t type_infos_len = %d;", length(&pctx->all_types));
|
genln("int64_t 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_Named(pctx->all_types, t) {
|
For2(pctx->all_types, t) {
|
||||||
if (t->kind == TYPE_POLYMORPH) continue;
|
if (t->kind == TYPE_POLYMORPH) continue;
|
||||||
genln("{/*%Q*/.kind = %d, .size = %d, .align = %d, .is_unsigned = %s, .type = %d, ", typestring(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);
|
(S32)t->kind, (S32)t->size, (S32)t->align, t->is_unsigned ? "true" : "false", t->type_id);
|
||||||
@@ -1038,7 +1038,7 @@ compile_to_c_code() {
|
|||||||
gen(".lambda_return = %d, ", t->func.ret->type_id);
|
gen(".lambda_return = %d, ", t->func.ret->type_id);
|
||||||
gen(".lambda_arguments.len = %d, ", t->func.args.len);
|
gen(".lambda_arguments.len = %d, ", t->func.args.len);
|
||||||
gen(".lambda_arguments.data = (Type_Info[%d]){", t->func.args.len);
|
gen(".lambda_arguments.data = (Type_Info[%d]){", t->func.args.len);
|
||||||
For_Named(t->func.args, arg) {
|
For2(t->func.args, arg) {
|
||||||
gen("{.type = %d}, ", arg->type_id);
|
gen("{.type = %d}, ", arg->type_id);
|
||||||
}
|
}
|
||||||
gen("}");
|
gen("}");
|
||||||
@@ -1047,7 +1047,7 @@ compile_to_c_code() {
|
|||||||
case TYPE_STRUCT: {
|
case TYPE_STRUCT: {
|
||||||
gen(".struct_members.len = %d, ", t->agg.members.len);
|
gen(".struct_members.len = %d, ", t->agg.members.len);
|
||||||
gen(".struct_members.data = (Type_Info_Struct_Member[]){");
|
gen(".struct_members.data = (Type_Info_Struct_Member[]){");
|
||||||
For_Named(t->agg.members, m) {
|
For2(t->agg.members, m) {
|
||||||
gen("{.name = (%Q){(uint8_t *)\"%Q\", %d}, .type = %d, .offset = %d}, ", prefixed_string_type, m.name, m.name.len, m.type->type_id, m.offset);
|
gen("{.name = (%Q){(uint8_t *)\"%Q\", %d}, .type = %d, .offset = %d}, ", prefixed_string_type, m.name, m.name.len, m.type->type_id, m.offset);
|
||||||
}
|
}
|
||||||
gen("}");
|
gen("}");
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ CORE_Static void
|
|||||||
parse_all_modules() {
|
parse_all_modules() {
|
||||||
pctx->time.parsing = os_time();
|
pctx->time.parsing = os_time();
|
||||||
|
|
||||||
For_Named(pctx->modules, module) {
|
For2(pctx->modules, module) {
|
||||||
if (module->state != MODULE_REGISTERED)
|
if (module->state != MODULE_REGISTERED)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -287,8 +287,8 @@ resolve_everything_in_module(Ast_Module *module) {
|
|||||||
if (module->state == MODULE_RESOLVED)
|
if (module->state == MODULE_RESOLVED)
|
||||||
return;
|
return;
|
||||||
pctx->time.typechecking = os_time();
|
pctx->time.typechecking = os_time();
|
||||||
For_Named(module->all_loaded_files, file) {
|
For2(module->all_loaded_files, file) {
|
||||||
For_Named(file->decls, decl) {
|
For2(file->decls, decl) {
|
||||||
if (decl->flags & AST_POLYMORPH) continue;
|
if (decl->flags & AST_POLYMORPH) continue;
|
||||||
|
|
||||||
// @cleanup: Why I'm not calling resolve_decl here?
|
// @cleanup: Why I'm not calling resolve_decl here?
|
||||||
|
|||||||
@@ -461,7 +461,7 @@ inside_scope_search(Scope_Search *search, Ast_Scope *scope, int level) {
|
|||||||
scope->visit_id = search->scope_visit_id;
|
scope->visit_id = search->scope_visit_id;
|
||||||
|
|
||||||
// Search for declarations in current scope
|
// Search for declarations in current scope
|
||||||
For_Named(scope->decls, decl) {
|
For2(scope->decls, decl) {
|
||||||
if (decl->name == search->name) {
|
if (decl->name == search->name) {
|
||||||
search->results.add(decl);
|
search->results.add(decl);
|
||||||
if (search->exit_on_find) {
|
if (search->exit_on_find) {
|
||||||
@@ -488,7 +488,7 @@ CORE_Static void
|
|||||||
scope_search(Scope_Search *search) {
|
scope_search(Scope_Search *search) {
|
||||||
// Climb the scope tree and search each scope in module and also
|
// Climb the scope tree and search each scope in module and also
|
||||||
// search in implicitly imported scopes
|
// search in implicitly imported scopes
|
||||||
For_Named(search->scopes, scope) {
|
For2(search->scopes, scope) {
|
||||||
for (Ast_Scope *it = scope; it; it = it->parent_scope) {
|
for (Ast_Scope *it = scope; it; it = it->parent_scope) {
|
||||||
inside_scope_search(search, it, 0);
|
inside_scope_search(search, it, 0);
|
||||||
|
|
||||||
@@ -844,7 +844,7 @@ resolve_stmt(Ast *ast, Ast_Type *ret) {
|
|||||||
resolve_stmt(it->init, ret);
|
resolve_stmt(it->init, ret);
|
||||||
resolve_and_require_bool("Conditional in a if condition", it->expr, AST_CAN_BE_NULL);
|
resolve_and_require_bool("Conditional in a if condition", it->expr, AST_CAN_BE_NULL);
|
||||||
try_propagating_resolved_type_to_untyped_literals(it->expr, pctx->type_bool);
|
try_propagating_resolved_type_to_untyped_literals(it->expr, pctx->type_bool);
|
||||||
For_Named(it->scope->stmts, jt)
|
For2(it->scope->stmts, jt)
|
||||||
resolve_stmt(jt, ret);
|
resolve_stmt(jt, ret);
|
||||||
}
|
}
|
||||||
BREAK();
|
BREAK();
|
||||||
@@ -858,18 +858,18 @@ resolve_stmt(Ast *ast, Ast_Type *ret) {
|
|||||||
try_converting_untyped_to_default_type(&base.value);
|
try_converting_untyped_to_default_type(&base.value);
|
||||||
try_propagating_resolved_type_to_untyped_literals(node->value, base.type);
|
try_propagating_resolved_type_to_untyped_literals(node->value, base.type);
|
||||||
For(node->cases) {
|
For(node->cases) {
|
||||||
For_Named(it->labels, label) {
|
For2(it->labels, label) {
|
||||||
Operand op = resolve_expr(label, AST_CANT_BE_NULL, 0, 0);
|
Operand op = resolve_expr(label, AST_CANT_BE_NULL, 0, 0);
|
||||||
if (!op.is_const) compiler_error(label->pos, "Switch label required to be constant");
|
if (!op.is_const) compiler_error(label->pos, "Switch label required to be constant");
|
||||||
make_sure_value_is_compatible_with_type(label->pos, &op, base.type, TYPE_AND_EXPR_REQUIRED);
|
make_sure_value_is_compatible_with_type(label->pos, &op, base.type, TYPE_AND_EXPR_REQUIRED);
|
||||||
try_propagating_resolved_type_to_untyped_literals(label, base.type);
|
try_propagating_resolved_type_to_untyped_literals(label, base.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
For_Named(it->scope->stmts, stmt)
|
For2(it->scope->stmts, stmt)
|
||||||
resolve_stmt(stmt, ret);
|
resolve_stmt(stmt, ret);
|
||||||
}
|
}
|
||||||
if (node->default_scope)
|
if (node->default_scope)
|
||||||
For_Named(node->default_scope->stmts, stmt)
|
For2(node->default_scope->stmts, stmt)
|
||||||
resolve_stmt(stmt, ret);
|
resolve_stmt(stmt, ret);
|
||||||
|
|
||||||
BREAK();
|
BREAK();
|
||||||
@@ -1066,7 +1066,7 @@ resolve_compound_struct(Ast_Call *node, Ast_Type *type) {
|
|||||||
|
|
||||||
Ast_Type *item_type = 0;
|
Ast_Type *item_type = 0;
|
||||||
if (is_flag_set(it->call_flags, CALL_NAME)) {
|
if (is_flag_set(it->call_flags, CALL_NAME)) {
|
||||||
For_Named(type->agg.members, m) {
|
For2(type->agg.members, m) {
|
||||||
if (it->name->intern_val == m.name) {
|
if (it->name->intern_val == m.name) {
|
||||||
it->resolved_name = m.name;
|
it->resolved_name = m.name;
|
||||||
it->resolved_index = (S32)type->agg.members.get_index(m);
|
it->resolved_index = (S32)type->agg.members.get_index(m);
|
||||||
@@ -1646,7 +1646,7 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str
|
|||||||
// every time.
|
// every time.
|
||||||
// Might be wise to revise it later but the approach of starting with
|
// Might be wise to revise it later but the approach of starting with
|
||||||
// lambda_args seems correct.
|
// lambda_args seems correct.
|
||||||
For_Named(lambda->args, lambda_arg) {
|
For2(lambda->args, lambda_arg) {
|
||||||
// assert(lambda_arg->type); // @todo: maybe add this check at the end
|
// assert(lambda_arg->type); // @todo: maybe add this check at the end
|
||||||
|
|
||||||
Ast_Call_Item *item = 0;
|
Ast_Call_Item *item = 0;
|
||||||
@@ -1682,9 +1682,9 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we found every item.
|
// Make sure we found every item.
|
||||||
For_Named(node->exprs, call_it) {
|
For2(node->exprs, call_it) {
|
||||||
bool included = false;
|
bool included = false;
|
||||||
For_Named(matches, match_it) {
|
For2(matches, match_it) {
|
||||||
if (call_it == match_it.call_arg) {
|
if (call_it == match_it.call_arg) {
|
||||||
included = true;
|
included = true;
|
||||||
break;
|
break;
|
||||||
@@ -1712,8 +1712,8 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str
|
|||||||
|
|
||||||
// We now need to fix the matches list CAUSE ITS FUCKED
|
// We now need to fix the matches list CAUSE ITS FUCKED
|
||||||
// Thanks polymorphism
|
// Thanks polymorphism
|
||||||
For_Named(matches, match_it) {
|
For2(matches, match_it) {
|
||||||
For_Named(lambda->args, lambda_it) {
|
For2(lambda->args, lambda_it) {
|
||||||
if (match_it.lambda_arg->name == lambda_it->name) {
|
if (match_it.lambda_arg->name == lambda_it->name) {
|
||||||
match_it.lambda_arg = lambda_it;
|
match_it.lambda_arg = lambda_it;
|
||||||
break;
|
break;
|
||||||
@@ -1859,7 +1859,7 @@ resolve_decl(Ast_Decl *ast) {
|
|||||||
node->type_val = type_enum(node, type_of_enum);
|
node->type_val = type_enum(node, type_of_enum);
|
||||||
|
|
||||||
S64 value = 1;
|
S64 value = 1;
|
||||||
For_Named(node->scope->decls, decl) {
|
For2(node->scope->decls, decl) {
|
||||||
Operand op = {};
|
Operand op = {};
|
||||||
if (decl->expr) {
|
if (decl->expr) {
|
||||||
op = require_const_int(decl->expr, AST_CANT_BE_NULL);
|
op = require_const_int(decl->expr, AST_CANT_BE_NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user