koka-lang / koka

Koka language compiler and interpreter
http://koka-lang.org
Other
3.16k stars 151 forks source link

Support external managed memory #494

Open TimWhiting opened 2 months ago

TimWhiting commented 2 months ago

I've been thinking a bit about automated generation of C wrappers (along the lines of a port of Dart's ffigen), but of course first we need a way of managing external ffi resources in Koka. After searching in kklib for a bit, I found the kk_cptr* functions which don't currently have a corresponding Koka api. Here is an initial Koka api for these functions, allowing us to manage allocated C memory completely from Koka.

TimWhiting commented 1 month ago

Marking this as draft: I've since made some updates here, which I need to migrate back to this PR: https://github.com/koka-community/std/blob/main/std/cextern.kk

TimWhiting commented 1 month ago

By the way, I have a version of the libuv branch, which uses this api, and automatically generated ffi bindings (adapted from dart's ffigen). This allows us to write almost all of the external binding code in koka.