A program compiled with polyc exits if there is an uncaught exception. In this case PolyML.SaveState.loadState is raising an exception. Adding a handler such as
    PolyML.SaveState.loadState s
       handle exn => (print(exnMessage exn); raise exn);
produces a message similar to:
Fail "Saved state was exported from a different executable or the executable has changed"

It would be nice to be able to import a saved state into a different executable but it would only be possible if the saved state had no pointers to data in the exporting executable.

David

On 31/08/2017 00:32, michael.norr...@data61.csiro.au wrote:
The state is being saved from “bare” poly, and being reloaded into the same 
environment (no complicated chains of states in my example).  “Silently crash” 
means exits without any output, even though the … section of my code includes 
calls to print.

Here is a simple example:

First:

     $ echo "val x = ref 10; PolyML.SaveState.saveState \"foo\";" | poly

generating my state file “foo”.

Then I write bar.ML:

````
fun die s = (TextIO.output(TextIO.stdErr, s ^ "\n");
              OS.Process.exit OS.Process.failure)

fun write_to_file f =
   let
     val ostrm = TextIO.openOut f
   in
     TextIO.output(ostrm, "(* this is a file *)\n");
     TextIO.closeOut ostrm
   end

fun main() =
   let
     val (s,file) = case CommandLine.arguments() of
                        [s,file] => (s,file)
                      | _ => die ("Usage:\n  "^CommandLine.name() ^
                                  " state file")
   in
     PolyML.SaveState.loadState s;
     print "Switched state successfully\n";
     write_to_file file;
     PolyML.use file
   end
````

Then I compile with polyc:

    $ polyc bar.ML

Then I try running a.out

    $ ./a.out foo usefile

I get no output, an exit code of 1 and usefile hasn’t been created.

This is on macos (uname says “Darwin Kernel Version 16.7.0”), and with Poly/ML 
5.6 Release.

Michael
_______________________________________________
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml

Reply via email to