Merge pull request #88 from keith-rollin/optimize
[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
51c2c1fe 13IMPLS = awk bash c clojure coffee cpp crystal cs erlang elixir es6 factor forth fsharp go groovy \
a9cd6543 14 haskell java julia js lua make mal ocaml matlab miniMAL nim \
80320efc 15 perl php ps python r racket rpython ruby rust scala swift vb guile
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
3b7ef8c7 29EXCLUDE_TESTS += test^awk^step5 # completes at 10,000
cc021efe
JM
30EXCLUDE_TESTS += test^bash^step5 # no stack exhaustion or completion
31EXCLUDE_TESTS += test^c^step5 # segfault
0fbd1b81 32EXCLUDE_TESTS += test^cpp^step5 # completes at 10,000
cc021efe 33EXCLUDE_TESTS += test^cs^step5 # fatal stack overflow fault
e07b9830 34EXCLUDE_TESTS += test^erlang^step5 # erlang is TCO, test passes
d88bc831 35EXCLUDE_TESTS += test^elixir^step5 # elixir is TCO, test passes
8862f80e 36EXCLUDE_TESTS += test^fsharp^step5 # completes at 10,000, fatal stack overflow at 100,000
7907cd90 37EXCLUDE_TESTS += test^haskell^step5 # test completes
cc021efe
JM
38EXCLUDE_TESTS += test^make^step5 # no TCO capability/step
39EXCLUDE_TESTS += test^mal^step5 # no TCO capability/step
dbac60df
JM
40EXCLUDE_TESTS += test^miniMAL^step5 # strange error with runtest.py
41EXCLUDE_TESTS += test^nim^step5 # test completes, even at 100,000
17e1c5f9 42EXCLUDE_TESTS += test^go^step5 # test completes, even at 100,000
cc021efe 43EXCLUDE_TESTS += test^php^step5 # test completes, even at 100,000
7907cd90 44EXCLUDE_TESTS += test^racket^step5 # test completes
cc021efe 45EXCLUDE_TESTS += test^ruby^step5 # test completes, even at 100,000
a77e2b31 46EXCLUDE_TESTS += test^rust^step5 # no catching stack overflows
44d4e31f 47EXCLUDE_TESTS += test^ocaml^step5 # test completes, even at 1,000,000
dbac60df 48EXCLUDE_TESTS += test^vb^step5 # completes at 10,000
725ee0bd 49EXCLUDE_TESTS += test^crystal^step5 # test completes, even at 1,000,000
cc021efe 50
db4c329a 51EXCLUDE_PERFS = perf^mal # TODO: fix this
31690700
JM
52
53#
54# Utility functions
55#
56
57STEP_TEST_FILES = $(strip $(wildcard $(1)/tests/$($(2)).mal) $(wildcard tests/$($(2)).mal))
58
3b7ef8c7 59awk_STEP_TO_PROG = awk/$($(1)).awk
db4c329a
JM
60bash_STEP_TO_PROG = bash/$($(1)).sh
61c_STEP_TO_PROG = c/$($(1))
31690700 62clojure_STEP_TO_PROG = clojure/src/$($(1)).clj
891c3f3b 63coffee_STEP_TO_PROG = coffee/$($(1)).coffee
9ddaa0b9 64cpp_STEP_TO_PROG = cpp/$($(1))
86fe6314 65crystal_STEP_TO_PROG = crystal/$($(1))
db4c329a 66cs_STEP_TO_PROG = cs/$($(1)).exe
51c2c1fe 67elixir_STEP_TO_PROG = elixir/lib/mix/tasks/$($(1)).ex
2cc3804b 68erlang_STEP_TO_PROG = erlang/$($(1))
4eb71990 69es6_STEP_TO_PROG = es6/build/$($(1)).js
389c9b8a 70factor_STEP_TO_PROG = factor/src/$($(1))/$($(1)).factor
59038a10 71forth_STEP_TO_PROG = forth/$($(1)).fs
1c358979 72fsharp_STEP_TO_PROG = fsharp/$($(1)).exe
69b4abd6 73go_STEP_TO_PROG = go/$($(1))
a9cd6543 74groovy_STEP_TO_PROG = groovy/$($(1)).groovy
db4c329a 75java_STEP_TO_PROG = java/src/main/java/mal/$($(1)).java
b76aa73b 76haskell_STEP_TO_PROG = haskell/$($(1))
a23e0cdb 77julia_STEP_TO_PROG = julia/$($(1)).jl
db4c329a 78js_STEP_TO_PROG = js/$($(1)).js
9d42904e 79lua_STEP_TO_PROG = lua/$($(1)).lua
db4c329a
JM
80make_STEP_TO_PROG = make/$($(1)).mk
81mal_STEP_TO_PROG = mal/$($(1)).mal
59d10e1b 82ocaml_STEP_TO_PROG = ocaml/$($(1))
9a54ea18 83matlab_STEP_TO_PROG = matlab/$($(1)).m
c1fe72ae 84miniMAL_STEP_TO_PROG = miniMAL/$($(1)).json
dbac60df 85nim_STEP_TO_PROG = nim/$($(1))
b5dedee0 86perl_STEP_TO_PROG = perl/$($(1)).pl
db4c329a
JM
87php_STEP_TO_PROG = php/$($(1)).php
88ps_STEP_TO_PROG = ps/$($(1)).ps
89python_STEP_TO_PROG = python/$($(1)).py
4d1456b9 90r_STEP_TO_PROG = r/$($(1)).r
f5223195 91racket_STEP_TO_PROG = racket/$($(1)).rkt
80320efc 92rpython_STEP_TO_PROG = rpython/$($(1))
db4c329a 93ruby_STEP_TO_PROG = ruby/$($(1)).rb
434516e0 94rust_STEP_TO_PROG = rust/target/release/$($(1))
821930db 95scala_STEP_TO_PROG = scala/$($(1)).scala
2539e6af 96swift_STEP_TO_PROG = swift/$($(1))
ee7cd585 97vb_STEP_TO_PROG = vb/$($(1)).exe
5eb1f5cb 98guile_STEP_TO_PROG = guile/$($(1)).scm
db4c329a 99
c4033aab
JM
100# Needed some argument munging
101COMMA = ,
102noop =
103SPACE = $(noop) $(noop)
389c9b8a 104export FACTOR_ROOTS := src
db4c329a 105
3b7ef8c7 106awk_RUNSTEP = awk -O -f ../$(2) $(3)
db4c329a
JM
107bash_RUNSTEP = bash ../$(2) $(3)
108c_RUNSTEP = ../$(2) $(3)
109clojure_RUNSTEP = lein with-profile +$(1) trampoline run $(3)
891c3f3b 110coffee_RUNSTEP = coffee ../$(2) $(3)
9ddaa0b9 111cpp_RUNSTEP = ../$(2) $(3)
86fe6314 112crystal_RUNSTEP = ../$(2) $(3)
db4c329a 113cs_RUNSTEP = mono ../$(2) --raw $(3)
df2ca97b 114elixir_RUNSTEP = mix $(notdir $(basename $(2))) $(3)
2cc3804b 115erlang_RUNSTEP = ../$(2) $(3)
4eb71990 116es6_RUNSTEP = node ../$(2) $(3)
389c9b8a 117factor_RUNSTEP = factor ../$(2) $(3)
59038a10 118forth_RUNSTEP = gforth ../$(2) $(3)
1c358979 119fsharp_RUNSTEP = mono ../$(2) --raw $(3)
69b4abd6 120go_RUNSTEP = ../$(2) $(3)
a9cd6543 121groovy_RUNSTEP = groovy ../$(2) $(3)
b76aa73b 122haskell_RUNSTEP = ../$(2) $(3)
798206ac 123java_RUNSTEP = mvn -quiet exec:java -Dexec.mainClass="mal.$($(1))" $(if $(3), -Dexec.args="$(3)",)
a23e0cdb 124julia_RUNSTEP = ../$(2) $(3)
db4c329a 125js_RUNSTEP = node ../$(2) $(3)
798206ac 126lua_RUNSTEP = ../$(2) $(3)
db4c329a
JM
127make_RUNSTEP = make -f ../$(2) $(3)
128mal_RUNSTEP = $(call $(MAL_IMPL)_RUNSTEP,$(1),$(call $(MAL_IMPL)_STEP_TO_PROG,stepA),../$(2),") #"
59d10e1b 129ocaml_RUNSTEP = ../$(2) $(3)
7f567f36
JM
130matlab_args = $(subst $(SPACE),$(COMMA),$(foreach x,$(strip $(1)),'$(x)'))
131matlab_RUNSTEP = matlab -nodisplay -nosplash -nodesktop -nojvm -r "$($(1))($(call matlab_args,$(3)));quit;"
c1fe72ae 132miniMAL_RUNSTEP = miniMAL ../$(2) $(3)
dbac60df 133nim_RUNSTEP = ../$(2) $(3)
82acd3de 134perl_RUNSTEP = perl ../$(2) $(3)
db4c329a 135php_RUNSTEP = php ../$(2) $(3)
01c97316 136ps_RUNSTEP = $(4)gs -q -I./ -dNODISPLAY -- ../$(2) $(3)$(4)
db4c329a 137python_RUNSTEP = $(PYTHON) ../$(2) $(3)
4d1456b9 138r_RUNSTEP = Rscript ../$(2) $(3)
f5223195 139racket_RUNSTEP = ../$(2) $(3)
80320efc 140rpython_RUNSTEP = ../$(2) $(3)
db4c329a 141ruby_RUNSTEP = ruby ../$(2) $(3)
abdd56eb 142rust_RUNSTEP = ../$(2) $(3)
821930db 143scala_RUNSTEP = sbt 'run-main $($(1))$(if $(3), $(3),)'
2539e6af 144swift_RUNSTEP = ../$(2) $(3)
ee7cd585 145vb_RUNSTEP = mono ../$(2) --raw $(3)
5eb1f5cb 146# needs TERM=dumb to work with readline
44af092c 147guile_RUNSTEP = guile -L ../guile ../$(2) $(3)
db4c329a
JM
148
149# Extra options to pass to runtest.py
7907cd90 150mal_TEST_OPTS = --start-timeout 60 --test-timeout 120
31690700
JM
151
152
153# Derived lists
154STEPS = $(sort $(filter step%,$(.VARIABLES)))
8569b2af
JM
155DO_IMPLS = $(filter-out $(SKIP_IMPLS),$(IMPLS))
156IMPL_TESTS = $(foreach impl,$(DO_IMPLS),test^$(impl))
31690700
JM
157STEP_TESTS = $(foreach step,$(STEPS),test^$(step))
158ALL_TESTS = $(filter-out $(EXCLUDE_TESTS),\
159 $(strip $(sort \
8569b2af 160 $(foreach impl,$(DO_IMPLS),\
31690700
JM
161 $(foreach step,$(STEPS),test^$(impl)^$(step))))))
162
8569b2af
JM
163IMPL_STATS = $(foreach impl,$(DO_IMPLS),stats^$(impl))
164IMPL_STATS_LISP = $(foreach impl,$(DO_IMPLS),stats-lisp^$(impl))
31690700 165
8569b2af 166IMPL_PERF = $(filter-out $(EXCLUDE_PERFS),$(foreach impl,$(DO_IMPLS),perf^$(impl)))
db4c329a 167
31690700
JM
168#
169# Build rules
170#
171
4fc7a281
JM
172# Build a program in an implementation directory
173$(foreach i,$(DO_IMPLS),$(foreach s,$(STEPS),$(call $(i)_STEP_TO_PROG,$(s)))):
9ddaa0b9
ST
174 $(MAKE) -C $(dir $(@)) $(notdir $(@))
175
31690700
JM
176# Allow test, test^STEP, test^IMPL, and test^IMPL^STEP
177.SECONDEXPANSION:
178$(IMPL_TESTS): $$(filter $$@^%,$$(ALL_TESTS))
179
180.SECONDEXPANSION:
181$(STEP_TESTS): $$(foreach step,$$(subst test^,,$$@),$$(filter %^$$(step),$$(ALL_TESTS)))
182
183.SECONDEXPANSION:
184$(ALL_TESTS): $$(call $$(word 2,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 3,$$(subst ^, ,$$(@))))
185 @$(foreach impl,$(word 2,$(subst ^, ,$(@))),\
186 $(foreach step,$(word 3,$(subst ^, ,$(@))),\
187 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
188 $(foreach test,$(call STEP_TEST_FILES,$(impl),$(step)),\
189 echo '----------------------------------------------'; \
190 echo 'Testing $@, step file: $+, test file: $(test)'; \
db4c329a 191 echo 'Running: ../runtest.py $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+))'; \
dbac60df 192 ../runtest.py $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+));)))
31690700
JM
193
194test: $(ALL_TESTS)
195tests: $(ALL_TESTS)
196
197
198# Stats rules
199
db4c329a
JM
200stats: $(IMPL_STATS)
201stats-lisp: $(IMPL_STATS_LISP)
202
31690700
JM
203.SECONDEXPANSION:
204$(IMPL_STATS):
205 @echo "----------------------------------------------"; \
206 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
207 echo "Stats for $(impl):"; \
208 $(MAKE) --no-print-directory -C $(impl) stats)
209
712af9ef
JM
210.SECONDEXPANSION:
211$(IMPL_STATS_LISP):
212 @echo "----------------------------------------------"; \
213 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
214 echo "Stats (lisp only) for $(impl):"; \
215 $(MAKE) --no-print-directory -C $(impl) stats-lisp)
216
db4c329a
JM
217
218# Performance test rules
219
220perf: $(IMPL_PERF)
221
222.SECONDEXPANSION:
223$(IMPL_PERF):
224 @echo "----------------------------------------------"; \
225 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
226 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
227 echo "Performance test for $(impl):"; \
228 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal)'; \
229 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal); \
230 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal)'; \
699f0ad2
JM
231 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal); \
232 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal)'; \
233 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal))