[MLton] Shared libraries for MLton

Jens Axel Søgaard jensaxel@soegaard.net
Sun, 24 Jul 2005 03:31:03 +0200


This is a multi-part message in MIME format.
--------------070609030506020205080209
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi Stephen,

Attached is a patch that almost enables MLton to produce
shared libraries. The patch is agains the CVS version.
It was tested on Linux (I gave up on Cygwin and installed
Linux inside Vmware).

Here is a summary of the changes:

  - mlton/main/main.fun
     o Added new compiler option -shared-library
  - mlton/control/control-flags.sig/sml
     o added Control.sharedLibrary, which defaults to false
  - basis-library/mlton/mlton.sml
     o If the Control.sharedLibrary is true, then
       the program ends with a call to returnToC otherwise
       the program exits
     o NOTE:
         I couldn't figure how to import Control,
         so right now it says true in stead of !Control.sharedLibrary
  - include/c-main.h
     o Added init_function, which is called when a shared library is
       opened. It takes care of initializing the GC collector and
       global variables.
     o NOTE: main() isn't called, when the executable is opened
             as shared library
     o NOTE: The first garbage collection provokes a crash, the
             error is probably to be found here.


The directory test contains a small test. The files test.sml
contains some small test functions. The file test.c shows that
MLton can produce a shared library and that a functions can
be exported and called repeatedly until the first garbage
collection kicks in. The file test.ss shows how to open
the shared library from mzscheme.


/Jens Axel

--------------070609030506020205080209
Content-Type: application/x-gzip;
 name="shared-library-for-mlton.tar.gz"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="shared-library-for-mlton.tar.gz"

H4sIAArf4kIAA+1a+3PaSBLOr+Gv6HB1tRKFhHn6wSZVjhPnvEdsl3Fua2+TooQ0gDZCw85I
fmQv//t1z0iAeBjwebO3d+oqgyV1f90zPY9vWsiRI5hnBX5fOOLeGnBhjYOIh5VnTyd7KPvN
pvpGWfxW/1f3avt7zeZ+fX//2V612Wo2nkHzCWNYK7GMHAHwTHAePaS36fli4/4kItflf+JE
7khdZ1Ue4YP6o9VorMt/q9aa5b+213q2V6vVW/Vn8E068f88/54/GIAlQCXdcm9kpe9IX6bZ
rujBoD5tOQ4SPT0kHlYtH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