[MLton] Re: MLton and shared libraries

Stephen Weeks MLton@mlton.org
Sat, 16 Apr 2005 10:30:46 -0700


>    val _ =  (Primitive.TopLevel.setHandler MLtonExn.topLevelHandler
>               ; Primitive.TopLevel.setSuffix
>                    (if Control.isSharedLibrary
>                     then   (fn () => 0)
>                     else   (fn () => MLtonProcess.exit MLtonProcess.Status.success)))
>    end
> 
> ?

I was thinking

  fn () => if Primitive.isSharedLibrary
             then Primitive.Thread.returnToC ()
           else MLtonProcess.exit MLtonProcess.Status.success

* I used Primitive.isSharedLibrary rather than Control.isSharedLibrary
  because Primitive is for holding such controls in the basis library,
  while Control is for holding such stuff in the compiler.

* I called returnToC, because falling off the end of the program
  without doing anything will cause a segfault, as the return will
  have nothing to return to.

* There's no need to duplicate the "fn () =>", as the if test will be
  simplified at compile time.  (just a style issue)