-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepl
executable file
·51 lines (43 loc) · 1.13 KB
/
repl
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
#!/bin/bash
###################################################################################
#
# run -r moduleName.ml opens a repl (utop) containing a module named ModuleName
# run -n moduleName.ml runs the native executable for file moduleName.ml
# run -b moduleName.ml runs the bytecode executable for file moduleName.ml
#
repl=utop # your favorite repl
build=_build # build directory
packages=( core, ppx_jane ) # packages you'd like to load into the repl
[ "$#" -eq 1 ] || {
echo "Usage: $0 FILE"
exit 1
}
file=$(basename "${1%.*}") # Remove .ml file extension if necessary
if ! which $repl > /dev/null; then
echo "utop not found. Run the following command to install:"
echo "opam install utop"
exit 1
fi
dop() { # do and print
echo $@
eval $@
}
dop make $file.byte
# Build -I flags for repl
flags=$(find $build -type d | while read d; do
echo -n "-I $d "
done)
# Build command to run in repl at startup
init=
for i in "${packages[@]}"; do
req="#require \"$i\";;"
echo $req
init=$init$req
done
load="#load_rec \"$file.cmo\";;"
echo $load
$repl $flags -init <(cat <<< "
$init
$load
")
dop rm $file.byte