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
On 30/8/17, 22:33, "David Matthews" <David.Matthews at prolingua.co.uk> wrote:
How exactly are you saving the state you want to load? The problem is that you can only load a saved state into the same executable as you used to save it. The ultimate reason for this restriction is that the saved state does not save any heap cells that are present in the executable but instead saves their (relative) addresses. loadState will raise an exception if the saved state does not match the executable.
By "silently crash" do you mean that it raises an exception that you are not handling or is this something else?
David
On 30/08/2017 13:10, Michael.Norrish at data61.csiro.au wrote: > If I have a program I?d like to compile with polyc that looks like > > > fun main () = > let > val _ = PolyML.SaveState.loadState (hd (CommandLine.arguments())) > in > ? > end > > what, if anything can I put in the ? and have it work? > > All I really want is what is effectively a sequence of calls to ?use? in that slot, but there seem to be many ways of generating executables that silently crash. > > Michael > > _______________________________________________ > polyml mailing list > polyml at inf.ed.ac.uk > http://lists.inf.ed.ac.uk/mailman/listinfo/polyml >