lib/scripts/run-polyml
author wenzelm
Thu Nov 13 23:45:15 2014 +0100 (2014-11-13)
changeset 58999 ed09ae4ea2d8
parent 56627 cb912b7de3cf
child 59344 e0ce214303c1
permissions -rwxr-xr-x
uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
discontinued obsolete 'txt_raw' (superseded by 'text_raw');
eliminated obsolete Outer_Syntax.markup (superseded by keyword kinds);
'text' and 'txt' no longer appear in Sidekick tree due to change of keyword kind;
changed tagging of diagnostic commands within proof;
     1 #!/usr/bin/env bash
     2 #
     3 # Author: Makarius
     4 #
     5 # Startup script for Poly/ML 5.1 ... 5.5.
     6 
     7 export -n INFILE OUTFILE MLTEXT TERMINATE NOWRITE
     8 
     9 
    10 ## diagnostics
    11 
    12 function fail()
    13 {
    14   echo "$1" >&2
    15   exit 2
    16 }
    17 
    18 function fail_out()
    19 {
    20   fail "Unable to create output heap file: \"$OUTFILE\""
    21 }
    22 
    23 function check_file()
    24 {
    25   [ ! -f "$1" ] && fail "Unable to locate \"$1\""
    26 }
    27 
    28 
    29 ## compiler executables and libraries
    30 
    31 [ -z "$ML_HOME" ] && fail "Missing ML installation (ML_HOME)"
    32 
    33 POLY="$ML_HOME/poly"
    34 check_file "$POLY"
    35 
    36 librarypath "$ML_HOME"
    37 
    38 
    39 
    40 ## prepare databases
    41 
    42 if [ -z "$INFILE" ]; then
    43   INIT=""
    44   EXIT="fun exit rc = Posix.Process.exit (Word8.fromInt rc);"
    45 else
    46   check_file "$INFILE"
    47   INIT="(Signal.signal (2, Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ())); PolyML.SaveState.loadState \"$INFILE\" handle exn => (TextIO.output (TextIO.stdErr, General.exnMessage exn ^ \": $INFILE\\n\"); Posix.Process.exit 0w1));"
    48   EXIT=""
    49 fi
    50 
    51 if [ -z "$OUTFILE" ]; then
    52   COMMIT='fun commit () = false;'
    53   MLEXIT=""
    54 else
    55   if [ -z "$INFILE" ]; then
    56     COMMIT="fun commit () = (PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.SaveState.saveState \"$OUTFILE\"; true) handle exn => (TextIO.output (TextIO.stdErr, General.exnMessage exn ^ \": $OUTFILE\\n\"); Posix.Process.exit 0w1);"
    57   else
    58     COMMIT="fun commit () = (ML_System.share_common_data (); ML_System.save_state \"$OUTFILE\");"
    59   fi
    60   [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
    61   MLEXIT="commit();"
    62 fi
    63 
    64 
    65 ## run it!
    66 
    67 MLTEXT="$INIT $EXIT $COMMIT $MLTEXT"
    68 
    69 if [ -z "$TERMINATE" ]; then
    70   FEEDER_OPTS=""
    71 else
    72   FEEDER_OPTS="-q"
    73 fi
    74 
    75 "$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
    76   { read FPID; "$POLY" -q $ML_OPTIONS; RC="$?"; kill -TERM "$FPID"; exit "$RC"; }
    77 RC="$?"
    78 
    79 [ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
    80 
    81 exit "$RC"
    82 
    83 #:wrap=soft:maxLineLen=100: