Dynamic library issues...
Anoq of the Sun
anoq@HardcoreProcessing.com
Thu, 25 Jan 2001 04:03:55 +0100
"Stephen Weeks" wrote:
> > 1) Generate the library with MLton
> I think there's a fair amount of work in getting (1) to work in MLton. One
> problem is the whole program assumption. You would need some way of indicating
> to MLton which functions should be entry points in the library. Propagating and
> using this information in the compiler might require substantial modifications.
> If it is possible to view every invocation of the library as a complete run of
> the whole program, and the heap is not shared across applications, it doesn't
> seem insurmountable though.
Well, without heap-sharing it will give severe limititions I
think - if it were to be used for "interesting" real-life stuff :)
> As a really gross hack using the current compiler, you could write your own
> wrapper and Main macro in C to make the library. You could store the parameters
> to each routine in globals and set a flag indicating which routine should be
> called. You could then call the MLton main procedure, which would dispatch on
> the flag and access the parameters stored in globals via the FFI mechanism.
Sounds like one of the hacks I'm using in the SDL::ML bindings
(at least in the new version which is not released yet) :)
> > 2) Passing arbitrary data-structures as
> > function arguments.
> >
> Problem (2) is already present in MLton's FFI interface. My feeling is that it
> shouldn't be too hard to load dynamic libraries within MLton, provided that the
> routines being called have types that MLton's FFI can handle. Accessing or
> creating ML data structures from C code is not easy, and will not happen in the
> forseeable future.
I'm just wondering - I'm sure that MLton must be
able to generate some kind of function-call in it's
code (otherwise I guess it would be impossible to
compile non-tail recursive functions :)
What if that kind of functions are just
exported as it is - and the representation
of complex datastructures is just retained -
wouldn't it then be possible to create and
load libraries? I know it will only work
if both library and main program is written
with MLton, but even that would be very
interesting :)
It requires that the GC is shared between
libraries and main program in some way -
but that should hopefully be do-able...
But then it's still the problem of propagating
which functions should go into a library as
you say...
> > I have attached the Dynlib.sig from
> > MoscowML - so that you don't have to
> > search for it if you want to see it :)
>
> Something like this should be doable. In fact, if you have a particular case
> where you need just a few functions, you might be able to build it yourself
> using MLton's FFI mechanism.
I guess you're right :)
So, making the libraries would still be the
hardest part I guess...
Cheers
--
http://www.HardcoreProcessing.com