-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtangle
executable file
·122 lines (99 loc) · 3.3 KB
/
tangle
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env zsh
return='0'
tests=( # straight-line-1-bimc1 straight-line-1-bimc2
# straight-line-2-bimc1 straight-line-2-bimc2 straight-line-2-bimc3
inf-div-bad-bimc inf-div-good-bimc
# sum-bimc1 sum-bimc2 sum-bimc3
# collatz-bimc collatz-all-bimc
# krazy-loop-correct-bimc krazy-loop-incorrect-bimc1 krazy-loop-incorrect-bimc2
# straight-line-1-sbc straight-line-2-sbc
# dead-if-sbc
# sum-sbc sum-plus-sbc
# collatz-sbc collatz-all-sbc
# krazy-loop-incorrect-sbc krazy-loop-correct-sbc
)
compiled_programs=( collatz collatz-all
krazy-loop-incorrect krazy-loop-correct
)
gecho() {
echo -e '\e[32m'$@'\e[39m'
}
recho() {
echo -e '\e[31m'$@'\e[39m'
}
h1() {
header="$1"
echo
echo "$header"
echo "$(echo "$header" | sed -n 's/./=/gp')"
echo
}
h2() {
header="$1"
echo "$header"
echo "$(echo "$header" | sed -n 's/./-/gp')"
}
h3() {
header="$1"
echo "### $header"
}
tangle_gen() {
h2 "generating tests ..."
# ----------------------
[[ ! -d tests/output ]] && mkdir -p tests/output
pandoc-tangle --from markdown --to code-sh --code test KAT-IMP-examples.md > tests/test.sh
for test in $tests; do
pandoc-tangle --from markdown --to code-k --code "$test" KAT-IMP-examples.md > "tests/output/$test.out"
done
h2 "generating sbc-ed programs and benchmarks ..."
# -----------------------------------------------
for program in $compiled_programs; do
[[ ! -d "tests/$program-compiled" ]] && mkdir -p "tests/$program-compiled"
pandoc-tangle --from markdown --to code-k --code "$program-compiled" KAT-IMP-examples.md > "tests/$program-compiled/$program.k"
pandoc-tangle --from markdown --to code-sh --code "benchmark-$program" KAT-IMP-examples.md > "tests/benchmark-$program.sh"
done
}
tangle_tests() {
for test in $tests; do
h2 "running '$test' ..."
# ---------------------
bash tests/test.sh $test
if [[ "$?" == '0' ]]; then
gecho "SUCCESS"
else
recho "FAILURE"
fi
done
}
tangle_benchmarks() {
for program in $compiled_programs; do
h2 "running benchmarks for '$program' ..."
# ---------------------------------------
PROGRAM="$(echo "$program" | awk '{print toupper($0)}')"
h3 "kompiling '$PROGRAM-COMPILED' ..."
###
pushd "tests/$program-compiled"
kompile --debug --main-module "$PROGRAM-COMPILED" --syntax-module "$PROGRAM-COMPILED" "$program.k" || exit 1
popd
h3 "running benchmarks for '$program' ..."
###
pushd tests
bash "benchmark-$program.sh"
popd
done
}
[[ "$#" == '0' ]] && set all
while [[ "$#" -gt '0' ]]; do
tangle_command="$1" && shift
h1 "attempting tangle command '$tangle_command' ..."
# =================================================
case "$tangle_command" in
all) set gen kompile examples test bench ;;
gen) tangle_gen ;;
examples) tangle_examples ;;
test) tangle_tests ;;
bench) tangle_benchmarks ;;
*) echo "Unrecognized option: '$tangle_command' ..." ;;
esac
done
exit "$return"