[MLton] more FFI revisions

Matthew Fluet fluet@cs.cornell.edu
Sat, 6 Aug 2005 09:33:32 -0400 (EDT)


I think we are honing in on a satisfactory treatment of FFI.

Here is current implementation, the result of a recent commit, adding 
_address and "alloc":

(* Current *)
  _address "symbol" : ptrTy;  ==>  ptrTy
  _import "symbol" [cdecl | stdcall] : cfTy;  ==>  cfTy
  _import "symbol" : cbTy;  ==>  cbTy;  (* DEPRECATED *)
  _import * [cdecl | stdcall] : ptrTy -> cfTy;  ==>  ptrTy -> cfTy
  _export "symbol" [cdecl | stdcall] : cfTy;  ==> cfTy -> unit
  _symbol "symbol" [alloc] : ptrTy, cbTy;  ==> ptrTy * (unit -> cbTy) * (cbTy -> unit)
  _symbol * : ptrTy, cbTy;  ==> (ptrTy -> cbTy) * (ptrTy * cbTy -> unit)


I think everyone is pretty much in favor of dropping the address component 
of _symbol "symbol", so I'll shortly revise things to:

(* No address on _symbol *)
  _address "symbol" : ptrTy;  ==>  ptrTy
  _import "symbol" [cdecl | stdcall] : cfTy;  ==>  cfTy
  _import "symbol" : cbTy;  ==>  cbTy;  (* DEPRECATED *)
  _import * [cdecl | stdcall] : ptrTy -> cfTy;  ==>  ptrTy -> cfTy
  _export "symbol" [cdecl | stdcall] : cfTy;  ==> cfTy -> unit
  _symbol "symbol" [alloc] : cbTy;  ==> (unit -> cbTy) * (cbTy -> unit)
  _symbol * : ptrTy, cbTy;  ==> (ptrTy -> cbTy) * (ptrTy * cbTy -> unit)


Looking at that, I think we ought to unify the treatment of the "*" forms.
Here is one proposal, which I think has the nice property that applying a 
"*" form to a pointer yields precisely the type of the corresponding 
"non-*" form:

(* A more uniform treatment of "*" forms? *)
  _address "symbol" : ptrTy;  ==>  ptrTy
  _import "symbol" [cdecl | stdcall] : cfTy;  ==>  cfTy
  _import "symbol" : cbTy;  ==>  cbTy;  (* DEPRECATED *)
  _import * [cdecl | stdcall] : ptrTy, cfTy;  ==>  ptrTy -> cfTy
  _export "symbol" [cdecl | stdcall] : cfTy;  ==> cfTy -> unit
  _symbol "symbol" [alloc] : cbTy;  ==> (unit -> cbTy) * (cbTy -> unit)
  _symbol * : ptrTy, cbTy;  ==> ptrTy -> (unit -> cbTy) * (cbTy -> unit)