mlton
mlton copied to clipboard
Conversion of ref/array/vector types to generic pointer for FFI
On Fri, 11 Apr 2014, John Reppy wrote:
I've been working on a new version of the SML3d library (based on the programmable core profile) and there is a feature that would greatly reduce the size of the C/ML interface. For a C function like
void glDrawElements (GLenum, GLsizei, GLenum, void *);
I generate multiple wrappers where the fourth parameter type is specialized to various different array and vector types:
val glDrawElements = _import "glDrawElements" stdcall : (glenum * glsizei * glenum * MLton.Pointer.t) -> unit;
val glDrawElementsArrub = _import "glDrawElements" stdcall : (glenum * glsizei * glenum * Word8.word array) -> unit;
val glDrawElementsArrui = _import "glDrawElements" stdcall : (glenum * glsizei * glenum * Word32.word array) -> unit;
val glDrawElementsArrus = _import "glDrawElements" stdcall : (glenum * glsizei * glenum * Word16.word array) -> unit;
val glDrawElementsVecub = _import "glDrawElements" stdcall : (glenum * glsizei * glenum * Word8.word vector) -> unit;
val glDrawElementsVecui = _import "glDrawElements" stdcall : (glenum * glsizei * glenum * Word32.word vector) -> unit;
val glDrawElementsVecus = _import "glDrawElements" stdcall : (glenum * glsizei * glenum * Word16.word vector) -> unit;
What I would like are functions in Unsafe.Vector
and Unsafe.Array
to cast vector and array types to pointers.
val toPtr : 'a Vector.vector -> MLton.Pointer.t
val toPtr : 'a Array.array -> MLtonPointer.t
For completeness, it would be good to have these on the monomorphic vector and array types too.
And I very want it!