forked from woodrush/lambdavm
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
215 lines (172 loc) · 6.38 KB
/
Makefile
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# Binary lambda calculus
BLC=./bin/Blc
UNI=./bin/uni
UNIPP=./bin/uni++
# Universal lambda
CLAMB=./bin/clamb
# Lazy K
LAZYK=./bin/lazyk
# Tools
ASC2BIN=./bin/asc2bin
LAM2BIN=./bin/lam2bin
BLCAIT=./bin/blc-ait
# Toolkit
LAMBDATOOLS=./build/lambda-calculus-devkit
# Other
SBCL=sbcl
LATEX=latex
DVIPDFMX=dvipdfmx
target_latex=out/lambdavm.tex
target_pdf=lambdavm.pdf
LAMBDAVM_SRCS=./src/lambdavm.cl ./src/lambdacraft.cl ./src/blc-numbers.cl ./src/blc-clamb-wrapper.cl
all: $(addsuffix .blc, $(addprefix out/, $(notdir $(wildcard examples/*.cl)))) \
$(addsuffix .lazy, $(addprefix out/, $(notdir $(wildcard examples/*.cl)))) \
$(addsuffix .ulamb, $(addprefix out/, $(notdir $(wildcard examples/*.cl))))
test: test-blc test-ulamb test-lazyk test-blc-unipp
testrot13: testrot13-blc testrot13-ulamb testrot13-lazyk testrot13-blc-unipp
pdf: $(target_pdf)
lambdavm.lam: $(BLCAIT) src/main.cl src/lambdavm.cl
sbcl --script src/main.cl > out/lambdavm.lam.tmp
$(BLCAIT) blc out/lambdavm.lam.tmp > out/lambdavm.lam.tmp.opt
cat out/lambdavm.lam.tmp.opt | sbcl --script notes/blc-to-ski.cl -iblc -olambda > out/lambdavm.lam.tmp
mv out/lambdavm.lam.tmp lambdavm.lam
rm out/lambdavm.lam.tmp.opt
lambdavm.blc: $(BLCAIT) src/main.cl src/lambdavm.cl
sbcl --script src/main.cl > out/lambdavm.lam.tmp
$(BLCAIT) blc out/lambdavm.lam.tmp > lambdavm.blc.tmp
mv lambdavm.blc.tmp lambdavm.blc
rm out/lambdavm.lam.tmp
lambdavm.lazy: $(BLCAIT) src/main-lazy.cl src/lambdavm.cl src/blc-clamb-wrapper.cl
sbcl --script src/main-lazy.cl > out/lambdavm.lazy.lam.tmp
$(BLCAIT) blc out/lambdavm.lazy.lam.tmp > out/lambdavm.lazy.lam.tmp.opt
cat out/lambdavm.lazy.lam.tmp.opt | sbcl --script notes/blc-to-ski.cl -iblc -oski > out/lambdavm.lazy.tmp
cat out/lambdavm.lazy.tmp | sed -e 's/``s`kki/k/g' > lambdavm.lazy
rm out/lambdavm.lazy.tmp out/lambdavm.lazy.lam.tmp
#================================================================
# Build the PDF
#================================================================
.PRECIOUS: $(target_latex)
$(target_latex): $(LAMBDAVM_SRCS) ./src/main.cl ./tools/main.tex ./tools/make-latex.sh
mkdir -p ./out
./tools/make-latex.sh
mv lambdavm.tex out
.PHONY: pdf
$(target_pdf): $(target_latex) lambdavm.lam
cp ./tools/main.tex out
cd out; $(LATEX) main.tex
cd out; $(DVIPDFMX) main.dvi -o lambdavm.pdf
mv out/lambdavm.pdf .
#================================================================
# Tests
#================================================================
.PHONY: testrot13-%
testrot13-%: out/rot13.cl.%-out.expected-diff
@echo "\n All tests have passed for $(interpreter-name-$*).\n"
.PHONY: test-%
test-%: $(addsuffix .%-out.expected-diff, $(addprefix out/, $(notdir $(wildcard examples/*.cl))))
@echo "\n All tests have passed for $(interpreter-name-$*).\n"
interpreter-name-blc="BLC with the interpreter 'uni'"
interpreter-name-blc-blc="BLC with the interpreter 'Blc'"
interpreter-name-blc-unipp="BLC with the interpreter 'uni++'"
interpreter-name-ulamb="Universal Lambda"
interpreter-name-lazyk="Lazy K"
.PRECIOUS: out/%.blc
out/%.blc: examples/% $(LAMBDAVM_SRCS)
mkdir -p out
$(SBCL) --script $< > $@
.PRECIOUS: out/%.ulamb
out/%.ulamb: examples/% $(LAMBDAVM_SRCS)
mkdir -p out
( printf '(defparameter **compile-ulamb** t)'; cat $< ) > [email protected]
$(SBCL) --script [email protected] > $@
.PRECIOUS: out/%.lazy
out/%.lazy: examples/% $(LAMBDAVM_SRCS)
mkdir -p out
( printf '(defparameter **compile-lazy** t)'; cat $< ) > [email protected]
$(SBCL) --script [email protected] > $@
.PRECIOUS: out/%.blc-blc-out
out/%.blc-blc-out: out/%.blc $(BLC) $(ASC2BIN)
if [ -f "test/$*.in" ]; then \
( cat $< | $(ASC2BIN); cat test/$*.in ) | $(BLC) | head -n 20 > [email protected]; else \
cat $< | $(ASC2BIN) | $(BLC) | head -n 20 > [email protected]; fi
mv [email protected] $@
.PRECIOUS: out/%.blc-out
out/%.blc-out: out/%.blc $(UNI) $(ASC2BIN)
if [ -f "test/$*.in" ]; then \
( cat $< | $(ASC2BIN); cat test/$*.in ) | $(UNI) | head -n 20 > [email protected]; else \
cat $< | $(ASC2BIN) | $(UNI) | head -n 20 > [email protected]; fi
mv [email protected] $@
.PRECIOUS: out/%.blc-unipp-out
out/%.blc-unipp-out: out/%.blc $(UNIPP) $(ASC2BIN)
if [ -f "test/$*.in" ]; then \
( cat $< | $(ASC2BIN); cat test/$*.in ) | $(UNIPP) -o | head -n 20 > [email protected]; else \
cat $< | $(ASC2BIN) | $(UNIPP) -o | head -n 20 > [email protected]; fi
mv [email protected] $@
.PRECIOUS: out/%.ulamb-out
out/%.ulamb-out: out/%.ulamb $(CLAMB) $(ASC2BIN)
if [ -f "test/$*.in" ]; then \
( cat $< | $(ASC2BIN); cat test/$*.in ) | $(CLAMB) -u | head -n 20 > [email protected]; else \
cat $< | $(ASC2BIN) | $(CLAMB) -u | head -n 20 > [email protected]; fi
mv [email protected] $@
.PRECIOUS: out/%.lazyk-out
out/%.lazyk-out: out/%.lazy $(LAZYK)
if [ -f "test/$*.in" ]; then \
cat test/$*.in | $(LAZYK) $< -u | head -n 20 > [email protected]; else \
$(LAZYK) $< -u | head -n 20 > [email protected]; fi
mv [email protected] $@
out/%.blc-out.expected-diff: ./out/%.blc-out ./test/%.out
diff $^ || exit 1
out/%.blc-blc-out.expected-diff: ./out/%.blc-blc-out ./test/%.out
diff $^ || exit 1
out/%.blc-unipp-out.expected-diff: ./out/%.blc-unipp-out ./test/%.out
diff $^ || exit 1
out/%.ulamb-out.expected-diff: ./out/%.ulamb-out ./test/%.out
diff $^ || exit 1
out/%.lazyk-out.expected-diff: ./out/%.lazyk-out ./test/%.out
diff $^ || exit 1
#================================================================
# Build the interpreters and tools
#================================================================
$(LAMBDATOOLS):
mkdir -p build
cd build; git clone https://github.com/woodrush/lambda-calculus-devkit
.PHONY: blc
blc: $(BLC)
$(BLC): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && $(MAKE) blc && mv bin/Blc ../../bin
.PHONY: uni
uni: $(UNI)
$(UNI): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && $(MAKE) uni && cp bin/uni ../../bin
.PHONY: uni++
uni++: $(UNIPP)
$(UNIPP): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && make uni++ && mv bin/uni++ ../../bin
.PHONY: clamb
clamb: $(CLAMB)
$(CLAMB): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && make clamb && mv bin/clamb ../../bin
.PHONY: lazyk
lazyk: $(LAZYK)
$(LAZYK): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && make lazyk && mv bin/lazyk ../../bin
.PHONY: asc2bin
asc2bin: $(ASC2BIN)
$(ASC2BIN): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && make asc2bin && mv bin/asc2bin ../../bin
.PHONY: lam2bin
lam2bin: $(LAM2BIN)
$(LAM2BIN): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && make lam2bin && mv bin/lam2bin ../../bin
.PHONY: blc-ait
blc-ait: $(BLCAIT)
$(BLCAIT): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && make blc-ait && mv bin/blc-ait ../../bin