diff --git a/Makefile.impls b/Makefile.impls index 68d1f983..685aadc6 100644 --- a/Makefile.impls +++ b/Makefile.impls @@ -24,6 +24,8 @@ matlab_MODE = octave python_MODE = python # scheme (chibi, kawa, gauche, chicken, sagittarius, cyclone, foment) scheme_MODE = chibi +# sml (polyml, mlton, mosml) +sml_MODE = polyml # wasmtime wasmer lucet wax node warpy wace_libc wasm_MODE = wasmtime diff --git a/impls/sml/.gitignore b/impls/sml/.gitignore new file mode 100644 index 00000000..cb5dad85 --- /dev/null +++ b/impls/sml/.gitignore @@ -0,0 +1,4 @@ +.smlmode +.step* +*.ui +*.uo diff --git a/impls/sml/Makefile b/impls/sml/Makefile index 9ef9d41d..7f4eef1a 100644 --- a/impls/sml/Makefile +++ b/impls/sml/Makefile @@ -1,23 +1,56 @@ STEP_BINS = step0_repl step1_read_print step2_eval step3_env step4_if_fn_do +sml_MODE_DEFAULT = polyml +sml_MODE_CONFIG = .smlmode + +ifeq ($(sml_MODE),) +sml_MODE = $(sml_MODE_DEFAULT) +endif +# some hackery to let Make know if it needs to rebuild when sml_MODE changes +ifneq ($(sml_MODE),$(shell cat $(sml_MODE_CONFIG) 2> /dev/null)) +$(shell rm $(sml_MODE_CONFIG) 2> /dev/null) +endif + +ifeq ($(sml_MODE),mlton) +SMLC = mlton +SMLCOUTFLAG = -output +BUILD_FILE = %.mlb +build_args = $1 +endif +ifeq ($(sml_MODE),mosml) +SMLC = mosmlc +SMLCOUTFLAG = -o +BUILD_FILE = %.mlb +build_args = -toplevel $(shell grep "\\.sml" $1) +endif +ifeq ($(sml_MODE),polyml) +SMLC = polyc +SMLCOUTFLAG = -o +BUILD_FILE = .%.poly.sml +build_args = $1 +endif + all: $(STEP_BINS) -step0_repl: step0_repl.mlb step0_repl.sml main.sml - mlton -output $@ $< +.%.dep: %.mlb + @echo sml-deps -o $@ $< + $(eval DEPS := $(shell grep "\\.sml" $<)) + @echo "$(@:.%.dep=%) $@: $(DEPS)" > $@ -step1_read_print: step1_read_print.mlb step1_read_print.sml reader.sml printer.sml types.sml util.sml main.sml - mlton -output $@ $< +include $(STEP_BINS:%=.%.dep) -step2_eval: step2_eval.mlb step2_eval.sml env.sml reader.sml printer.sml types.sml util.sml main.sml - mlton -output $@ $< +.%.poly.sml: %.mlb + @echo generate-sml -o $@ $< + @grep "\\.sml" $< | grep -v main | xargs printf "use \"%s\";\n" > $@ -step3_env: step3_env.mlb step3_env.sml env.sml reader.sml printer.sml types.sml util.sml main.sml - mlton -output $@ $< +# some hackery to let Make track changes in sml_MODE +$(sml_MODE_CONFIG): + @echo $(sml_MODE) > $@ -step4_if_fn_do: step4_if_fn_do.mlb step4_if_fn_do.sml core.sml env.sml reader.sml printer.sml types.sml util.sml main.sml - mlton -output $@ $< +$(STEP_BINS): %: $(BUILD_FILE) $(sml_MODE_CONFIG) + $(SMLC) $(SMLCOUTFLAG) $@ $(call build_args,$<) clean: - rm -f $(STEP_BINS) + rm -f $(STEP_BINS) .*.dep *.ui *.uo .*.poly.sml $(sml_MODE_CONFIG) .PHONY: all clean