-
Notifications
You must be signed in to change notification settings - Fork 31
/
Makefile
1489 lines (1296 loc) · 49.9 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
###(((((((((((((((((((((((((((((((( L i S P ))))))))))))))))))))))))))))))))
### This file is derived from the files that accompany the book:
### LISP Implantation Semantique Programmation (InterEditions, France)
### or Lisp In Small Pieces (Cambridge University Press).
### By Christian Queinnec <[email protected]>
### The original sources can be downloaded from the author's website at
### http://pagesperso-systeme.lip6.fr/Christian.Queinnec/WWW/LiSP.html
### This file may have been altered from the original in order to work with
### modern schemes. The latest copy of these altered sources can be found at
### https://github.com/appleby/Lisp-In-Small-Pieces
### If you want to report a bug in this program, open a GitHub Issue at the
### repo mentioned above.
### Check the README file before using this file.
###(((((((((((((((((((((((((((((((( L i S P ))))))))))))))))))))))))))))))))
default.work : build.interpreter
# This is the Makefile of the distribution. The first part defines
# the variables that you may have to setup in order to run the
# tests. The second part defines how to test the various parts of
# the sourcef files.
# If you decide to build a specialized interpreter on top of Bigloo
# then indicate the correct command to invoke bigloo.
BIGLOO = bigloo
# If you decide to build multiple specialized interpreters on
# multiple machines, then you must give different HOSTTYPE for all
# these CPU-different machines. Very often, HOSTTYPE is set up for
# you by your shell (tcsh does this). If so, you can leave empty
# this definition, it will be automatically inherited from your
# shell.
export HOSTTYPE := $(shell uname -m)
# Choose a Scheme interpreter. This interpreter must contain Meroonet,
# hygienic macros and a test-suite driver. It is better to build a
# specialized interpreter with these facilities compiled in. See the
# target o/${HOSTTYPE}/book.bigloo below for an example of a
# pre-compiled interpreter. You can also directly use an interpreter
# and load on the fly Meroonet and the test-suite driver every time.
# This is what the MIT, Gambit, and Guile-based definitions do.
# The original Makefile defines only the SCHEME variable. MYSCHEME is
# a shorthand form that is easier to override on the make command
# line.
#
# The default value for MYSCHEME is bigloo because the Bigloo
# interpreter is the only one that is pre-compiled with Meroonet and
# other support code, and is quite a bit faster at executing the
# included test suite than any other interpreter. -- appleby
MYSCHEME = bigloo
# MYSCHEME = guile
# MYSCHEME = mit
SCHEME = o/${HOSTTYPE}/book.${MYSCHEME}
# This variable allows to measure time. I personnally use Gnu time but time
# will do also.
TIME = time
# A temporary file used to store temporary results. Put it in a
# place where it will disappear automatically sometime.
RESULTS = o/test.results
# A temporary file used to store the names of failing tests when
# running the grand.test target.
FAILURES = o/test.failures
# Make an archive grouping *.o files
# You need it if you want to test the Scheme towards C compiler.
AR = ar
# Updating an archive (void on some machines)
# You need it if you want to test the Scheme towards C compiler.
RANLIB = ranlib
# Only needed for test.chap6.ml. -- appleby
CAMLLIGHT = camllight
# This is the C compiler I used as well as its preferred flags.
# You need it if you want to test the Scheme towards C compiler.
# On BSD, you probably want to set CC=gcc48, or whatever version of gcc you
# have installed. Note that it's not enough to specify CC=gcc48 on the make
# command line. The `export' clause here will override it. -- appleby
export CC=gcc
export CFLAGS=-ansi -pedantic -Wall -O
# This is perl. I use it for checking results of tests. It is not
# mandatory to setup this variable.
PERL = perl
# Absolute path to LiSP source root. -- appleby
export LiSP_TOPDIR=${PWD}
# Set the SHELL explicitly. Mit-scheme's run-shell-command respects
# this variable, and some shell commands will fail if using a non-standard
# shell (e.g. fish). -- appleby
export SHELL=/bin/sh
# This part of the Makefile defines how to run and test the programs
# of the book.
# Build the necessary directories where will go specialized interpreters.
MKDIR_TARGET = o/${HOSTTYPE}/mkdir_done
${MKDIR_TARGET}:
mkdir -p o/${HOSTTYPE}
touch $@
##################################### Build specialized interpreters.
# Rebuild a Bigloo interpreter with Meroonet and tester in it.
# Adapted to Bigloo 4.1a. Due to name conflicts, the compilation of
# rtbook.scm emits much warnings: ignore them!
o/${HOSTTYPE}/book.bigloo : bigloo/book.scm o/${HOSTTYPE}/rtbook.a
${BIGLOO} -v -call/cc -cg -o o/${HOSTTYPE}/book.bigloo bigloo/book.scm \
-ldopt o/${HOSTTYPE}/rtbook.a
-rm bigloo/book.[co] o/${HOSTTYPE}/book.[co]
o/${HOSTTYPE}/rtbook.a : o/${HOSTTYPE}/rtbook.o common/pp.scm common/format.scm
-rm o/${HOSTTYPE}/rtbook.a
cd o/${HOSTTYPE} ; ${AR} cvr rtbook.a rtbook.o
-${RANLIB} o/${HOSTTYPE}/rtbook.a
o/${HOSTTYPE}/rtbook.o : bigloo/rtbook.scm bigloo/hack.scm src/tester.scm ${MKDIR_TARGET}
${BIGLOO} -c -v -call/cc -cg -w -o o/${HOSTTYPE}/rtbook.o bigloo/rtbook.scm
-rm bigloo/rtbook.[co] o/${HOSTTYPE}/rtbook.c
# Default work for the distribution, create some sub-directories
# where will go compilation products.
build.interpreter : ${MKDIR_TARGET}
@if [ "X${SCHEME}" = X ] ; \
then echo "*** Unbound SCHEME variable, see Makefile" ; exit 1 ; \
else : ; fi
case "${SCHEME}" in \
*bigloo|*mit|*guile) ${MAKE} ${SCHEME} ;; \
*) : ;; esac
######################################## Test interpreters
test.interpreters : o/${HOSTTYPE}/book.bigloo.test o/${HOSTTYPE}/book.mit.test \
o/${HOSTTYPE}/book.guile.test
MIT_BAND_FILE=o/${HOSTTYPE}/book.mit.com
${MIT_BAND_FILE} : ${MKDIR_TARGET}
echo "(disk-save \"${MIT_BAND_FILE}\" \"${MIT_BAND_FILE}\")" \
| mit-scheme --batch-mode --no-init-file --load mitscheme/book.scm
# Makes a command to run mitscheme. Must be run from the current
# directory.
o/${HOSTTYPE}/book.mit : ${MIT_BAND_FILE}
echo "#!/bin/sh" > $@
echo "exec mit-scheme --band ${MIT_BAND_FILE} --eval '(start)'" >> $@
chmod a=rwx $@
# Makes a command to run guile. Must be run from the current
# directory.
o/${HOSTTYPE}/book.guile : ${MKDIR_TARGET}
echo "#!/bin/sh" > $@
echo "exec guile -q -l guile/book.scm" >> $@
chmod a=rwx $@
check.results :
@if grep -i '= done' ${RESULTS} ; \
then echo '*** Tests successfully passed ***' ; \
else echo '*** *** Abnormal results **** ***' ; exit 1 ; fi
o/${HOSTTYPE}/book.bigloo.test :
${MAKE} SCHEME=o/${HOSTTYPE}/book.bigloo book.interpreter.test
o/${HOSTTYPE}/book.mit.test :
${MAKE} SCHEME=o/${HOSTTYPE}/book.mit book.interpreter.test
o/${HOSTTYPE}/book.guile.test :
${MAKE} SCHEME=o/${HOSTTYPE}/book.guile book.interpreter.test
book.interpreter.test : book.interpreter.test1 book.interpreter.test2 \
book.interpreter.test3 book.interpreter.test4
book.interpreter.test1 : ${SCHEME}
echo '(test "src/syntax.tst")' | ${SCHEME} | tee ${RESULTS}
${MAKE} check.results
book.interpreter.test2 : ${SCHEME}
echo '(test "meroonet/oo-tests.scm")' | ${SCHEME} | tee ${RESULTS}
${MAKE} check.results
book.interpreter.test3 : ${SCHEME}
${MAKE} SCHEME=${SCHEME} test.chap1 | tee ${RESULTS}
${MAKE} check.results
book.interpreter.test4 : ${SCHEME}
${MAKE} SCHEME=${SCHEME} test.chap2a | tee ${RESULTS}
${MAKE} check.results
########################## All the tests
# Some tests have a name starting with no. That means that the test
# has some problems (it does not complete or loops) I just verify
# that it ends at the expected point. Some test have a name starting
# with long. That means that it is a very long long test, so it is
# only run if the variable YOU_HAVE_TIME is true (not false).
# Moore's law has been kind to us. Tests that apparently took hours to
# run on the original author's machine 20 years ago now complete in
# less than a minute. I'm leaving the long- prefixes and YOU_HAVE_TIME
# alone since they're still useful, but unless you're really
# impatient, you probably don't want to disable the "long" tests. For
# reference, the entire grand.test suite takes about 6 minutes to
# complete even with the slower interpreters on my 5-year-old (as of
# late 2014) laptop. When using a pre-compiled interpreter
# (i.e. SCHEME = book.bigloo) the entire suite finishes in less than 3
# minutes. -- appleby
YOU_HAVE_TIME = true
GRAND_TESTS = ${TEST_CHAP1} ${TEST_CHAP2} ${TEST_CHAP3} ${TEST_CHAP4} \
${TEST_CHAP5} ${TEST_CHAP6} ${TEST_CHAP7} ${TEST_CHAP8} \
${TEST_CHAP9} ${TEST_CHAP10}
GRAND_TEST_FLAGS = SCHEME="${SCHEME}" YOU_HAVE_TIME="${YOU_HAVE_TIME}"
grand.test :
${TIME} nice ${MAKE} do.grand.test ${GRAND_TEST_FLAGS}
do.grand.test : ${SCHEME}
@rm -f ${FAILURES}
@for test in ${GRAND_TESTS} ; do \
( echo Testing $$test ... ; ${MAKE} $$test ${GRAND_TEST_FLAGS} ) \
| tee ${RESULTS} ; echo Checking results of $$test ... ; \
${PERL} perl/check.prl ${RESULTS} $$test ; \
[ $$? -ne 0 ] && echo $$test >> ${FAILURES} ; \
done; echo "Finished grand.test"
@[ -e ${FAILURES} ] && ( echo "The following tests failed:"; \
cat ${FAILURES} ) || echo "All tests passed."
grand.test.with.bigloo : o/${HOSTTYPE}/book.bigloo
${MAKE} grand.test SCHEME=o/$$HOSTTYPE/book.bigloo
grand.test.with.mit : o/${HOSTTYPE}/book.mit
${MAKE} grand.test SCHEME=o/$$HOSTTYPE/book.mit
grand.test.with.guile : o/${HOSTTYPE}/book.guile
${MAKE} grand.test SCHEME=o/$$HOSTTYPE/book.guile
########################## (Really) All the tests
# Run all tests for all schemes. This includes all tests from the
# test.interpreters and grand.test targets, plus a handful of other
# targets. -- appleby
ALL_SCHEMES = bigloo guile mit
EXTRA_TESTS = chap10e.example chap10k.example o/chap10ex.E test.chap10e.c
MISC_TARGETS = test.chap6.bgl test.chap6.ml compare.chap10
GRAND_BENCH = ${BENCH_CHAP5} ${BENCH_CHAP6} ${BENCH_CHAP7}
define ok-or-fail =
${PERL} -e "printf '%-40s', '"${1}"'" ; \
${2} ; \
if [ $$? -eq 0 ] ; \
then echo ok ; \
else echo fail; echo " ${1}" >> "${FAILURES}"; fi
endef
define check-failures =
if [ -e "${FAILURES}" ]; \
then echo "The following tests failed:"; cat "${FAILURES}"; exit 1; \
else echo "All tests passed."; fi
endef
all.test:
@${MAKE} -s clean
@${TIME} ${MAKE} -s do.all.test
do.all.test:
@${MAKE} misc.test
@for scheme in ${ALL_SCHEMES} ; do \
${MAKE} clean.all.but.failures; \
${MAKE} build.interpreter.nospew MYSCHEME=$$scheme; \
${MAKE} interpreter.test MYSCHEME=$$scheme; \
${MAKE} extra.test MYSCHEME=$$scheme; \
${MAKE} grand.test.nospew MYSCHEME=$$scheme; \
${MAKE} grand.bench.nospew MYSCHEME=$$scheme; \
done; echo "Finished all.test."
@$(check-failures)
# build.interpreter.nospew is like build.interpreter, but only prints
# pass/fail status.
build.interpreter.nospew: ${MKDIR_TARGET}
@$(call ok-or-fail,"Running ${SCHEME}",\
${MAKE} -s ${SCHEME} > ${RESULTS} 2>&1)
# interpreter.test is equivalent to test.interpreters, but for a
# single $SCHEME, rather than all schemes. Also, this target only
# prints pass/fail status.
interpreter.test: ${MKDIR_TARGET}
@$(call ok-or-fail,"Running book.${MYSCHEME}.test",\
${MAKE} o/${HOSTTYPE}/book.${MYSCHEME}.test > /dev/null 2>&1)
# misc.test includes the few targets that are not included in
# grand.test and that do not depend on $SCHEME.
misc.test: ${MKDIR_TARGET}
@for target in ${MISC_TARGETS} ; do \
$(call ok-or-fail,"Running $$target",\
${MAKE} $$target > ${RESULTS} 2>/dev/null) ; \
done
# extra.test contains tests not included in the grand.test* targets.
extra.test: ${SCHEME}
@for target in ${EXTRA_TESTS} ; do \
$(call ok-or-fail,"Running $$target with ${MYSCHEME}",\
${MAKE} $$target MYSCHEME=${MYSCHEME} > ${RESULTS} 2> /dev/null) ; \
done
# grand.test.quitely is like the grand.test target, but with less
# output on stdout/stderr.
grand.test.quietly:
@${MAKE} -s clean
@${MAKE} -s build.interpreter.nospew
@${TIME} ${MAKE} -s grand.test.nospew
@$(check-failures)
# grand.test.nospew runs the same tests as the grand.test target, but
# only prints a single pass/fail status for each test, rather than
# dumping all test output on stdout/stderr.
grand.test.nospew: ${SCHEME}
@for target in ${GRAND_TESTS} ; do \
$(call ok-or-fail,"Running $$target with ${MYSCHEME}",\
${MAKE} $$target MYSCHEME=${MYSCHEME} > ${RESULTS} 2> /dev/null \
&& ${PERL} perl/check.prl ${RESULTS} $$target > /dev/null) ; \
done
# grand.bench.nospew is like grand.test.nospew, but runs all
# benchmarks instead of tests.
grand.bench.nospew: ${SCHEME}
@for target in ${GRAND_BENCH} ; do \
$(call ok-or-fail,"Running $$target with ${MYSCHEME}",\
${MAKE} $$target MYSCHEME=${MYSCHEME} > ${RESULTS} 2> /dev/null) ; \
done
##################################### Chap 1 ##############################
TEST_CHAP1 = test.chap1
# chap1.scm contains a naive interpreter written in naive Scheme.
test.chap1 : src/chap1.scm
echo \
'(load "src/chap1.scm")' \
'(and (test-scheme1 "src/scheme.tst")' \
' (test-scheme1 "src/chap1.tst"))' \
| ${SCHEME}
##################################### Chap 2 ##############################
TEST_CHAP2 = test.chap2a test.chap2b test.chap2c test.chap2e test.chap2f \
test.chap2g test.chap2h
# chap2a.scm contains a little Lisp2 interpreter (eval e env fenv).
# chap2d.scm displays simple cyclic lists in a finite way.
test.chap2a : src/chap2a.scm
echo \
'(load "src/chap2a.scm")' \
'(and (test-chap2a "src/chap2a.tst")' \
' (load "src/chap2d.scm")' \
" 'done)" \
| ${SCHEME}
# chap2b.scm adds flet and function to the previous interpreter
src/chap2b.scm : src/chap2a.scm
test.chap2b : src/chap2b.scm
echo \
'(load "src/chap2a.scm")' \
'(load "src/chap2b.scm")' \
'(test-scheme2a "src/chap2b.tst")' \
| ${SCHEME}
# chap2c.scm adds dynamic variables (eval e env fenv denv)
src/chap2c.scm : src/chap2b.scm
test.chap2c : src/chap2c.scm
echo \
'(load "src/chap2a.scm")' \
'(load "src/chap2b.scm")' \
'(load "src/chap2c.scm")' \
'(test-scheme2c "src/chap2c.tst")' \
| ${SCHEME}
# chap2e.scm adds dynamic variables a la Common Lisp
src/chap2e.scm : src/chap2c.scm
test.chap2e : src/chap2e.scm
echo \
'(load "src/chap2a.scm")' \
'(load "src/chap2b.scm")' \
'(load "src/chap2c.scm")' \
'(load "src/chap2e.scm")' \
'(test-scheme2c "src/chap2e.tst")' \
| ${SCHEME}
# chap2f.scm adds dynamic variables without special forms
test.chap2f : src/chap2f.scm
echo \
'(load "src/chap2f.scm")' \
'(test-scheme2f "src/chap2f.tst")' \
| ${SCHEME}
# chap2g.scm adds the let, letrec special forms to chap1.scm (scheme)
src/chap2g.scm : src/chap1.scm
test.chap2g : src/chap2g.scm
echo \
'(load "src/chap1.scm")' \
'(load "src/chap2g.scm")' \
'(and (test-scheme1 "src/scheme.tst")' \
' (test-scheme1 "src/chap2g.tst"))' \
| ${SCHEME}
# chap2h.scm allows extensions such as (1 e) or ((f1 f2) e)
src/chap2h.scm : src/chap1.scm
test.chap2h : src/chap2h.scm
echo \
'(load "src/chap1.scm")' \
'(load "src/chap2h.scm")' \
'(and (test-scheme1 "src/scheme.tst")' \
' (test-scheme1 "src/chap2h.tst"))' \
| ${SCHEME}
##################################### Chap 3 ##############################
TEST_CHAP3 = test.chap3f test.chap3h
# chap3{a,b,c,d,e}.scm contain excerpts from chapter3 (not necessarily
# Scheme).
# chap3f.scm contains an interpreter in OO style
test.chap3f : src/chap3g.scm
echo \
'(load "src/chap3f.scm")' \
'(load "src/chap3g.scm")' \
'(load "src/chap3h.scm")' \
'(test-scheme3f "src/scheme.tst")' \
| ${SCHEME}
# chap3g.scm defines additional control features (block, catch)
# chap3h.scm defines unwind-protect
# chap3j.scm improves chap3f.scm
src/chap3g.scm : src/chap3f.scm
src/chap3h.scm : src/chap3f.scm
src/chap3j.scm : src/chap3f.scm
test.chap3h : src/chap3g.scm
echo \
'(load "src/chap3f.scm")' \
'(load "src/chap3g.scm")' \
'(load "src/chap3h.scm")' \
'(load "src/chap3j.scm")' \
'(and (test-scheme3f "src/scheme.tst")' \
' (test-scheme3f "src/chap3f.tst"))' \
| ${SCHEME}
##################################### Chap 4 ##############################
TEST_CHAP4 = test.chap4
# chap4.scm contains excerpts from chapter 4
# chap4a.scm contains a Scheme interpreter coded with nothing but closures.
test.chap4 : src/chap4.scm src/chap4a.scm src/chap4.tst
echo \
'(load "src/chap4.scm")' \
'(load "src/chap4a.scm")' \
"(define box1 'wait)" \
"(define p1 'wait)" \
'(and (file-test "src/scheme.tst")' \
' (set! evaluate new-evaluate)' \
' (file-test "src/chap4a.tst")' \
' (suite-test' \
' "src/chap4.tst" "?? " "== " #t' \
' (lambda (read check err)' \
" (lambda () (check (eval (read)))))" \
' naive-match))' \
| ${SCHEME}
##################################### Chap 5 ##############################
# Denotational semantics
TEST_CHAP5 = test.chap5a loop.test.chap5b test.chap5c test.chap5d test.chap5e \
test.chap5f test.chap5g test.chap5h
BENCH_CHAP5 = bench.chap5a bench.chap5d
bench.chap5 : bench.chap5a
test.chap5a : src/chap5a.scm
echo \
'(load "src/chap5a.scm")' \
'(test-denScheme "src/scheme.tst")' \
| ${SCHEME}
# See typical times a the end of src/chap5-bench.scm
bench.chap5a : src/chap5a.scm
echo \
'(load "src/chap5a.scm")' \
'(bench "src/chap5-bench.scm")' \
| ${SCHEME}
# Lambda calculus denotation
# The last tests loop due to applicative order.
loop.test.chap5b :
-echo skip that test or run it by hand : ${MAKE} test.chap5b
test.chap5b : src/chap5b.scm
echo \
'(load "src/chap5b.scm")' \
'(test-L "src/chap5b.tst")' \
| ${SCHEME}
# Scheme + dynamic variables denotational interpreter
test.chap5c : src/chap5c.scm
echo \
'(load "src/chap5c.scm")' \
'(and (test-denScheme "src/scheme.tst")' \
' (test-denScheme "src/chap5c.tst"))' \
| ${SCHEME}
# Same as chap5c except that this one tries to precompute meanings.
# This is slightly faster than chap5a.
test.chap5d : src/chap5d.scm
echo \
'(load "src/chap5d.scm")' \
'(test-denScheme "src/scheme.tst")' \
| ${SCHEME}
bench.chap5d : src/chap5d.scm src/chap5-bench.scm
echo \
'(load "src/chap5d.scm")' \
'(bench "src/chap5-bench.scm")' \
| ${SCHEME}
# Modify the denotational interpreter chap5d to specify that
# the evaluation order is unspecified.
test.chap5e : src/chap5e.scm
echo \
'(load "src/chap5d.scm")' \
'(load "src/chap5e.scm")' \
'(test-den+Scheme "src/chap5e.tst")' \
| ${SCHEME}
# CPS without any tests.
test.chap5f : src/chap5f.scm
echo \
'(and (load "src/chap5f.scm")' \
" 'done)" \
| ${SCHEME}
# Same as chap5d with an explicit global environment.
test.chap5g : src/chap5g.scm
echo \
'(load "src/chap5g.scm")' \
'(and (test-denScheme "src/scheme.tst")' \
'(test-denScheme "src/chap5g.tst"))' \
| ${SCHEME}
# Unordered evaluation order simulated with random.
test.chap5h : src/chap5h.scm
echo \
'(load "src/chap5h.scm")' \
'(load "src/chap1.scm")' \
'(test-scheme1 "src/scheme.tst")' \
| ${SCHEME}
##################################### Chap 6 ##############################
# Chapter on fast interpretation (by means of precompilation)
TEST_CHAP6 = test.chap6a test.chap6b test.chap6c test.chap6d \
shared.test.chap6dd test.chap6e dynext.test.chap6f test.chap6g \
test.chap6h
BENCH_CHAP6 = bench.chap6a bench.chap6b bench.chap6c bench.chap6d bench.chap6e bench.chap6f
bench.chap6 : bench.chap6a bench.chap6b bench.chap6c bench.chap6d bench.chap6e
# Fast interpretation, code is precompiled into (lambda (sr k)..)
test.chap6a : src/chap6a.scm
echo \
'(load "src/chap6a.scm")' \
'(test-scheme6a "src/scheme.tst")' \
| ${SCHEME}
# Interpreted bench
bench.chap6a : src/chap6a.scm
echo \
'(load "src/chap6a.scm")' \
'(bench6a 1 (call-with-input-file "src/chap5-bench.scm" read))' \
| ${SCHEME}
# The file bigloo/compapp.scm was not included in the source tarball
# from the author's site. One could re-create
# `compile-bigloo-application' and get this target working again, if
# one so desired. I do not so desire. -- appleby
#
# Compiled bench with Bigloo
# test.chap6a.bgl : o/${HOSTTYPE}/rtbook.a o/${HOSTTYPE}/bglchap6a
# ${TIME} o/${HOSTTYPE}/bglchap6a 10
# o/${HOSTTYPE}/bglchap6a : src/chap6a.scm bigloo/compapp.scm
# echo \
# '(load "bigloo/compapp.scm")' \
# '(define the-bench (call-with-input-file "src/chap5-bench.scm" read))' \
# '(compile-bigloo-application '\
# ' "${BIGLOO}" "o/${HOSTTYPE}/" "bglchap6a" ' \
# " `(bench6a (string->number (cadr command-options)) ',the-bench)" \
# ' "src/chap6a.scm")' \
# | ${SCHEME}
# Testing the same fast interpreter with Bigloo (intepreted)
test.chap6.bgl :
echo \
"(define primes " \
" (lambda (n f max)" \
" ((lambda (filter) " \
" (begin " \
" (set! filter (lambda (p) (lambda (n) (= 0 (remainder n p)))))" \
" (if (> n max)" \
" '()" \
" (if (f n)" \
" (primes (+ n 1) f max)" \
" (cons n ((lambda (ff)" \
" (primes (+ n 1)" \
" (lambda (p) (if (f p) #t (ff p)))" \
" max))" \
" (filter n)))))))" \
" 'wait)))" \
"(define (bench factor)" \
" (let loop ((factor factor))" \
" (let ((v (eval '(primes 2 (lambda (x) #f) 500))))" \
" (if (> factor 1)" \
" (loop (- factor 1))" \
" (display v)))))" \
"(bench 100)" \
| ${TIME} ${BIGLOO} -i
# Compare also with CAML light
test.chap6.ml :
echo \
"let rec primes n f max =" \
" let filter p n = (0 = n mod p) in" \
" if (n > max) then" \
" []" \
" else if (f n) then" \
" primes (n+1) f max" \
" else" \
" n :: let ff = (filter n) in" \
" primes (n+1)" \
" (function p -> if (f p) then true else (ff p))" \
" max;;" \
"let bench factor =" \
" let rec loop factor =" \
" let v = primes 2 (fun x -> false) 500 in" \
" if (factor > 1) then" \
" loop (factor-1)" \
" else" \
" v" \
" in" \
" loop factor;; " \
"bench 100;;" \
| ${TIME} ${CAMLLIGHT}
# patch to chap6a.scm to define new global variables on the fly:
test.chap6b : src/chap6a.scm src/chap6b.scm
echo \
'(load "src/chap6a.scm")' \
'(load "src/chap6b.scm")' \
'(and (test-scheme6b "src/chap6b.tst")' \
' (test-scheme6b "src/scheme.tst"))' \
| ${SCHEME}
# Interpreted bench
bench.chap6b : src/chap6a.scm src/chap6b.scm
echo \
'(load "src/chap6a.scm")' \
'(load "src/chap6b.scm")' \
'(bench6a 1 (call-with-input-file "src/chap5-bench.scm" read))' \
| ${SCHEME}
# Environment is now held in a global variable *env*.
# Programs are precompiled into (lambda (k) ...)
test.chap6c : src/chap6c.scm
echo \
'(load "src/chap6a.scm")' \
'(load "src/chap6c.scm")' \
'(test-scheme6c "src/scheme.tst")' \
| ${SCHEME}
# Interpreted bench
bench.chap6c : src/chap6c.scm
echo \
'(load "src/chap6a.scm")' \
'(load "src/chap6c.scm")' \
'(bench6c 1 (call-with-input-file "src/chap5-bench.scm" read))' \
| ${SCHEME}
# Make continuation implicit.
# The program is precompiled into (lambda ()...)
test.chap6d : src/chap6d.scm
echo \
'(load "src/chap6d.scm")' \
'(test-scheme6d "src/scheme.tst")' \
| ${SCHEME}
# Interpreted bench
bench.chap6d : src/chap6d.scm
echo \
'(load "src/chap6d.scm")' \
'(bench6d 1 (call-with-input-file "src/chap5-bench.scm" read))' \
| ${SCHEME}
# Variant with pre-allocated frames (work for Lisp not for Scheme)
# An error is expected on one of the lattest tests on call/cc. This
# test is preceded by the string "The following test forces a
# continuation to return multiply."
shared.test.chap6dd : test.chap6dd
test.chap6dd : src/chap6d.scm src/chap6dd.scm
echo \
'(load "src/chap6d.scm")' \
'(load "src/chap6dd.scm")' \
'(and (test-scheme6d "src/chap6dd.tst")' \
' (test-scheme6d "src/scheme.tst"))' \
| ${SCHEME}
# a small byte-tree-code compiler. (Not used in the book)
test.chap6e : src/chap6e.scm
echo \
'(load "src/chap6d.scm")' \
'(load "src/chap6e.scm")' \
'(test-scheme6e "src/scheme.tst")' \
| ${SCHEME}
bench.chap6e : src/chap6e.scm
echo \
'(load "src/chap6d.scm")' \
'(load "src/chap6e.scm")' \
'(bench6e 1 (call-with-input-file "src/chap5-bench.scm" read))' \
| ${SCHEME}
# chap6e is very dependent on tests on types in byte-eval
# but faster than Scheme->C.
########### Skip chap6f which was superseded by chap10.
# Small compiler towards C (not in the book but still working). This
# compiler uses a different pattern of C generation and a variant
# for environment management. That's why I leave it here. It is
# grafted to the precompiler similarly to the bytecode compiler.
# ATTENTION, this is a very long test. This test fails on
# continuation used out of their dynamic extent (no full
# continuation a la Scheme).
long.dynext.test.chap6f :
if ${YOU_HAVE_TIME} ; then ${MAKE} dynext.test.chap6f ; else : ; fi
dynext.test.chap6f : test.chap6f
test.chap6f : o/${HOSTTYPE}/rt.o src/chap6f.scm
echo \
'(load "src/chap6f.scm")' \
'(test-scheme6f "src/scheme.tst")' \
| ${SCHEME}
# start an interpreter to interactively compile towards C.
#
# The (scheme) toplevel reads an expression and shows the generated
# C. This test fails on continuation used out of their dynamic
# extent (no full continuation a la Scheme).
start.chap6f : o/${HOSTTYPE}/rt.o src/chap6f.scm
@(echo '(load "src/chap6f.scm") (scheme6f)' ; tee ) | ${SCHEME}
# A little bench to appreciate the compiler speed. (obsolete)
bench.chap6f : o/${HOSTTYPE}/chap6f-bench
${TIME} o/${HOSTTYPE}/chap6f-bench
export CaFLAGS=-I${LiSP_TOPDIR}/src/c ${CFLAGS}
o/${HOSTTYPE}/chap6f-bench.c : src/chap6f.scm src/chap5-bench.scm
echo \
'(load "src/chap6f.scm")' \
'(compile-file "src/chap5-bench.scm" "$@")' \
| ${SCHEME}
-indent $@
# The runtime in C for that compiler. Generates a lot of warnings...
# superseded by the new library src/c/scheme*.[ch] (but this one
# contains a GC).
o/${HOSTTYPE}/rt.o : src/c/rt.c src/c/rt.h
cd o/${HOSTTYPE} ; ${CC} -c ${CaFLAGS} ../../src/c/rt.c
o/${HOSTTYPE}/chap6f-bench : o/${HOSTTYPE}/chap6f-bench.c
o/${HOSTTYPE}/chap6f-bench : o/${HOSTTYPE}/rt.o
${CC} -o $@ ${CaFLAGS} o/${HOSTTYPE}/chap6f-bench.c o/${HOSTTYPE}/rt.o
########### end of chap6f which was superseded by chap10. (obsolete)
# Handling the define special form.
test.chap6g : src/chap6a.scm src/chap6b.scm src/chap6g.scm
echo \
'(load "src/chap6a.scm")' \
'(load "src/chap6b.scm")' \
'(load "src/chap6g.scm")' \
'(and (test-scheme6b "src/chap6g.tst")' \
' (test-scheme6b "src/scheme.tst"))' \
| ${SCHEME}
# exercice on a specialized invocation protocol for thunks
test.chap6h : src/chap6d.scm src/chap6h.scm
echo \
'(load "src/chap6d.scm")' \
'(load "src/chap6h.scm")' \
'(test-scheme6d "src/scheme.tst")' \
| ${SCHEME}
##################################### Chap 7 ##############################
# Bytecode compilation
TEST_CHAP7 = test.chap7a test.chap7b test.chap7c test.chap7d test.chap7e \
test.chap7g test.chap7h shallow.test.chap7i
BENCH_CHAP7 = bench.chap7d
bench.chap7 : bench.chap7d
# Linearize the intermediate language to make register *val* appear.
test.chap7a : src/chap6d.scm src/chap7a.scm
echo \
'(load "src/chap6d.scm")' \
'(load "src/chap7a.scm")' \
'(test-scheme7a "src/scheme.tst")' \
| ${SCHEME}
# make stack appear (as well as other registers)
test.chap7b : src/chap6d.scm src/chap7b.scm
echo \
'(load "src/chap6d.scm")' \
'(load "src/chap7b.scm")' \
'(test-scheme7b "src/scheme.tst")' \
| ${SCHEME}
# represents instructions by list of closures. Make register PC
# appear.
test.chap7c : src/chap6d.scm src/chap7c.scm
echo \
'(load "src/chap6d.scm")' \
'(load "src/chap7c.scm")' \
'(test-scheme7c "src/scheme.tst")' \
| ${SCHEME}
# the complete bytecode compiler itself.
# The instruction set is defined in chap7f but is directly
# handled by chap7d.
test.chap7d : src/chap6d.scm src/chap7d.scm src/chap7f.scm
echo \
'(load "src/chap6d.scm")' \
'(load "src/chap7d.scm")' \
'(test-scheme7d "src/scheme.tst")' \
| ${SCHEME}
bench.chap7d : src/chap6d.scm src/chap7d.scm src/chap7f.scm
echo \
'(load "src/chap6d.scm")' \
'(load "src/chap7d.scm")' \
'(bench7d 1 (call-with-input-file "src/chap5-bench.scm" read))' \
| ${SCHEME}
# added bind-exit, dynamic variables and error handling (first version
# with dynenv register) in the bytecode compiler.
test.chap7e : src/chap7d.scm src/chap7e.scm
echo \
'(load "src/chap6d.scm")' \
'(load "src/chap7d.scm")' \
'(load "src/chap7e.scm")' \
'(and (test-scheme7e "src/scheme.tst")' \
' (test-scheme7e "src/chap7d.tst")' \
' (test-scheme7e "src/chap5c.tst"))' \
| ${SCHEME}
# chap7f.scm contains the definition of the instructions of the machine
# separate compilation stuff, link compiled files, build stand-alone
# with the bytecode compiler.
test.chap7g : src/chap7h.scm src/chap7g.scm
echo \
'(load "src/chap6d.scm")' \
'(load "src/chap7d.scm")' \
'(load "src/chap7h.scm")' \
'(load "src/chap7g.scm")' \
'(and (test-scheme7g "src/scheme.tst")' \
' (test-scheme7g "src/chap7d.tst")' \
' (test-scheme7g "src/chap5c.tst"))' \
'(compile-file "si/foo.scm" "o/foo.so")' \
'(run-application 100 "o/foo.so")' \
'(compile-file "si/fact.scm" "o/fact.so")' \
'(compile-file "si/fib.scm" "o/fib.so")' \
'(compile-file "si/after.scm" "o/after.so")' \
'(build-application' \
' "o/a.out" "o/fact.so" "o/fib.so" "o/foo.so" "o/after.so")' \
'(run-application 400 "o/a.out")' \
'(build-application-renaming-variables' \
' "o/na.out" "o/a.out"' \
" '((fib fact) (fact fib)))" \
'(run-application 400 "o/na.out")' \
"(assoc 'long-goto (disassemble *code*))" \
| ${SCHEME}
# implementation variant for dynamic variables, error handlers
# with labels in the stack (without dynenv register).
test.chap7h : src/chap7d.scm src/chap7h.scm
echo \
'(load "src/chap6d.scm")' \
'(load "src/chap7d.scm")' \
'(load "src/chap7h.scm")' \
'(and (test-scheme7h "src/scheme.tst")' \
' (test-scheme7h "src/chap7d.tst")' \
' (test-scheme7h "src/chap5c.tst"))' \
| ${SCHEME}
# shallow binding for dynamic variables
# It will fail on the last test of src/chap7d.tst
shallow.test.chap7i : test.chap7i
test.chap7i : src/chap7h.scm
echo \
'(load "src/chap6d.scm")' \
'(load "src/chap7d.scm")' \
'(load "src/chap7h.scm")' \
'(load "src/chap7i.scm")' \
'(and (test-scheme7h "src/scheme.tst")' \
' (test-scheme7h "src/chap5c.tst")' \
' (test-scheme7h "src/chap7d.tst"))' \
| ${SCHEME}
##################################### Chap 8 ##############################
# Chapter on evaluation and reflection
TEST_CHAP8 = test.chap8a test.chap8b test.chap8c test.chap8d evalf.test.chap8e \
evalf.test.chap8f evalf.test.chap8g test.chap8h test.chap8i \
big.test.chap8j
# add eval/ce (as a special form) to the naive interpreter of chapter 1.
test.chap8a : src/chap8a.scm src/chap1.scm
echo \
'(load "src/chap1.scm")' \
'(load "src/chap8a.scm")' \
'(and (test-scheme1 "src/scheme.tst")' \
' (test-program "src/chap8.tst")' \
' (set! set-global-value! dynamic-set-global-value!)' \
' (test-scheme1 "src/chap8a.tst"))' \
| ${SCHEME}
# Add eval/ce (as a special form) to the predenotational interpreter
# (with closures everyhere) seen in chapter 4.
test.chap8b : src/chap8b.scm src/chap4a.scm
echo \
'(load "src/chap8a.scm")' \
'(load "src/chap4a.scm")' \
'(load "src/chap8b.scm")' \
'(and (file-test "src/scheme.tst")' \
' (file-test "src/chap8a.tst"))' \
| ${SCHEME}
# Add eval/ce (as a special form) to the threaded interpreter of
# chapter 6.
test.chap8c : src/chap8c.scm src/chap6d.scm
echo \
'(load "src/chap8a.scm")' \
'(load "src/chap6d.scm")' \
'(load "src/chap8c.scm")' \
'(and (test-scheme6d "src/scheme.tst")' \
' (test-scheme6d "src/chap8a.tst"))' \
| ${SCHEME}
# Add eval/ce (as a special form) to the bytecode compiler
test.chap8d : src/chap8c.scm src/chap8d.scm src/chap6d.scm
echo \
'(load "src/chap8a.scm")' \
'(load "src/chap6d.scm")' \
'(load "src/chap7d.scm")' \
'(load "src/chap7h.scm")' \
'(load "src/chap7g.scm")' \
'(load "src/chap8d.scm")' \
'(and (test-scheme7g "src/scheme.tst")' \
' (test-scheme7g "src/chap5c.tst")' \
' (test-scheme7g "src/chap7d.tst")' \
' (test-scheme7g "src/chap8a.tst"))' \
| ${SCHEME}
# add eval/at (a function) as a function to the naive interpreter
# It fails on a test preceded by "eval as a function will fail..."
evalf.test.chap8e : src/chap8e.scm src/chap1.scm
echo \
'(load "src/chap8a.scm")' \
'(load "src/chap1.scm")' \
'(load "src/chap8e.scm")' \
'(and (test-scheme1 "src/scheme.tst")' \
' (test-scheme1 "src/chap8a.tst"))' \
| ${SCHEME}
# add eval/at (a function) to the bytecode compiler.
# It fails on a test preceded by "eval as a function will fail..."
evalf.test.chap8f : src/chap8f.scm
echo \
'(load "src/chap8a.scm")' \