swift3: steps6-A, vectors, maps, keywords, meta.
[jackhill/mal.git] / Makefile
CommitLineData
31690700
JM
1#
2# Command line settings
3#
4
5MAL_IMPL = js
6
a05f7822 7PYTHON = python
47699629 8USE_MATLAB =
32d0a1cf
JM
9# python, js, cpp, or neko are currently supported
10HAXE_MODE = neko
a05f7822 11
337c8031
JM
12# Extra options to pass to runtest.py
13TEST_OPTS =
14
17180e85
JM
15# Test with previous test files not just the test files for the
16# current step. Step 0 and 1 tests are special and not included in
17# later steps.
18REGRESS=
19
337c8031
JM
20# Extra implementation specific options to pass to runtest.py
21mal_TEST_OPTS = --start-timeout 60 --test-timeout 120
22
31690700
JM
23#
24# Settings
25#
26
6c4c14bd
JM
27IMPLS = awk bash c d clojure coffee cpp crystal cs erlang elixir es6 \
28 factor forth fsharp go groovy guile haskell haxe java julia \
29 js kotlin lua make mal ocaml matlab miniMAL nim perl php ps \
0eace3df 30 python r racket rpython ruby rust scala swift swift3 tcl vb vimscript
31690700
JM
31
32step0 = step0_repl
33step1 = step1_read_print
34step2 = step2_eval
35step3 = step3_env
36step4 = step4_if_fn_do
37step5 = step5_tco
38step6 = step6_file
39step7 = step7_quote
40step8 = step8_macros
01c97316 41step9 = step9_try
90f618cb 42stepA = stepA_mal
31690700 43
17180e85
JM
44regress_step0 = step0
45regress_step1 = step1
46regress_step2 = step2
47regress_step3 = $(regress_step2) step3
48regress_step4 = $(regress_step3) step4
49regress_step5 = $(regress_step4) step5
50regress_step6 = $(regress_step5) step6
51regress_step7 = $(regress_step6) step7
52regress_step8 = $(regress_step7) step8
53regress_step9 = $(regress_step8) step9
54regress_stepA = $(regress_step9) stepA
55
56STEP5_EXCLUDES += awk # completes at 10,000
57STEP5_EXCLUDES += bash # no stack exhaustion or completion
58STEP5_EXCLUDES += c # segfault
59STEP5_EXCLUDES += cpp # completes at 10,000
60STEP5_EXCLUDES += cs # fatal stack overflow fault
61STEP5_EXCLUDES += d # completes at 10,000, fatal stack overflow at 1,000,000
62STEP5_EXCLUDES += erlang # erlang is TCO, test passes
63STEP5_EXCLUDES += elixir # elixir is TCO, test passes
64STEP5_EXCLUDES += fsharp # completes at 10,000, fatal stack overflow at 100,000
65STEP5_EXCLUDES += haskell # test completes
66STEP5_EXCLUDES += make # no TCO capability/step
67STEP5_EXCLUDES += mal # no TCO capability/step
47699629 68STEP5_EXCLUDES += matlab # too slow to complete 10,000
17180e85
JM
69STEP5_EXCLUDES += miniMAL # strange error with runtest.py
70STEP5_EXCLUDES += nim # test completes, even at 100,000
71STEP5_EXCLUDES += go # test completes, even at 100,000
72STEP5_EXCLUDES += php # test completes, even at 100,000
73STEP5_EXCLUDES += racket # test completes
74STEP5_EXCLUDES += ruby # test completes, even at 100,000
75STEP5_EXCLUDES += rust # no catching stack overflows
0eace3df 76STEP5_EXCLUDES += swift3 # no catching stack overflows
17180e85
JM
77STEP5_EXCLUDES += ocaml # test completes, even at 1,000,000
78STEP5_EXCLUDES += vb # completes at 10,000
79STEP5_EXCLUDES += crystal # test completes, even at 1,000,000
80
81PERF_EXCLUDES = mal # TODO: fix this
31690700
JM
82
83#
84# Utility functions
85#
86
47699629
JM
87MATLAB = matlab -nodisplay -nosplash -nodesktop -nojvm -r
88OCTAVE = octave --no-gui -q --traditional --eval
89matlab_args = $(subst $(SPACE),$(COMMA),$(foreach x,$(strip $(1)),'$(x)'))
90matlab_cmd = $(if $(strip $(USE_MATLAB)),$(MATLAB),$(OCTAVE))
91
32d0a1cf
JM
92haxe_STEP_TO_PROG_neko = haxe/$($(1)).n
93haxe_STEP_TO_PROG_python = haxe/$($(1)).py
94haxe_STEP_TO_PROG_cpp = haxe/cpp/$($(1))
95haxe_STEP_TO_PROG_js = haxe/$($(1)).js
96
97haxe_RUNSTEP_neko = neko ../$(2) $(3)
98haxe_RUNSTEP_python = python3 ../$(2) $(3)
99haxe_RUNSTEP_cpp = ../$(2) $(3)
100haxe_RUNSTEP_js = node ../$(2) $(3)
101
17180e85
JM
102# Return list of test files for a given step. If REGRESS is set then
103# test files will include step 2 tests through tests for the step
104# being tested.
105STEP_TEST_FILES = $(strip $(wildcard \
106 $(foreach s,$(if $(strip $(REGRESS)),$(regress_$(2)),$(2)),\
107 $(1)/tests/$($(s)).mal tests/$($(s)).mal)))
31690700 108
17180e85 109# Map of step (e.g. "step8") to executable file for that step
3b7ef8c7 110awk_STEP_TO_PROG = awk/$($(1)).awk
db4c329a
JM
111bash_STEP_TO_PROG = bash/$($(1)).sh
112c_STEP_TO_PROG = c/$($(1))
f82cb965 113d_STEP_TO_PROG = d/$($(1))
31690700 114clojure_STEP_TO_PROG = clojure/src/$($(1)).clj
891c3f3b 115coffee_STEP_TO_PROG = coffee/$($(1)).coffee
9ddaa0b9 116cpp_STEP_TO_PROG = cpp/$($(1))
86fe6314 117crystal_STEP_TO_PROG = crystal/$($(1))
db4c329a 118cs_STEP_TO_PROG = cs/$($(1)).exe
51c2c1fe 119elixir_STEP_TO_PROG = elixir/lib/mix/tasks/$($(1)).ex
2cc3804b 120erlang_STEP_TO_PROG = erlang/$($(1))
4eb71990 121es6_STEP_TO_PROG = es6/build/$($(1)).js
199b1ce7 122factor_STEP_TO_PROG = factor/$($(1))/$($(1)).factor
59038a10 123forth_STEP_TO_PROG = forth/$($(1)).fs
1c358979 124fsharp_STEP_TO_PROG = fsharp/$($(1)).exe
69b4abd6 125go_STEP_TO_PROG = go/$($(1))
a9cd6543 126groovy_STEP_TO_PROG = groovy/$($(1)).groovy
36e287b5 127java_STEP_TO_PROG = java/target/classes/mal/$($(1)).class
b76aa73b 128haskell_STEP_TO_PROG = haskell/$($(1))
32d0a1cf 129haxe_STEP_TO_PROG = $(haxe_STEP_TO_PROG_$(HAXE_MODE))
a23e0cdb 130julia_STEP_TO_PROG = julia/$($(1)).jl
db4c329a 131js_STEP_TO_PROG = js/$($(1)).js
53c2ea70 132kotlin_STEP_TO_PROG = kotlin/$($(1)).jar
9d42904e 133lua_STEP_TO_PROG = lua/$($(1)).lua
db4c329a
JM
134make_STEP_TO_PROG = make/$($(1)).mk
135mal_STEP_TO_PROG = mal/$($(1)).mal
59d10e1b 136ocaml_STEP_TO_PROG = ocaml/$($(1))
9a54ea18 137matlab_STEP_TO_PROG = matlab/$($(1)).m
c1fe72ae 138miniMAL_STEP_TO_PROG = miniMAL/$($(1)).json
dbac60df 139nim_STEP_TO_PROG = nim/$($(1))
b5dedee0 140perl_STEP_TO_PROG = perl/$($(1)).pl
db4c329a
JM
141php_STEP_TO_PROG = php/$($(1)).php
142ps_STEP_TO_PROG = ps/$($(1)).ps
143python_STEP_TO_PROG = python/$($(1)).py
4d1456b9 144r_STEP_TO_PROG = r/$($(1)).r
f5223195 145racket_STEP_TO_PROG = racket/$($(1)).rkt
80320efc 146rpython_STEP_TO_PROG = rpython/$($(1))
db4c329a 147ruby_STEP_TO_PROG = ruby/$($(1)).rb
434516e0 148rust_STEP_TO_PROG = rust/target/release/$($(1))
821930db 149scala_STEP_TO_PROG = scala/$($(1)).scala
2539e6af 150swift_STEP_TO_PROG = swift/$($(1))
0eace3df 151swift3_STEP_TO_PROG = swift3/$($(1))
54d9903c 152tcl_STEP_TO_PROG = tcl/$($(1)).tcl
ee7cd585 153vb_STEP_TO_PROG = vb/$($(1)).exe
50a964ce 154vimscript_STEP_TO_PROG = vimscript/$($(1)).vim
5eb1f5cb 155guile_STEP_TO_PROG = guile/$($(1)).scm
db4c329a 156
17180e85 157
c4033aab
JM
158# Needed some argument munging
159COMMA = ,
160noop =
161SPACE = $(noop) $(noop)
d1596ac2 162export FACTOR_ROOTS := .
db4c329a 163
17180e85
JM
164# Macro for running a step:
165# $(1): step (e.g. "stepA")
166# $(2): program for step (e.g. result of *_STEP_TO_PROG
167# $(3): program arguments
3b7ef8c7 168awk_RUNSTEP = awk -O -f ../$(2) $(3)
db4c329a
JM
169bash_RUNSTEP = bash ../$(2) $(3)
170c_RUNSTEP = ../$(2) $(3)
f82cb965 171d_RUNSTEP = ../$(2) $(3)
db4c329a 172clojure_RUNSTEP = lein with-profile +$(1) trampoline run $(3)
891c3f3b 173coffee_RUNSTEP = coffee ../$(2) $(3)
9ddaa0b9 174cpp_RUNSTEP = ../$(2) $(3)
86fe6314 175crystal_RUNSTEP = ../$(2) $(3)
db4c329a 176cs_RUNSTEP = mono ../$(2) --raw $(3)
df2ca97b 177elixir_RUNSTEP = mix $(notdir $(basename $(2))) $(3)
2cc3804b 178erlang_RUNSTEP = ../$(2) $(3)
4eb71990 179es6_RUNSTEP = node ../$(2) $(3)
389c9b8a 180factor_RUNSTEP = factor ../$(2) $(3)
59038a10 181forth_RUNSTEP = gforth ../$(2) $(3)
1c358979 182fsharp_RUNSTEP = mono ../$(2) --raw $(3)
69b4abd6 183go_RUNSTEP = ../$(2) $(3)
a9cd6543 184groovy_RUNSTEP = groovy ../$(2) $(3)
b76aa73b 185haskell_RUNSTEP = ../$(2) $(3)
6c4c14bd 186haxe_RUNSTEP = python3 ../$(2) $(3)
32d0a1cf 187haxe_RUNSTEP = $(haxe_RUNSTEP_$(HAXE_MODE))
798206ac 188java_RUNSTEP = mvn -quiet exec:java -Dexec.mainClass="mal.$($(1))" $(if $(3), -Dexec.args="$(3)",)
a23e0cdb 189julia_RUNSTEP = ../$(2) $(3)
db4c329a 190js_RUNSTEP = node ../$(2) $(3)
53c2ea70 191kotlin_RUNSTEP = java -jar ../$(2) $(3)
798206ac 192lua_RUNSTEP = ../$(2) $(3)
db4c329a 193make_RUNSTEP = make -f ../$(2) $(3)
922d4c3b 194mal_RUNSTEP = $(call $(MAL_IMPL)_RUNSTEP,stepA,$(call $(MAL_IMPL)_STEP_TO_PROG,stepA),../$(2),") #"
59d10e1b 195ocaml_RUNSTEP = ../$(2) $(3)
47699629 196matlab_RUNSTEP = $(matlab_cmd) "$($(1))($(call matlab_args,$(3)));quit;"
c1fe72ae 197miniMAL_RUNSTEP = miniMAL ../$(2) $(3)
dbac60df 198nim_RUNSTEP = ../$(2) $(3)
82acd3de 199perl_RUNSTEP = perl ../$(2) $(3)
db4c329a 200php_RUNSTEP = php ../$(2) $(3)
406761e7 201ps_RUNSTEP = gs -q -I./ -dNODISPLAY -- ../$(2) $(3)
db4c329a 202python_RUNSTEP = $(PYTHON) ../$(2) $(3)
4d1456b9 203r_RUNSTEP = Rscript ../$(2) $(3)
f5223195 204racket_RUNSTEP = ../$(2) $(3)
80320efc 205rpython_RUNSTEP = ../$(2) $(3)
db4c329a 206ruby_RUNSTEP = ruby ../$(2) $(3)
abdd56eb 207rust_RUNSTEP = ../$(2) $(3)
821930db 208scala_RUNSTEP = sbt 'run-main $($(1))$(if $(3), $(3),)'
2539e6af 209swift_RUNSTEP = ../$(2) $(3)
0eace3df 210swift3_RUNSTEP = ../$(2) $(3)
576ef370 211tcl_RUNSTEP = tclsh ../$(2) --raw $(3)
ee7cd585 212vb_RUNSTEP = mono ../$(2) --raw $(3)
50a964ce 213vimscript_RUNSTEP = ./run_vimscript.sh ../$(2) $(3)
5eb1f5cb 214# needs TERM=dumb to work with readline
337c8031 215guile_RUNSTEP = guile --no-auto-compile -L ../guile ../$(2) $(3)
db4c329a 216
31690700 217
50a964ce
DM
218vimscript_TEST_OPTS = --test-timeout 30
219ifeq ($(MAL_IMPL),vimscript)
220mal_TEST_OPTS = --start-timeout 60 --test-timeout 180
221endif
31690700
JM
222
223# Derived lists
224STEPS = $(sort $(filter step%,$(.VARIABLES)))
8569b2af
JM
225DO_IMPLS = $(filter-out $(SKIP_IMPLS),$(IMPLS))
226IMPL_TESTS = $(foreach impl,$(DO_IMPLS),test^$(impl))
31690700 227STEP_TESTS = $(foreach step,$(STEPS),test^$(step))
17180e85 228ALL_TESTS = $(filter-out $(foreach impl,$(STEP5_EXCLUDES),test^$(impl)^step5),\
31690700 229 $(strip $(sort \
8569b2af 230 $(foreach impl,$(DO_IMPLS),\
31690700
JM
231 $(foreach step,$(STEPS),test^$(impl)^$(step))))))
232
8569b2af
JM
233IMPL_STATS = $(foreach impl,$(DO_IMPLS),stats^$(impl))
234IMPL_STATS_LISP = $(foreach impl,$(DO_IMPLS),stats-lisp^$(impl))
31690700 235
cf1d3eae
JM
236DOCKER_BUILD = $(foreach impl,$(DO_IMPLS),docker-build^$(impl))
237
17180e85 238IMPL_PERF = $(foreach impl,$(filter-out $(PERF_EXCLUDES),$(DO_IMPLS)),perf^$(impl))
db4c329a 239
854cf2a6
DM
240IMPL_REPL = $(foreach impl,$(DO_IMPLS),repl^$(impl))
241ALL_REPL = $(strip $(sort \
242 $(foreach impl,$(DO_IMPLS),\
243 $(foreach step,$(STEPS),repl^$(impl)^$(step)))))
244
31690700
JM
245#
246# Build rules
247#
248
4fc7a281 249# Build a program in an implementation directory
f045aba1
JM
250# Make sure we always try and build first because the dependencies are
251# encoded in the implementation Makefile not here
252.PHONY: $(foreach i,$(DO_IMPLS),$(foreach s,$(STEPS),$(call $(i)_STEP_TO_PROG,$(s))))
4fc7a281 253$(foreach i,$(DO_IMPLS),$(foreach s,$(STEPS),$(call $(i)_STEP_TO_PROG,$(s)))):
f045aba1
JM
254 $(foreach impl,$(word 1,$(subst /, ,$(@))),\
255 $(MAKE) -C $(impl) $(subst $(impl)/,,$(@)))
9ddaa0b9 256
31690700
JM
257# Allow test, test^STEP, test^IMPL, and test^IMPL^STEP
258.SECONDEXPANSION:
259$(IMPL_TESTS): $$(filter $$@^%,$$(ALL_TESTS))
260
261.SECONDEXPANSION:
262$(STEP_TESTS): $$(foreach step,$$(subst test^,,$$@),$$(filter %^$$(step),$$(ALL_TESTS)))
263
264.SECONDEXPANSION:
265$(ALL_TESTS): $$(call $$(word 2,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 3,$$(subst ^, ,$$(@))))
266 @$(foreach impl,$(word 2,$(subst ^, ,$(@))),\
267 $(foreach step,$(word 3,$(subst ^, ,$(@))),\
268 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
269 $(foreach test,$(call STEP_TEST_FILES,$(impl),$(step)),\
270 echo '----------------------------------------------'; \
271 echo 'Testing $@, step file: $+, test file: $(test)'; \
fc4c7889
JM
272 echo 'Running: ../runtest.py $(TEST_OPTS) $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+))'; \
273 ../runtest.py $(TEST_OPTS) $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+));)))
31690700
JM
274
275test: $(ALL_TESTS)
276tests: $(ALL_TESTS)
277
278
279# Stats rules
280
db4c329a
JM
281stats: $(IMPL_STATS)
282stats-lisp: $(IMPL_STATS_LISP)
283
31690700
JM
284.SECONDEXPANSION:
285$(IMPL_STATS):
286 @echo "----------------------------------------------"; \
287 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
288 echo "Stats for $(impl):"; \
289 $(MAKE) --no-print-directory -C $(impl) stats)
290
712af9ef
JM
291.SECONDEXPANSION:
292$(IMPL_STATS_LISP):
293 @echo "----------------------------------------------"; \
294 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
295 echo "Stats (lisp only) for $(impl):"; \
296 $(MAKE) --no-print-directory -C $(impl) stats-lisp)
297
cf1d3eae
JM
298# Docker build rules
299
300docker-build: $(DOCKER_BUILD)
301
302.SECONDEXPANSION:
303$(DOCKER_BUILD):
304 echo "----------------------------------------------"; \
305 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
f7824465
JM
306 echo "Running: docker build -t kanaka/mal-test-$(impl) .:"; \
307 cd $(impl) && docker build -t kanaka/mal-test-$(impl) .)
db4c329a
JM
308
309# Performance test rules
310
311perf: $(IMPL_PERF)
312
313.SECONDEXPANSION:
314$(IMPL_PERF):
315 @echo "----------------------------------------------"; \
316 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
317 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
318 echo "Performance test for $(impl):"; \
319 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal)'; \
320 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal); \
321 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal)'; \
699f0ad2
JM
322 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal); \
323 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal)'; \
324 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal))
854cf2a6
DM
325
326# REPL invocation rules
327# Allow repl^IMPL^STEP and repl^IMPL (which starts REPL of stepA)
328
329.SECONDEXPANSION:
330$(IMPL_REPL): $$@^stepA
331
332.SECONDEXPANSION:
333$(ALL_REPL): $$(call $$(word 2,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 3,$$(subst ^, ,$$(@))))
334 @$(foreach impl,$(word 2,$(subst ^, ,$(@))),\
335 $(foreach step,$(word 3,$(subst ^, ,$(@))),\
336 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
337 echo 'REPL implementation $(impl), step file: $+'; \
338 echo 'Running: $(call $(impl)_RUNSTEP,$(step),$(+))'; \
339 $(call $(impl)_RUNSTEP,$(step),$(+));))