From 21075564bdc48df4b50d565d1a484d26d936d3be Mon Sep 17 00:00:00 2001 From: eldesh Date: Thu, 30 Jul 2020 08:42:29 -0700 Subject: [PATCH 1/4] Add: Makefile for MLton --- .gitignore | 1 + Makefile.mlton | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 Makefile.mlton diff --git a/.gitignore b/.gitignore index bbaef55..1a3ef37 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .cm/ sources +*.mlb.d diff --git a/Makefile.mlton b/Makefile.mlton new file mode 100644 index 0000000..bbd1374 --- /dev/null +++ b/Makefile.mlton @@ -0,0 +1,83 @@ + +MLTON := mlton +MLTON_FLAGS := -default-ann "nonexhaustiveMatch ignore" +ifneq ($(MLB_PATH_MAP),) +MLTON_FLAGS += -mlb-path-map $(MLB_PATH_MAP) +endif + +PREFIX := /usr/local/mlton + +LMLML_MLB := LMLML.mlb +LMLML_TEST_MLB := test/sources.mlb +LMLML_MLBS := $(LMLML_MLB) \ + $(LMLML_TEST_MLB) + +EXAMPLES := example/RegExp/example/Grep/sources + +EXAMPLE_MLB := $(EXAMPLES:=.mlb) + +LMLML_DIR := $(shell readlink -f .) + + +all: typecheck_lmlml test example + + +.PHONY: typecheck_lmlml +typecheck_lmlml: $(LMLML_MLB) + @echo " [MLTON] typecheck $<" + @$(MLTON) $(MLTON_FLAGS) -stop tc $< + + +$(EXAMPLE_MLB:.mlb=): MLTON_FLAGS += -mlb-path-var "LMLML $(LMLML_DIR)" +$(LMLML_TEST_MLB:.mlb=) $(EXAMPLE_MLB:.mlb=): %: %.mlb + @echo " [MLTON] $@" + @$(MLTON) $(MLTON_FLAGS) -output $@ $< + + +$(EXAMPLE_MLB:.mlb=.mlb.d): MLTON_FLAGS += -mlb-path-var "LMLML $(LMLML_DIR)" +%.mlb.d: %.mlb + @echo " [GEN] $@" + @$(SHELL) -ec '$(MLTON) $(MLTON_FLAGS) -stop f $< \ + | sed -e "1i$(<:.mlb=) $@:\\\\" -e "s|.*| & \\\\|" -e "\$$s| \\\\||" > $@; \ + [ -s $@ ] || rm -rf $@' + + +.PHONY: test +test: typecheck_lmlml $(LMLML_TEST_MLB:.mlb=) + $(LMLML_TEST_MLB:.mlb=) + + +.PHONY: example +example: typecheck_lmlml $(EXAMPLES) + + +ifeq ($(findstring clean,$(MAKECMDGOALS)),) +include $(LMLML_MLBS:.mlb=.mlb.d) +include $(EXAMPLE_MLB:.mlb=.mlb.d) +endif + + +.PHONY: install +install: typecheck_lmlml $(LMLML_MLB) + @[ -e $(PREFIX)/lib/LMLML ] || mkdir $(PREFIX)/lib/LMLML + @$(MLTON) $(MLTON_FLAGS) -stop f $(LMLML_MLB) | \ + while read file; do \ + if expr $$(readlink -f $$file) : ^$$(pwd) >/dev/null; then \ + cp --parents $$(realpath --relative-to=$$(pwd) $$file) $(PREFIX)/lib/LMLML; \ + echo -n . ; \ + fi; \ + done + @echo "Installation has been completed." + @echo "Please add the entry to your mlb path map file:" + @echo "" + @echo " LMLML $(PREFIX)/lib/LMLML" + @echo "" + + +.PHONY: clean +clean: + -$(RM) $(LMLML_MLBS:.mlb=) + -$(RM) $(LMLML_MLBS:.mlb=.mlb.d) + -$(RM) $(EXAMPLES) + -$(RM) $(EXAMPLE_MLB:.mlb=.mlb.d) + From 302194e01a9e5da8ba7c4e2899b4634268970511 Mon Sep 17 00:00:00 2001 From: eldesh Date: Thu, 30 Jul 2020 08:55:04 -0700 Subject: [PATCH 2/4] Doc: update Readme about new Makefile.mlton --- Readme.md | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/Readme.md b/Readme.md index cd57638..34006f1 100644 --- a/Readme.md +++ b/Readme.md @@ -75,22 +75,45 @@ val it = true : bool ### Install -Insert mapping entry to `mlb-path-map`. +To install [LMLML] for MLton, use `Makefile.mlton`. ```sh -$ echo 'LMLML /path/to/LMLML' >> $MLTON_ROOT/mlb-path-map +$ make -f Makefile.mlton install + [MLTON] typecheck LMLML.mlb +..............................Installation has been completed. +Please add the entry to your mlb path map file: + + LMLML /usr/local/mlton/lib/LMLML + ``` -Refer to `$(LMLML)/LMLML.mlb` from your `sources.mlb`. +This command install this library to `/usr/local/mlton/lib/LMLML` by default. +It is able to change the location with `PREFIX` variable like: + +```sh +$ make -f Makefile.mlton PREFIX=~/.sml/mlton install +``` + +After `make install`, you need to add an entry in a mlb path mapping file: + +```sh +$ echo 'LMLML /path/to/$PREFIX/lib/LMLML' >> /path/to/mlb-path-map +``` + +Refer to `$(LMLML)/LMLML.mlb` from your mlbasis files. ### Test +Perform unit tests for [LMLML], execute `test` target: + ```sh -$ mlton test/sources.mlb -$ ./test/sources -..........................................................................F.F..F............................... -..................................................E.............................F.F.EF......................... +$ make -f Makefile.mlton test + [MLTON] typecheck LMLML.mlb +test/sources +..........................................................................F.F..F...................................... +...........................................E.............................F.F.EF....................................... +..........................................E.............................F.F.EF........................................ . . ``` From 7f686aa220747a2d87ade5a24f471b20db74f5cb Mon Sep 17 00:00:00 2001 From: eldesh Date: Tue, 4 Aug 2020 00:07:25 +0900 Subject: [PATCH 3/4] Add: support SuffixArray example with MLton --- example/SuffixArray/main/call-main.sml | 1 + example/SuffixArray/main/sources.mlb | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 example/SuffixArray/main/call-main.sml create mode 100644 example/SuffixArray/main/sources.mlb diff --git a/example/SuffixArray/main/call-main.sml b/example/SuffixArray/main/call-main.sml new file mode 100644 index 0000000..359f6ea --- /dev/null +++ b/example/SuffixArray/main/call-main.sml @@ -0,0 +1 @@ +SuffixArray.main (CommandLine.name(), CommandLine.arguments()); diff --git a/example/SuffixArray/main/sources.mlb b/example/SuffixArray/main/sources.mlb new file mode 100644 index 0000000..c3832d9 --- /dev/null +++ b/example/SuffixArray/main/sources.mlb @@ -0,0 +1,6 @@ +$(SML_LIB)/basis/basis.mlb +$(SML_LIB)/smlnj-lib/Util/smlnj-lib.mlb +../../../main/sources.mlb +SuffixArray.sml +call-main.sml + From eae56f349fecc76bbab50afbd463437d46ede19d Mon Sep 17 00:00:00 2001 From: eldesh Date: Tue, 4 Aug 2020 00:39:11 +0900 Subject: [PATCH 4/4] Doc: update MLton sections of Readme --- Readme.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 34006f1..de9d3c2 100644 --- a/Readme.md +++ b/Readme.md @@ -97,7 +97,7 @@ $ make -f Makefile.mlton PREFIX=~/.sml/mlton install After `make install`, you need to add an entry in a mlb path mapping file: ```sh -$ echo 'LMLML /path/to/$PREFIX/lib/LMLML' >> /path/to/mlb-path-map +$ echo 'LMLML $(PREFIX)/lib/LMLML' >> /path/to/mlb-path-map ``` Refer to `$(LMLML)/LMLML.mlb` from your mlbasis files. @@ -108,8 +108,9 @@ Refer to `$(LMLML)/LMLML.mlb` from your mlbasis files. Perform unit tests for [LMLML], execute `test` target: ```sh -$ make -f Makefile.mlton test +$ make -f Makefile.mlton MLB_PATH_MAP=~/.sml/mlton/mlb-path-map [MLTON] typecheck LMLML.mlb + [MLTON] test/sources test/sources ..........................................................................F.F..F...................................... ...........................................E.............................F.F.EF....................................... @@ -118,6 +119,18 @@ test/sources . ``` +### Example + +The `example` target builds `Grep` and `SuffixArray` examples. + +- `Grep` (./example/RegExp/example/Grep/sources) is a multilingualized grep. + `sources ` read input string from stdin per line, and checking the contents of the line matches to the regexp pattern. + If the line matches to the pattern, print it. + + +- `SuffixArray` (./example/SuffixArray/main/sources) is a multilingualized full text search. + `sources ` searches fragments match to the pattern. + ## License