From 25b8db28cf87708808744b97774c2a8427e129e2 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Thu, 26 Feb 2026 17:45:31 +0200 Subject: fix vec example + Compiler works fine, example was borked :) + Although, not a very good example I must admit, it bashes a hole into my nice memory analysis plan :( --- examples/vec.fwd | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'examples/vec.fwd') diff --git a/examples/vec.fwd b/examples/vec.fwd index 903c3e7..6950c2a 100644 --- a/examples/vec.fwd +++ b/examples/vec.fwd @@ -25,19 +25,21 @@ next_s_vec(u64 s, (u64) ok) reserve_vec(vec v, u64 c, (vec) ok) { v => [n => n, s => s, buf => buf]; - n + c => nn; /* expand if we run out of space */ - if nn > s { + if c > s { next_s_vec(s) => s; /* note that fwdrealloc creates a new closure, meaning that it * takes ownership of v.buf, so we can't back out and do a * single ok(v) at the end of the function */ fwdrealloc(buf, s * sizeof(i64)) => nbuf; - ok([nn => n, s => s, nbuf => buf] vec); + ok([c => n, s => s, nbuf => buf] vec); } else { - ok([nn => n, s => s, buf => buf] vec); + /* if this were a generic vector we'd have to worry about + * destroying the elements, but since we're just dealing with + * integers this is fine */ + ok([c => n, s => s, buf => buf] vec); } } @@ -142,7 +144,7 @@ check_vec(i64 i, i64 n, vec v, (vec) ok) main() { init_vec(0 as u64) => vec v; - populate_vec(0, 10, v) => vec v; - check_vec(0, 10, v) => vec v; + populate_vec(0, 1000000, v) => vec v; + check_vec(0, 1000000, v) => vec v; destroy_vec(v); } -- cgit v1.2.3