lib/scripts/run-polyml-5.6
changeset 61715 5dc95d957569
parent 61294 2d3d26e9b191
child 62386 10e55e168672
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/scripts/run-polyml-5.6	Fri Nov 20 21:52:05 2015 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +#!/usr/bin/env bash
     1.5 +# :mode=shellscript:
     1.6 +#
     1.7 +# Author: Makarius
     1.8 +#
     1.9 +# Startup script for Poly/ML 5.6.
    1.10 +
    1.11 +export -n INFILE OUTFILE MLTEXT TERMINATE NOWRITE
    1.12 +
    1.13 +
    1.14 +## diagnostics
    1.15 +
    1.16 +function fail()
    1.17 +{
    1.18 +  echo "$1" >&2
    1.19 +  exit 2
    1.20 +}
    1.21 +
    1.22 +function fail_out()
    1.23 +{
    1.24 +  fail "Unable to create output heap file: \"$OUTFILE\""
    1.25 +}
    1.26 +
    1.27 +function check_file()
    1.28 +{
    1.29 +  [ ! -f "$1" ] && fail "Unable to locate \"$1\""
    1.30 +}
    1.31 +
    1.32 +
    1.33 +## compiler executables and libraries
    1.34 +
    1.35 +[ -z "$ML_HOME" ] && fail "Missing ML installation (ML_HOME)"
    1.36 +
    1.37 +POLY="$ML_HOME/poly"
    1.38 +check_file "$POLY"
    1.39 +
    1.40 +librarypath "$ML_HOME"
    1.41 +
    1.42 +
    1.43 +
    1.44 +## prepare databases
    1.45 +
    1.46 +case "$ML_PLATFORM" in
    1.47 +  *-windows)
    1.48 +    PLATFORM_INFILE="$(platform_path -m "$INFILE")"
    1.49 +    PLATFORM_OUTFILE="$(platform_path -m "$OUTFILE")"
    1.50 +    ;;
    1.51 +  *)
    1.52 +    PLATFORM_INFILE="$INFILE"
    1.53 +    PLATFORM_OUTFILE="$OUTFILE"
    1.54 +    ;;
    1.55 +esac
    1.56 +
    1.57 +if [ -z "$INFILE" ]; then
    1.58 +  INIT=""
    1.59 +  case "$ML_PLATFORM" in
    1.60 +    *-windows)
    1.61 +      EXIT="fun exit 0 = OS.Process.exit OS.Process.success | exit 1 = OS.Process.exit OS.Process.failure | exit rc = OS.Process.exit (RunCall.unsafeCast (Word8.fromInt rc));"
    1.62 +      ;;
    1.63 +    *)
    1.64 +      EXIT="fun exit rc = Posix.Process.exit (Word8.fromInt rc);"
    1.65 +      ;;
    1.66 +  esac
    1.67 +else
    1.68 +  check_file "$INFILE"
    1.69 +  INIT="(Signal.signal (2, Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ())); PolyML.SaveState.loadState \"$PLATFORM_INFILE\" handle exn => (TextIO.output (TextIO.stdErr, General.exnMessage exn ^ \": $INFILE\\n\"); OS.Process.exit OS.Process.success));"
    1.70 +  EXIT=""
    1.71 +fi
    1.72 +
    1.73 +if [ -z "$OUTFILE" ]; then
    1.74 +  MLEXIT=""
    1.75 +else
    1.76 +  if [ -z "$INFILE" ]; then
    1.77 +    MLEXIT="(PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.SaveState.saveState \"$PLATFORM_OUTFILE\"; true) handle exn => (TextIO.output (TextIO.stdErr, General.exnMessage exn ^ \": $OUTFILE\\n\"); OS.Process.exit OS.Process.success);"
    1.78 +  else
    1.79 +    MLEXIT="Session.save \"$OUTFILE\";"
    1.80 +  fi
    1.81 +  [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
    1.82 +fi
    1.83 +
    1.84 +
    1.85 +## run it!
    1.86 +
    1.87 +MLTEXT="$INIT $EXIT $MLTEXT"
    1.88 +
    1.89 +if [ -n "$TERMINATE" -a -z "$MLEXIT" ]; then
    1.90 +  "$POLY" -q -i $ML_OPTIONS --eval "$(perl "$ISABELLE_HOME/lib/scripts/recode.pl" "$MLTEXT")" \
    1.91 +    --error-exit </dev/null
    1.92 +  RC="$?"
    1.93 +else
    1.94 +  if [ -z "$TERMINATE" ]; then
    1.95 +    FEEDER_OPTS=""
    1.96 +  else
    1.97 +    FEEDER_OPTS="-q"
    1.98 +    ML_OPTIONS="$ML_OPTIONS --error-exit"
    1.99 +  fi
   1.100 +  "$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
   1.101 +    { read FPID; "$POLY" -q -i $ML_OPTIONS; RC="$?"; kill -TERM "$FPID"; exit "$RC"; }
   1.102 +  RC="$?"
   1.103 +fi
   1.104 +
   1.105 +[ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
   1.106 +
   1.107 +exit "$RC"
   1.108 +
   1.109 +#:wrap=soft:maxLineLen=100: