forked from JKTKops/unlambda-compilers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunlc
More file actions
37 lines (32 loc) · 932 Bytes
/
unlc
File metadata and controls
37 lines (32 loc) · 932 Bytes
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
#!/usr/bin/env bash
set -euo pipefail
compile_via_scheme() {
runhaskell "CompileViaScheme.hs" "$1"
}
compile_via_c() {
runhaskell "CompileViaC.hs" $mode "$1"
}
if [[ -z "$1" ]] || [[ "$1" == 'help' ]] || [[ "$1" == '--help' ]] ; then
echo "usage: $0 [help|--help] [--backend (c|scheme)]
[--duplicate-arg|--delay-arg]
FILE"
exit 0
fi
backend='scheme'
mode=''
args=()
while [[ $# -gt 0 ]]; do
arg="$1"
case $arg in
--backend) backend="$2" ; shift 2 ;;
--duplicate-arg) mode="-duplicate-arg" ; shift ;;
--delay-arg) mode="-delay-arg" ; shift ;;
*) args+=("$1") ; shift ;;
esac
done
[[ "${#args[@]}" -le 0 ]] || set -- "${args[@]}"
case "$backend" in
scheme) compile_via_scheme "$@" ;;
c) compile_via_c "$@" ;;
*) $0 help ; fatal "Unknown backend: $backend" ;;
esac