[MLton] Exporting closures to C code

Matthew Fluet fluet@cs.cornell.edu
Tue, 27 Sep 2005 07:24:18 -0400 (EDT)


> However, the MLton side of it is largely irrelevant
> as you will see in a minute.

It is not totally irrelevant, on at least two points.
First, having more support in a language means that you need less tool 
support and less 'stubs' in C to mediate.  I think this was Florian's 
original concern.
Second, I don't consider the ability to dynamically construct a closure 
via a 'language API' (a weird concept) to be a prerequisite for a 
language; in particular, you can't do this in MLton.  Closures arise 
naturally in the dynamic evaluation of an SML program, but you can't 
construct them in C.

You have an interesting design, but I think it is a bit overkill for 
Florian's original question.  You can accomplish his goals by registering 
a single ML _export for all instances of an object with a callback, 
maintaining a mapping from object instances to ML closures, and _export 
the function that dynamically finds and runs the appropriate closure from 
the object identity of the callback.

This has the same GC issue, that you can't delete the ML closures from the 
mapping automatically, since you may not know when the C object will no 
longer invoke it's callback.