[MLton] bool and MLton FFI

skaller skaller@users.sourceforge.net
Sat, 24 Jun 2006 14:00:40 +1000


On Fri, 2006-06-23 at 11:01 -0400, Matthew Fluet wrote:
> >> I disagree here. We should start encouraging users to use _import
> >> like this:
> >> 	_import "foo" : C_Int.t * C_Long.t * Int32.t-> C_Bool.t
> >> for the function:
> >> 	extern bool foo(int x, long y, int32_t z);
> >> Otherwise their code won't be portable.
> >
> > This is naive. No realistic libraries provide functions like that.
> 
> Everything in the standard C and posix librarys are functions like that.

Many of the types are 'size_t', which is an alias.

Also binding the C standard library and much of Posix is irrelevant:
C because it provides no useful functionality, and Posix because
a hand crafted ML library will provide services much better.

Its the non-standardised libraries that are the real reason
you need an FFI.

> gl-types.x86-linux.sml:
> ------------------------------------------------------------
> structure GL_Int = C_Int
> ------------------------------------------------------------
> 
> gl-imports.sml:
> ------------------------------------------------------------
> val getStatus = _import "GLgetStatus": GL_Int.int -> GL_Int.int;
> ------------------------------------------------------------
> 
> gl-imports.mlb:
> ------------------------------------------------------------
> local
>    $(SML_LIB)/basis/c-types.mlb
> in
>    gl-types.$(TARGET_ARCH)-$(TARGET_OS).sml
>    gl-imports.sml
> end
> ------------------------------------------------------------
> 
> 
> This is precisely how we handle things like 'mode_t', 'uid_t', and 
> 'gid_t', which don't have a fixed size across platforms.

Yes, that's the kind of thing needed. Here you're emulating
conditional compilation by including something whose name
is generated.


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net