FFI test for mutating a pointer within struct

This commit is contained in:
dzaima 2022-10-08 19:21:42 +03:00
parent 7e1c9b50cd
commit 86fa4a066e
3 changed files with 27 additions and 0 deletions

View File

@ -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;
}

View File

@ -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, 1234, 3.25
f "lib.so" •FFI "&", "incMany", "&"s2, "u64" •Show¨ F 036+3<01+2<200, 2e9, ¯30000, 1234, 3.25, 3
{
calloc @•FFI"*:i32""calloc""u64""u64" mem Calloc 34
f "lib.so" •FFI "i32""arrayRefOp"">&{*:i32,u64}"
{𝕊: sum, arrsz F mem3 •Show sum arr-mem}¨ 2
}
Section "# self-ffi"
•term.Flush@
f @ •FFI "i32", "putchar", ">i32" F¨ 10˜"text"-@

View File

@ -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