grin-compiler / grin

GRIN is a compiler back-end for lazy and strict functional languages with whole program optimization support.
https://grin-compiler.github.io/
1.03k stars 38 forks source link

Foreign pointer primitive type #131

Open Z-snails opened 2 years ago

Z-snails commented 2 years ago

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.

csabahruska commented 2 years ago

What operations do you need?

luc-tielen commented 2 years ago

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.

Z-snails commented 2 years ago

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

csabahruska commented 2 years ago

Would foreign pointers interact with the garbage collector?

Z-snails commented 2 years ago

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)