lib/scripts/run-polyml
author nipkow
Tue, 18 Sep 2012 03:33:53 +0200
changeset 49433 1095f240146a
parent 48662 b171bcd5dd86
child 51099 2ef891f99d2c
permissions -rwxr-xr-x
tuned
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10555
2323ec838401 /usr/bin/env bash;
wenzelm
parents: 10206
diff changeset
     1
#!/usr/bin/env bash
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
     2
#
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents: 25123
diff changeset
     3
# Author: Makarius
2314
67bf78c7c725 replaced cat by ucat;
wenzelm
parents: 2301
diff changeset
     4
#
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents: 25123
diff changeset
     5
# Poly/ML 5.1/5.2 startup script.
9977
32955afeb835 unexport exports;
wenzelm
parents: 9789
diff changeset
     6
31317
1f5740424c69 removed "compress" option from isabelle-process and isabelle usedir -- this is always enabled;
wenzelm
parents: 31315
diff changeset
     7
export -n INFILE OUTFILE MLTEXT TERMINATE NOWRITE
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
     8
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
     9
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    10
## diagnostics
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    11
40544
34e56a6668ba tuned error messages;
wenzelm
parents: 40480
diff changeset
    12
function fail()
34e56a6668ba tuned error messages;
wenzelm
parents: 40480
diff changeset
    13
{
34e56a6668ba tuned error messages;
wenzelm
parents: 40480
diff changeset
    14
  echo "$1" >&2
34e56a6668ba tuned error messages;
wenzelm
parents: 40480
diff changeset
    15
  exit 2
34e56a6668ba tuned error messages;
wenzelm
parents: 40480
diff changeset
    16
}
34e56a6668ba tuned error messages;
wenzelm
parents: 40480
diff changeset
    17
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2314
diff changeset
    18
function fail_out()
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    19
{
40544
34e56a6668ba tuned error messages;
wenzelm
parents: 40480
diff changeset
    20
  fail "Unable to create output heap file: \"$OUTFILE\""
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    21
}
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    22
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    23
function check_file()
5063
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    24
{
40544
34e56a6668ba tuned error messages;
wenzelm
parents: 40480
diff changeset
    25
  [ ! -f "$1" ] && fail "Unable to locate \"$1\""
5063
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    26
}
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    27
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    28
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents: 25123
diff changeset
    29
## compiler executables and libraries
16374
f4b7cf8975af some cygwin support;
wenzelm
parents: 16285
diff changeset
    30
40544
34e56a6668ba tuned error messages;
wenzelm
parents: 40480
diff changeset
    31
[ -z "$ML_HOME" ] && fail "Missing ML installation (ML_HOME)"
34e56a6668ba tuned error messages;
wenzelm
parents: 40480
diff changeset
    32
21356
556addc67737 removed old cygwin wrappers;
wenzelm
parents: 18166
diff changeset
    33
POLY="$ML_HOME/poly"
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    34
check_file "$POLY"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    35
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents: 25123
diff changeset
    36
if [ "$(basename "$ML_HOME")" = bin ]; then
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents: 25123
diff changeset
    37
  POLYLIB="$(cd "$ML_HOME"; cd "$(pwd -P)"; cd ../lib; pwd)"
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    38
else
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents: 25123
diff changeset
    39
  POLYLIB="$ML_HOME"
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    40
fi
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    41
41614
b7cd80330a16 added librarypath: shared library convenience in bash, keeping LD_LIBRARY_PATH and DYLD_LIBRARY_PATH separate;
wenzelm
parents: 40544
diff changeset
    42
librarypath "$POLYLIB"
9765
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    43
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    44
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    45
## prepare databases
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    46
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    47
if [ -z "$INFILE" ]; then
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents: 25123
diff changeset
    48
  INIT=""
48662
b171bcd5dd86 more informative process exit code;
wenzelm
parents: 48002
diff changeset
    49
  EXIT="fun exit rc : unit = Posix.Process.exit (Word8.fromInt rc);"
10105
f9be78009930 added COPYDB argument;
wenzelm
parents: 9997
diff changeset
    50
else
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents: 25123
diff changeset
    51
  check_file "$INFILE"
48662
b171bcd5dd86 more informative process exit code;
wenzelm
parents: 48002
diff changeset
    52
  INIT="(Signal.signal (2, Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ())); PolyML.SaveState.loadState \"$INFILE\" handle Fail msg => (TextIO.output (TextIO.stdErr, msg ^ \": $INFILE\\n\"); Posix.Process.exit 0w1));"
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents: 25123
diff changeset
    53
  EXIT=""
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    54
fi
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    55
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    56
if [ -z "$OUTFILE" ]; then
39619
34952c2423c6 isabelle-process: less verbose no-commit mode;
wenzelm
parents: 31317
diff changeset
    57
  COMMIT='fun commit () = false;'
34952c2423c6 isabelle-process: less verbose no-commit mode;
wenzelm
parents: 31317
diff changeset
    58
  MLEXIT=""
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    59
else
31317
1f5740424c69 removed "compress" option from isabelle-process and isabelle usedir -- this is always enabled;
wenzelm
parents: 31315
diff changeset
    60
  COMMIT="fun commit () = (PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.SaveState.saveState \"$OUTFILE\"; true);"
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents: 25123
diff changeset
    61
  [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
39619
34952c2423c6 isabelle-process: less verbose no-commit mode;
wenzelm
parents: 31317
diff changeset
    62
  MLEXIT="commit();"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    63
fi
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    64
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    65
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    66
## run it!
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    67
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents: 25123
diff changeset
    68
MLTEXT="$INIT $EXIT $COMMIT $MLTEXT"
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents: 25123
diff changeset
    69
16254
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
    70
if [ -z "$TERMINATE" ]; then
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
    71
  FEEDER_OPTS=""
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
    72
else
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
    73
  FEEDER_OPTS="-q"
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
    74
fi
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
    75
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents: 25123
diff changeset
    76
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
48002
6de952f4069f potentially more convincing kill -TERM of feeder (cf. 32c03d45fffe) -- attempt to workaround spurious perl "hangs" on lxbroy10;
wenzelm
parents: 41614
diff changeset
    77
  { read FPID; "$POLY" -q $ML_OPTIONS; RC="$?"; kill -TERM "$FPID"; exit "$RC"; }
9789
wenzelm
parents: 9765
diff changeset
    78
RC="$?"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    79
4505
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4333
diff changeset
    80
[ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    81
9789
wenzelm
parents: 9765
diff changeset
    82
exit "$RC"
40480
d695d258dfbc tuned error message;
wenzelm
parents: 39619
diff changeset
    83
d695d258dfbc tuned error message;
wenzelm
parents: 39619
diff changeset
    84
#:wrap=soft:maxLineLen=100: