comparison vext @ 1740:669bd699082d

Update vext
author Chris Cannam
date Thu, 13 Jul 2017 15:34:33 +0100
parents bf8a5ce8fb62
children bf4a7015033e
comparison
equal deleted inserted replaced
1739:713ab804d16e 1740:669bd699082d
9 set -eu 9 set -eu
10 10
11 mydir=$(dirname "$0") 11 mydir=$(dirname "$0")
12 program="$mydir/vext.sml" 12 program="$mydir/vext.sml"
13 13
14 hasher=
15 local_install=
16 if [ -w "$mydir" ]; then
17 if echo | sha256sum >/dev/null 2>&1 ; then
18 hasher=sha256sum
19 local_install=true
20 elif echo | shasum >/dev/null 2>&1 ; then
21 hasher=shasum
22 local_install=true
23 else
24 echo "WARNING: sha256sum or shasum program not found" 1>&2
25 fi
26 fi
27
28 if [ -n "$local_install" ]; then
29 hash=$(echo "$sml" | cat "$program" - | $hasher | cut -c1-16)
30 gen_sml=$mydir/.vext-$hash.sml
31 gen_out=$mydir/.vext-$hash.bin
32 trap 'rm -f $gen_sml' 0
33 else
34 gen_sml=$(mktemp /tmp/vext-XXXXXXXX.sml)
35 gen_out=$(mktemp /tmp/vext-XXXXXXXX.bin)
36 trap 'rm -f $gen_sml $gen_out' 0
37 fi
38
39 if [ -x "$gen_out" ]; then
40 exec "$gen_out" "$@"
41 fi
42
14 # We need one of Poly/ML, SML/NJ, or MLton. Since we're running a 43 # We need one of Poly/ML, SML/NJ, or MLton. Since we're running a
15 # single-file SML program as if it were a script, our order of 44 # single-file SML program as if it were a script, our order of
16 # preference is based on startup speed. 45 # preference is based on startup speed, except in the local_install
46 # case where we retain a persistent binary.
17 47
18 if [ -z "$sml" ]; then 48 if [ -z "$sml" ]; then
19 if sml -h 2>&1 | grep -q 'Standard ML of New Jersey'; then 49 if [ -n "$local_install" ] && mlton 2>&1 | grep -q 'MLton'; then
50 sml="mlton"
51 elif sml -h 2>&1 | grep -q 'Standard ML of New Jersey'; then
20 sml="smlnj" 52 sml="smlnj"
21 # We would prefer Poly/ML to SML/NJ, except that Poly v5.7 has a 53 # We would prefer Poly/ML to SML/NJ, except that Poly v5.7 has a
22 # nasty bug that occasionally causes it to deadlock on startup. 54 # nasty bug that occasionally causes it to deadlock on startup.
23 # That appears to be fixed in their repo, so we could promote it 55 # That appears to be fixed in their repo, so we could promote it
24 # up the order again at some point in future 56 # up the order again at some point in future
53 EOF 85 EOF
54 exit 2 86 exit 2
55 fi 87 fi
56 fi 88 fi
57 89
58 tmp_sml=$(mktemp /tmp/vext-XXXXXXXX.sml)
59 tmp_out=$(mktemp /tmp/vext-XXXXXXXX.bin)
60
61 trap 'rm -f $tmp_sml $tmp_out' 0
62
63 arglist="" 90 arglist=""
64 for arg in "$@"; do 91 for arg in "$@"; do
65 if [ -n "$arglist" ]; then arglist="$arglist,"; fi 92 if [ -n "$arglist" ]; then arglist="$arglist,"; fi
66 if echo "$arg" | grep -q '[^a-z]' ; then 93 if echo "$arg" | grep -q '[^a-z]' ; then
67 arglist="$arglist\"usage\"" 94 arglist="$arglist\"usage\""
69 arglist="$arglist\"$arg\"" 96 arglist="$arglist\"$arg\""
70 fi 97 fi
71 done 98 done
72 99
73 case "$sml" in 100 case "$sml" in
74 poly) echo 'use "'"$program"'"; vext ['"$arglist"'];' | 101 poly)
75 poly -q --error-exit ;; 102 if [ -n "$local_install" ] && polyc --help >/dev/null 2>&1 ; then
103 if [ ! -x "$gen_out" ]; then
104 polyc -o "$gen_out" "$program"
105 fi
106 "$gen_out" "$@"
107 else
108 echo 'use "'"$program"'"; vext ['"$arglist"'];' |
109 poly -q --error-exit
110 fi ;;
76 mlton) 111 mlton)
77 cat "$program" > "$tmp_sml" 112 if [ ! -x "$gen_out" ]; then
78 echo 'val _ = main ()' >> "$tmp_sml" 113 echo "val _ = main ()" | cat "$program" - > "$gen_sml"
79 mlton -output "$tmp_out" "$tmp_sml" 114 mlton -output "$gen_out" "$gen_sml"
80 "$tmp_out" "$@" ;; 115 fi
116 "$gen_out" "$@" ;;
81 smlnj) 117 smlnj)
82 cat "$program" | ( 118 cat "$program" | (
83 cat <<EOF 119 cat <<EOF
84 val smlrun__cp = 120 val smlrun__cp =
85 let val x = !Control.Print.out in 121 let val x = !Control.Print.out in
100 cat - 136 cat -
101 cat <<EOF 137 cat <<EOF
102 val _ = vext [$arglist]; 138 val _ = vext [$arglist];
103 val _ = OS.Process.exit (OS.Process.success); 139 val _ = OS.Process.exit (OS.Process.success);
104 EOF 140 EOF
105 ) > "$tmp_sml" 141 ) > "$gen_sml"
106 CM_VERBOSE=false sml "$tmp_sml" ;; 142 CM_VERBOSE=false sml "$gen_sml" ;;
107 *) 143 *)
108 echo "Unknown SML implementation name: $sml"; 144 echo "Unknown SML implementation name: $sml";
109 exit 2 ;; 145 exit 2 ;;
110 esac 146 esac
111 147