[MLton] Representation of strings in the FFI

Jens Axel Søgaard jensaxel@soegaard.net
Sun, 01 May 2005 13:43:43 +0200


Stephen Weeks wrote:
>>Since globals are treated as roots by the garbage collector,
>>I can use global reference cells to prevent the garbage
>>collector to free needed values.
> 
> Possibly.  You need to worry about MLton's optimizer being clever
> enough to notice that a ref cell's contents are unused and then
> removing the contents, or even the ref cell.

Ok - thanks for the warning.

>>The overall goal is to make it easy to use an MLton library for a
>>Scheme programmer knowing (almost) nothing about ML.
> 
> ...
> 
>>the Scheme-ML FFI should automatically convert Scheme values to ML
>>values, when a call to an ML functions is made, and the ML return
>>value should be converted to a Scheme value.
> 
> OK, although copying unbounded-size data structures seems like an
> costly approach.  Plus, there are issues with sharing and mutability.

Indeed - I hope I can find a way where I can keep track of the
ML arrays from within Scheme. It needs some kind of registering
mechanism on the ML side, so a) aren't garbage collected and
b) can be found, even though they are moved in a garbage collection.

The first step is to get something simple working, then I can improve
it later.

>>The conversion of return values from ML to Scheme turned out to be
>>easy.
> 
> ...
> 
>>The other way, converting Scheme values to ML values, is tricky due
>>to the garbage collector.
> 
> I don't think this entirely solves your problem, but perhaps it would
> help to expose Scheme's universal datatype to SML via some _import's
> and then convert a Scheme value to an ML value by making a single call
> to an _export'ed function, thus sidestepping the GC issue.  Of course,
> the ML code has to know all the possible types it might deal with.

Hm - I need to think about that.

-- 
Jens Axel Søgaard