[MLton-devel] Callbacks

Stephen Weeks MLton@mlton.org
Tue, 20 May 2003 09:13:02 -0700


> I guess; but one might well argue that there is just as much room for
> error on the ML side for importing C functions.  When I write
>   _ffi "foo" : unit -> unit;
> nothing complains when foo is really:
>   int foo(int x) { return x; }

Yes.  That is bad too and has been on my todo list to fix forever.  I
made some progress lately when I added the code to the C codegen to
emit the prototypes of all FFI's.  The problem is that MLton doesn't
know the real C types of the functions, e.g. we have

	Pointer Posix_FileSys_Dirstream_opendir (Pointer x0);

when the correct spec is

       DIR *opendir(const char *name);

So, I'm not sure how we should type check _ffi.

> > MLton also builds the appropriate C routine for each export, which is
> > easy to do from the type.  Our example would generate
> >
> > 	int A (int x1, int x1) {
> > 	        MLton_FFI_setI (0, 13);
> > 	        MLton_FFI_setI (1, x1);
> > 	        MLton_FFI_setI (2, x2);
> > 	        MLton_callFromC ();
> > 	        return MLton_FFI_getI (0);
> > 	}
> 
> This presumably get's dumped into some auxilary .c file that is compiled
> and linked into the .o for the SML?

Yeah, I was thinking to put it in the same file with Main.


-------------------------------------------------------
This SF.net email is sponsored by: ObjectStore.
If flattening out C++ or Java code to make your application fit in a
relational database is painful, don't do it! Check out ObjectStore.
Now part of Progress Software. http://www.objectstore.net/sourceforge
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel