-
Notifications
You must be signed in to change notification settings - Fork 3
/
polyrun
executable file
·53 lines (43 loc) · 1.08 KB
/
polyrun
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
#
# polyrun - run a SML program defined in a SML or MLB file using Poly/ML
#
# Chris Cannam, 2015-2018. MIT licence
set -e
usage() {
me=$(basename "$0")
echo 1>&2
echo "$me: Run a SML program defined in a MLB file using Poly/ML" 1>&2
echo 1>&2
echo "Usage: $me file.sml" 1>&2
echo " $me [-u] file.mlb" 1>&2
echo 1>&2
echo "where" 1>&2
echo " -u: Unique: \"use\" each file only once, regardless of how many times it" 1>&2
echo " appears in the MLB file. See \"polybuild\" for discussion." 1>&2
echo 1>&2
exit 2
}
unique_arg=""
if [ "$1" = "-u" ]; then
unique_arg="-u"
shift
fi
arg="$1"
if [ -z "$arg" ]; then
usage
fi
shift
set -u
mydir=$(dirname "$0")
. "$mydir/smlbuild-include.sh"
out=$(get_outfile "$arg")
tmpobj=$(get_tmpobjfile "$arg")
tmpout=$(get_tmpfile "$arg")
trap "rm -f ${tmpobj} ${tmpout}" 0
( expand_arg $unique_arg "$arg" | \
sed 's|^\(.*\)$|use "\1";|' ;
echo 'PolyML.export("'"$tmpobj"'", main);' ) | \
poly -q --error-exit &&
polyc -o "$tmpout" "$tmpobj" &&
"$tmpout" "$@"