diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2026-02-26 01:19:56 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2026-02-26 01:19:56 +0200 |
| commit | e36f35d0ee1132a8aa998891ca333ff0c4ed64c2 (patch) | |
| tree | 4659fe55698fd2aac309bda3bf6ba2a0ee4046f9 | |
| parent | bdb66a2de5cd1e6c192f7342b9d0b3349d8c9c6a (diff) | |
| download | fwd-e36f35d0ee1132a8aa998891ca333ff0c4ed64c2.tar.gz fwd-e36f35d0ee1132a8aa998891ca333ff0c4ed64c2.zip | |
example/vec fixes
+ Doesn't quite work yet, but compiles fine. Some issues were in the
example itself, heh
| -rw-r--r-- | examples/vec.fwd | 23 | ||||
| -rw-r--r-- | include/fwd/mod.h | 8 |
2 files changed, 20 insertions, 11 deletions
diff --git a/examples/vec.fwd b/examples/vec.fwd index 22049e0..bd88091 100644 --- a/examples/vec.fwd +++ b/examples/vec.fwd @@ -44,11 +44,12 @@ reserve_vec(vec v, u64 c, (vec) ok) set_vec(vec v, i64 i, i64 e, (vec) ok) { v => [n => n, s => s, buf => buf]; - buf + (n - 1 as u64) => nbuf; + /* oh wait, this is dumb, of course nbuf will never be null */ + buf + i => nbuf; nil nbuf { nil nbuf; fwdfree(buf); - fwdpanic("should never happen"); + fwdpanic("set_vec, should never happen\n"); } => dst; /* perform actual store */ @@ -68,7 +69,7 @@ append_vec(vec v, i64 e, (vec) ok) { n_vec(v) => v, n; reserve_vec(v, n + 1 as u64) => v; - set_vec(v, n as i64 - 1, e) => v; + set_vec(v, n as i64, e) => v; ok(v); } @@ -77,14 +78,14 @@ at_vec(vec v, u64 i, (vec, &i64) ok) v => [n => n, s => s, buf => buf]; guard(i < n) => { fwdfree(buf); - fwdpanic("bounds error"); + fwdpanic("at_vec, bounds error\n"); } => ; buf + i => *i64 nbuf; nil nbuf { nil nbuf; fwdfree(buf); - fwdpanic("should never happen"); + fwdpanic("at_vec, should never happen\n"); } => &i64 bufr; nil nbuf; @@ -112,9 +113,9 @@ populate_vec(i64 i, i64 n, vec v, (vec) ok) guard(bool c, () err | () ok) { if c { - err(); - } else { ok(); + } else { + err(); } } @@ -123,9 +124,9 @@ check_vec(i64 i, i64 n, vec v, (vec) ok) if i < n { at_vec(v, i as u64) => v, elem; - guard(elem* != i) => { + guard(elem* == i) => { destroy_vec(v); - fwdpanic("vec built wrong"); + fwdpanic("check_vec, vec built wrong\n"); } => ; check_vec(i + 1, n, v, ok); @@ -137,7 +138,7 @@ check_vec(i64 i, i64 n, vec v, (vec) ok) main() { init_vec(0 as u64) => vec v; - populate_vec(0, 1000000, v) => vec v; - check_vec(0, 1000000, v) => vec v; + populate_vec(0, 10, v) => vec v; + check_vec(0, 10, v) => vec v; destroy_vec(v); } diff --git a/include/fwd/mod.h b/include/fwd/mod.h index c77e76c..ef0448e 100644 --- a/include/fwd/mod.h +++ b/include/fwd/mod.h @@ -57,7 +57,15 @@ static inline void *fwd_arg(fwd_extern_args_t args, size_t idx, fwd_type_t id) assert(idx < args.argc); assert(args.args[idx + 1].t == id); switch (id) { + case FWD_I8: return &args.args[idx + 1].i8; + case FWD_I16: return &args.args[idx + 1].i16; + case FWD_I32: return &args.args[idx + 1].i32; case FWD_I64: return &args.args[idx + 1].i64; + case FWD_U8: return &args.args[idx + 1].u8; + case FWD_U16: return &args.args[idx + 1].u16; + case FWD_U32: return &args.args[idx + 1].u32; + case FWD_U64: return &args.args[idx + 1].u64; + case FWD_PTR: return &args.args[idx + 1].p; default: abort(); } |
