fsharp: step5: Added tail call optimization.
[jackhill/mal.git] / Makefile
CommitLineData
31690700
JM
1#
2# Command line settings
3#
4
5MAL_IMPL = js
6
a05f7822
JM
7PYTHON = python
8
31690700
JM
9#
10# Settings
11#
12
d993b22f
PS
13IMPLS = bash c clojure coffee cpp cs forth fsharp go haskell java \
14 julia js lua make mal ocaml matlab miniMAL nim perl php ps \
15 python r racket ruby rust scala swift vb
31690700
JM
16
17step0 = step0_repl
18step1 = step1_read_print
19step2 = step2_eval
20step3 = step3_env
21step4 = step4_if_fn_do
22step5 = step5_tco
23step6 = step6_file
24step7 = step7_quote
25step8 = step8_macros
01c97316 26step9 = step9_try
90f618cb 27stepA = stepA_mal
31690700 28
cc021efe
JM
29EXCLUDE_TESTS += test^bash^step5 # no stack exhaustion or completion
30EXCLUDE_TESTS += test^c^step5 # segfault
0fbd1b81 31EXCLUDE_TESTS += test^cpp^step5 # completes at 10,000
cc021efe 32EXCLUDE_TESTS += test^cs^step5 # fatal stack overflow fault
8862f80e 33EXCLUDE_TESTS += test^fsharp^step5 # completes at 10,000, fatal stack overflow at 100,000
7907cd90 34EXCLUDE_TESTS += test^haskell^step5 # test completes
cc021efe
JM
35EXCLUDE_TESTS += test^make^step5 # no TCO capability/step
36EXCLUDE_TESTS += test^mal^step5 # no TCO capability/step
dbac60df
JM
37EXCLUDE_TESTS += test^miniMAL^step5 # strange error with runtest.py
38EXCLUDE_TESTS += test^nim^step5 # test completes, even at 100,000
17e1c5f9 39EXCLUDE_TESTS += test^go^step5 # test completes, even at 100,000
cc021efe 40EXCLUDE_TESTS += test^php^step5 # test completes, even at 100,000
7907cd90 41EXCLUDE_TESTS += test^racket^step5 # test completes
cc021efe 42EXCLUDE_TESTS += test^ruby^step5 # test completes, even at 100,000
a77e2b31 43EXCLUDE_TESTS += test^rust^step5 # no catching stack overflows
44d4e31f 44EXCLUDE_TESTS += test^ocaml^step5 # test completes, even at 1,000,000
dbac60df 45EXCLUDE_TESTS += test^vb^step5 # completes at 10,000
cc021efe 46
db4c329a 47EXCLUDE_PERFS = perf^mal # TODO: fix this
31690700
JM
48
49#
50# Utility functions
51#
52
53STEP_TEST_FILES = $(strip $(wildcard $(1)/tests/$($(2)).mal) $(wildcard tests/$($(2)).mal))
54
db4c329a
JM
55bash_STEP_TO_PROG = bash/$($(1)).sh
56c_STEP_TO_PROG = c/$($(1))
31690700 57clojure_STEP_TO_PROG = clojure/src/$($(1)).clj
891c3f3b 58coffee_STEP_TO_PROG = coffee/$($(1)).coffee
9ddaa0b9 59cpp_STEP_TO_PROG = cpp/$($(1))
db4c329a 60cs_STEP_TO_PROG = cs/$($(1)).exe
59038a10 61forth_STEP_TO_PROG = forth/$($(1)).fs
1c358979 62fsharp_STEP_TO_PROG = fsharp/$($(1)).exe
69b4abd6 63go_STEP_TO_PROG = go/$($(1))
db4c329a 64java_STEP_TO_PROG = java/src/main/java/mal/$($(1)).java
b76aa73b 65haskell_STEP_TO_PROG = haskell/$($(1))
a23e0cdb 66julia_STEP_TO_PROG = julia/$($(1)).jl
db4c329a 67js_STEP_TO_PROG = js/$($(1)).js
9d42904e 68lua_STEP_TO_PROG = lua/$($(1)).lua
db4c329a
JM
69make_STEP_TO_PROG = make/$($(1)).mk
70mal_STEP_TO_PROG = mal/$($(1)).mal
59d10e1b 71ocaml_STEP_TO_PROG = ocaml/$($(1))
9a54ea18 72matlab_STEP_TO_PROG = matlab/$($(1)).m
c1fe72ae 73miniMAL_STEP_TO_PROG = miniMAL/$($(1)).json
dbac60df 74nim_STEP_TO_PROG = nim/$($(1))
b5dedee0 75perl_STEP_TO_PROG = perl/$($(1)).pl
db4c329a
JM
76php_STEP_TO_PROG = php/$($(1)).php
77ps_STEP_TO_PROG = ps/$($(1)).ps
78python_STEP_TO_PROG = python/$($(1)).py
4d1456b9 79r_STEP_TO_PROG = r/$($(1)).r
f5223195 80racket_STEP_TO_PROG = racket/$($(1)).rkt
db4c329a 81ruby_STEP_TO_PROG = ruby/$($(1)).rb
434516e0 82rust_STEP_TO_PROG = rust/target/release/$($(1))
821930db 83scala_STEP_TO_PROG = scala/$($(1)).scala
2539e6af 84swift_STEP_TO_PROG = swift/$($(1))
ee7cd585 85vb_STEP_TO_PROG = vb/$($(1)).exe
db4c329a 86
c4033aab
JM
87# Needed some argument munging
88COMMA = ,
89noop =
90SPACE = $(noop) $(noop)
db4c329a
JM
91
92bash_RUNSTEP = bash ../$(2) $(3)
93c_RUNSTEP = ../$(2) $(3)
94clojure_RUNSTEP = lein with-profile +$(1) trampoline run $(3)
891c3f3b 95coffee_RUNSTEP = coffee ../$(2) $(3)
9ddaa0b9 96cpp_RUNSTEP = ../$(2) $(3)
db4c329a 97cs_RUNSTEP = mono ../$(2) --raw $(3)
59038a10 98forth_RUNSTEP = gforth ../$(2) $(3)
1c358979 99fsharp_RUNSTEP = mono ../$(2) --raw $(3)
69b4abd6 100go_RUNSTEP = ../$(2) $(3)
b76aa73b 101haskell_RUNSTEP = ../$(2) $(3)
798206ac 102java_RUNSTEP = mvn -quiet exec:java -Dexec.mainClass="mal.$($(1))" $(if $(3), -Dexec.args="$(3)",)
a23e0cdb 103julia_RUNSTEP = ../$(2) $(3)
db4c329a 104js_RUNSTEP = node ../$(2) $(3)
798206ac 105lua_RUNSTEP = ../$(2) $(3)
db4c329a
JM
106make_RUNSTEP = make -f ../$(2) $(3)
107mal_RUNSTEP = $(call $(MAL_IMPL)_RUNSTEP,$(1),$(call $(MAL_IMPL)_STEP_TO_PROG,stepA),../$(2),") #"
59d10e1b 108ocaml_RUNSTEP = ../$(2) $(3)
7f567f36
JM
109matlab_args = $(subst $(SPACE),$(COMMA),$(foreach x,$(strip $(1)),'$(x)'))
110matlab_RUNSTEP = matlab -nodisplay -nosplash -nodesktop -nojvm -r "$($(1))($(call matlab_args,$(3)));quit;"
c1fe72ae 111miniMAL_RUNSTEP = miniMAL ../$(2) $(3)
dbac60df 112nim_RUNSTEP = ../$(2) $(3)
82acd3de 113perl_RUNSTEP = perl ../$(2) $(3)
db4c329a 114php_RUNSTEP = php ../$(2) $(3)
01c97316 115ps_RUNSTEP = $(4)gs -q -I./ -dNODISPLAY -- ../$(2) $(3)$(4)
db4c329a 116python_RUNSTEP = $(PYTHON) ../$(2) $(3)
4d1456b9 117r_RUNSTEP = Rscript ../$(2) $(3)
f5223195 118racket_RUNSTEP = ../$(2) $(3)
db4c329a 119ruby_RUNSTEP = ruby ../$(2) $(3)
abdd56eb 120rust_RUNSTEP = ../$(2) $(3)
821930db 121scala_RUNSTEP = sbt 'run-main $($(1))$(if $(3), $(3),)'
2539e6af 122swift_RUNSTEP = ../$(2) $(3)
ee7cd585 123vb_RUNSTEP = mono ../$(2) --raw $(3)
db4c329a
JM
124
125# Extra options to pass to runtest.py
7907cd90 126mal_TEST_OPTS = --start-timeout 60 --test-timeout 120
31690700
JM
127
128
129# Derived lists
130STEPS = $(sort $(filter step%,$(.VARIABLES)))
8569b2af
JM
131DO_IMPLS = $(filter-out $(SKIP_IMPLS),$(IMPLS))
132IMPL_TESTS = $(foreach impl,$(DO_IMPLS),test^$(impl))
31690700
JM
133STEP_TESTS = $(foreach step,$(STEPS),test^$(step))
134ALL_TESTS = $(filter-out $(EXCLUDE_TESTS),\
135 $(strip $(sort \
8569b2af 136 $(foreach impl,$(DO_IMPLS),\
31690700
JM
137 $(foreach step,$(STEPS),test^$(impl)^$(step))))))
138
8569b2af
JM
139IMPL_STATS = $(foreach impl,$(DO_IMPLS),stats^$(impl))
140IMPL_STATS_LISP = $(foreach impl,$(DO_IMPLS),stats-lisp^$(impl))
31690700 141
8569b2af 142IMPL_PERF = $(filter-out $(EXCLUDE_PERFS),$(foreach impl,$(DO_IMPLS),perf^$(impl)))
db4c329a 143
31690700
JM
144#
145# Build rules
146#
147
148# Build a program in 'c' directory
149c/%:
150 $(MAKE) -C $(dir $(@)) $(notdir $(@))
151
9ddaa0b9
ST
152# Build a program in 'cpp' directory
153cpp/%:
154 $(MAKE) -C $(dir $(@)) $(notdir $(@))
155
31690700
JM
156# Allow test, test^STEP, test^IMPL, and test^IMPL^STEP
157.SECONDEXPANSION:
158$(IMPL_TESTS): $$(filter $$@^%,$$(ALL_TESTS))
159
160.SECONDEXPANSION:
161$(STEP_TESTS): $$(foreach step,$$(subst test^,,$$@),$$(filter %^$$(step),$$(ALL_TESTS)))
162
163.SECONDEXPANSION:
164$(ALL_TESTS): $$(call $$(word 2,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 3,$$(subst ^, ,$$(@))))
165 @$(foreach impl,$(word 2,$(subst ^, ,$(@))),\
166 $(foreach step,$(word 3,$(subst ^, ,$(@))),\
167 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
168 $(foreach test,$(call STEP_TEST_FILES,$(impl),$(step)),\
169 echo '----------------------------------------------'; \
170 echo 'Testing $@, step file: $+, test file: $(test)'; \
db4c329a 171 echo 'Running: ../runtest.py $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+))'; \
dbac60df 172 ../runtest.py $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+));)))
31690700
JM
173
174test: $(ALL_TESTS)
175tests: $(ALL_TESTS)
176
177
178# Stats rules
179
db4c329a
JM
180stats: $(IMPL_STATS)
181stats-lisp: $(IMPL_STATS_LISP)
182
31690700
JM
183.SECONDEXPANSION:
184$(IMPL_STATS):
185 @echo "----------------------------------------------"; \
186 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
187 echo "Stats for $(impl):"; \
188 $(MAKE) --no-print-directory -C $(impl) stats)
189
712af9ef
JM
190.SECONDEXPANSION:
191$(IMPL_STATS_LISP):
192 @echo "----------------------------------------------"; \
193 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
194 echo "Stats (lisp only) for $(impl):"; \
195 $(MAKE) --no-print-directory -C $(impl) stats-lisp)
196
db4c329a
JM
197
198# Performance test rules
199
200perf: $(IMPL_PERF)
201
202.SECONDEXPANSION:
203$(IMPL_PERF):
204 @echo "----------------------------------------------"; \
205 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
206 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
207 echo "Performance test for $(impl):"; \
208 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal)'; \
209 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal); \
210 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal)'; \
699f0ad2
JM
211 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal); \
212 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal)'; \
213 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal))
db4c329a 214