Fix? ordered_remove in loops

This commit is contained in:
Krzosa Karol
2023-04-01 20:56:34 +02:00
parent 2ce696b04b
commit 7a369d801a
4 changed files with 12 additions and 8 deletions

View File

@@ -117,7 +117,7 @@ struct Array {
return result; return result;
} }
void ordered_remove(T &item) { void ordered_remove(T &item) { // Dont use in loops !!!!
assert(len > 0); assert(len > 0);
assert(&item >= begin() && &item < end()); assert(&item >= begin() && &item < end());
int index = get_index(&item); int index = get_index(&item);

View File

@@ -354,9 +354,11 @@ Ast_Decl *get_or_instantiate_polymorph_lambda(Token *pos, Ast_Decl *poly, Array<
if (!result) { if (!result) {
result = (Ast_Decl *)ast_copy(poly, poly->parent_scope, &poly->polymorph_parameters, &params); result = (Ast_Decl *)ast_copy(poly, poly->parent_scope, &poly->polymorph_parameters, &params);
For(result->lambda->args) { for (int i = 0; i < result->lambda->args.len; i += 1) {
auto &it = result->lambda->args[i];
if (it->flags & AST_IDENT_POLYMORPH) { if (it->flags & AST_IDENT_POLYMORPH) {
result->lambda->args.ordered_remove(it); //@verify: this does not fuck ordereding result->lambda->args.ordered_remove(it);
i -= 1;
} }
} }

View File

@@ -1696,10 +1696,12 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str
// Find the polymorph // Find the polymorph
if (lambda->flags & AST_POLYMORPH) { if (lambda->flags & AST_POLYMORPH) {
Array<Ast_Call_Item *> replacements = {scratch.arena}; Array<Ast_Call_Item *> replacements = {scratch.arena};
For(matches) { for (int i = 0; i < matches.len; i += 1) {
Match &it = matches[i];
if (it.lambda_arg->flags & AST_POLYMORPH) { if (it.lambda_arg->flags & AST_POLYMORPH) {
replacements.add(it.call_arg); replacements.add(it.call_arg);
matches.ordered_remove(it); //@verify: this does not fuck ordereding matches.ordered_remove(it);
i -= 1;
} }
} }

View File

@@ -1,14 +1,14 @@
MA :: #import "Arena.core" MA :: #import "Arena.core"
PushStruct :: (a: *MA.Arena, $T: Type): *T PushStruct :: (a: *MA.Arena, $K: Type, $T: Type): *T
size := SizeOf(T) size := SizeOf(T)
result := MA.PushSize(a, size->U64) result := MA.PushSize(a, size->U64)
return result->*T return result->*T
main :: (argc: int, argv: **char): int main :: (argc: int, argv: **char): int
arena: MA.Arena arena: MA.Arena
a: *int = PushStruct(&arena, int) a: *int = PushStruct(&arena, int, int)
b: *F32 = PushStruct(&arena, F32) b: *F32 = PushStruct(&arena, int, F32)
padding := SizeOf(int) padding := SizeOf(int)
Assert(arena.len->S64 == (SizeOf(int) + SizeOf(F32) + padding)) Assert(arena.len->S64 == (SizeOf(int) + SizeOf(F32) + padding))