add ffi:{allocate,read_ptr,deallocate}

This commit is contained in:
Skgland
2025-08-09 02:14:02 +02:00
committed by Bennet Bleßmann
parent 35d34231f2
commit 20d52c093a
9 changed files with 539 additions and 86 deletions

View File

@@ -73,6 +73,23 @@ use_foreign_module(LibName, Predicates) :-
'$load_foreign_lib'(LibName, Predicates),
maplist(assert_predicate, Predicates).
allocate(Allocator, Type, Args, Ptr) :-
must_be(var, Ptr),
must_be(atom, Type),
must_be(atom, Allocator),
'$ffi_allocate'(Allocator, Type, Args, Ptr).
read_ptr(Type, Ptr, Value) :-
must_be(var, Value),
must_be(atom, Type),
must_be(integer, Ptr),
'$ffi_read_ptr'(Type, Ptr, Value).
deallocate(Allocator, Type, Ptr) :-
must_be(atom, Allocator),
must_be(integer, Ptr),
'$ffi_deallocate'(Allocator, Type, Ptr).
assert_predicate(PredicateDefinition) :-
PredicateDefinition =.. [Name, Inputs, void],
length(Inputs, NumInputs),