[MLton] ffi improvements

Matthew Fluet fluet@cs.cornell.edu
Thu, 16 Sep 2004 22:04:07 -0400 (EDT)


Looking through some of the FFI stuff, here are some items of note:

1) The CType structure (in the compiler) distinguishes between Pointer and
   Word32.  However, MLton.Pointer.t (in the basis), while abstract, is
   defined to be equal to word.  I think it might be cleaner to have a
   primitive pointer tycon.

2) I don't see that the thread/preThread distinction is really used within
   the compiler.  In light of the above, I suggest dropping the
   thread and preThread tycons and in the basis define:
     structure Thread :> sig type t end = struct type t = pointer end
     structure PreThread :> sig type t end = struct type t = pointer end
   which will keep threads and preThreads distinct in the Basis.

3) I've implemented indirect C calls.  However, I'm not sure which is a
   better syntax:

     _import * : MLton.Pointer.t * t1 * ... * tn -> tr;

     _import var : t1 * ... * tn -> tr;

   I like the second version because the user writes down exactly the type
   of the C function they wish to call (as in a direct _import).  On the
   other hand, it breaks the syntax of other _xyz extensions.  The second
   version also requires unifying the var with some type; unfortunately,
   the MLton.Pointer.t type isn't available from within the compiler.  So
   we could unify with word (or, preferably, with pointer from #1).  The
   advantage of the first version is that the _import type parsing can
   peek through an abstraction, so one can use an abstract type in the
   function pointer position, so long as it's CType is Word32 (again, it
   would be better to make it CType.Pointer, but only thread and preThread
   map to Pointer).


BTW, I'm not pushing to get these changes in before the release; just
thought I would put them down while they are on my mind.