diff --git a/test/ffi/ffiTest.c b/test/ffi/ffiTest.c index f6b7b3c2..6ad08611 100644 --- a/test/ffi/ffiTest.c +++ b/test/ffi/ffiTest.c @@ -228,6 +228,25 @@ void incMany(S2* list, uint64_t count) { } } +typedef struct { + uint32_t* arr; + uint64_t sz; +} U32Arr; + +uint32_t arrayOp(U32Arr a) { + uint32_t r = 0; + for (uint64_t i = 0; i < a.sz; i++) { + r+= a.arr[i]; + a.arr[i]++; + } + return r; +} +uint32_t arrayRefOp(U32Arr* a) { + uint32_t res = arrayOp(*a); + a->arr++; + return res; +} + int plusone(int x) { return x + 1; } diff --git a/test/ffi/test.bqn b/test/ffi/test.bqn index 809eb389..4a139d68 100644 --- a/test/ffi/test.bqn +++ b/test/ffi/test.bqn @@ -78,6 +78,12 @@ f ↩ "lib.so" •FFI ⟨"i16", "thirdMember", ">"∾s1⟩ ⋄ •Show F ⟨200, f ↩ "lib.so" •FFI ⟨s1, "incMembers", ">"∾s1⟩ ⋄ •Show F ⟨200, 2e9, ¯30000, 1‿2‿3‿4, 3.25⟩ f ↩ "lib.so" •FFI ⟨"&", "incMany", "&"∾s2, "u64"⟩ ⋄ •Show¨ F ⟨0‿3‿6+3⥊<0‿1+2⥊<⟨200, 2e9, ¯30000, 1‿2‿3‿4, 3.25⟩, 3⟩ +{ + calloc ← @•FFI"*:i32"‿"calloc"‿"u64"‿"u64" ⋄ mem ← Calloc 3‿4 + f ← "lib.so" •FFI "i32"‿"arrayRefOp"‿">&{*:i32,u64}" + {𝕊: ⟨sum, ⟨arr‿sz⟩⟩ ← F ⟨mem‿3⟩ ⋄ •Show sum ∾ arr-mem}¨ ↕2 +} + Section "# self-ffi" •term.Flush@ f ↩ @ •FFI ⟨"i32", "putchar", ">i32"⟩ ⋄ F¨ 10∾˜"text"-@ diff --git a/test/ffi/test.expected b/test/ffi/test.expected index 9324593c..815949a5 100644 --- a/test/ffi/test.expected +++ b/test/ffi/test.expected @@ -109,6 +109,8 @@ ff7fdfefefdf7bb4 ff7fdfefefdf7bb4 fefffdfff7ffbffb bffff7fffdfffeff ┌─ · ⟨ 207 2000000007 ¯29993 ⟨ 8 8 9 10 ⟩ 10.25 ⟩ ⟨ 209 2000000009 ¯29991 ⟨ 10 9 10 11 ⟩ 12.25 ⟩ ┘ +⟨ 0 4 0 ⟩ +⟨ 3 4 0 ⟩ # self-ffi text