Chris@523: #!/bin/bash Chris@523: Chris@523: # Disable shellcheck warnings for useless-use-of-cat. UUOC is good Chris@523: # practice, not bad: clearer, safer, less error-prone. Chris@523: # shellcheck disable=SC2002 Chris@523: Chris@523: sml="$VEXT_SML" Chris@523: Chris@523: set -eu Chris@523: Chris@523: mydir=$(dirname "$0") Chris@523: program="$mydir/vext.sml" Chris@523: Chris@523: # We need one of Poly/ML, SML/NJ, or MLton. Since we're running a Chris@523: # single-file SML program as if it were a script, our order of Chris@523: # preference is based on startup speed. Chris@523: Chris@523: if [ -z "$sml" ]; then Chris@523: if sml -h 2>&1 | grep -q 'Standard ML of New Jersey'; then Chris@523: sml="smlnj" Chris@523: # We would prefer Poly/ML to SML/NJ, except that Poly v5.7 has a Chris@523: # nasty bug that occasionally causes it to deadlock on startup. Chris@523: # That appears to be fixed in their repo, so we could promote it Chris@523: # up the order again at some point in future Chris@523: elif echo | poly -v 2>/dev/null | grep -q 'Poly/ML'; then Chris@523: sml="poly" Chris@523: elif mlton 2>&1 | grep -q 'MLton'; then Chris@523: sml="mlton" Chris@523: else cat 1>&2 < "$tmp_sml" Chris@523: echo 'val _ = main ()' >> "$tmp_sml" Chris@523: mlton -output "$tmp_out" "$tmp_sml" Chris@523: "$tmp_out" "$@" ;; Chris@523: smlnj) Chris@523: cat "$program" | ( Chris@523: cat < (), flush = fn () => () }; Chris@523: x Chris@523: end; Chris@523: val smlrun__prev = ref ""; Chris@523: Control.Print.out := { Chris@523: say = fn s => Chris@523: (if String.isSubstring " Error" s Chris@523: then (Control.Print.out := smlrun__cp; Chris@523: (#say smlrun__cp) (!smlrun__prev); Chris@523: (#say smlrun__cp) s) Chris@523: else (smlrun__prev := s; ())), Chris@523: flush = fn s => () Chris@523: }; Chris@523: EOF Chris@523: cat - Chris@523: cat < "$tmp_sml" Chris@523: CM_VERBOSE=false sml "$tmp_sml" ;; Chris@523: *) Chris@523: echo "Unknown SML implementation name: $sml"; Chris@523: exit 2 ;; Chris@523: esac Chris@523: