grin icon indicating copy to clipboard operation
grin copied to clipboard

Foreign pointer primitive type

Open Z-snails opened this issue 2 years ago • 5 comments

This is needed for various features of many functional languages, eg arbitrary precision integers and arrays implemented in FFI.

If there's only support for foreign pointers, that makes code-gen easier as the layout is consistent, however having structs would be useful, eg for interfacing with pass-by-value C libraries.

Z-snails avatar Jan 15 '22 19:01 Z-snails

What operations do you need?

csabahruska avatar Jan 15 '22 19:01 csabahruska

If there's only support for foreign pointers, that makes code-gen easier as the layout is consistent, however having structs would be useful, eg for interfacing with pass-by-value C libraries.

Idiomatic C never passes a struct by value in one of the arguments, only by pointer to avoid copies.

luc-tielen avatar Jan 16 '22 07:01 luc-tielen

@csabahruska Passing too and from FFI functions. My current use case is arbitrary precision integers in the idris2-grin backend.

@luc-tielen unfortunately not all C libraries are idiomatic.

Z-snails avatar Jan 16 '22 13:01 Z-snails

Would foreign pointers interact with the garbage collector?

csabahruska avatar Jan 16 '22 14:01 csabahruska

In the long term, yes (eg for IORef) however I don't think for Integer all that is needed is a static (as in known at runtime) finaliser function (which can also be grin which calls the ffi free function)

Z-snails avatar Jan 16 '22 15:01 Z-snails