From 8f46fdb6d262441cb022bac8852212b630e8a6a5 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sun, 14 Jan 2018 17:15:40 -0600 Subject: [PATCH] move to jbuilder (closes #165) --- .gitignore | 1 + .merlin | 23 ------ Makefile | 137 +++++--------------------------- _oasis | 169 ---------------------------------------- _tags | 164 -------------------------------------- benchs/jbuild | 10 +++ configure | 31 -------- opam => containers.opam | 3 +- examples/jbuild | 10 +++ qtest/Makefile | 31 ++++++++ qtest/jbuild | 23 ++++++ setup.ml | 32 -------- src/core/CCList.ml | 6 +- src/core/CCParse.ml | 43 +++++----- src/core/CCRandom.ml | 6 +- src/core/CCString.ml | 12 +-- src/core/jbuild | 10 +++ src/data/jbuild | 10 +++ src/iter/jbuild | 10 +++ src/monomorphic/jbuild | 10 +++ src/sexp/jbuild | 12 +++ src/threads/jbuild | 11 +++ src/top/jbuild | 12 +++ src/unix/.merlin | 5 +- src/unix/jbuild | 10 +++ 25 files changed, 218 insertions(+), 573 deletions(-) delete mode 100644 .merlin delete mode 100644 _oasis delete mode 100644 _tags create mode 100644 benchs/jbuild delete mode 100755 configure rename opam => containers.opam (95%) create mode 100644 examples/jbuild create mode 100644 qtest/Makefile create mode 100644 qtest/jbuild delete mode 100644 setup.ml create mode 100644 src/core/jbuild create mode 100644 src/data/jbuild create mode 100644 src/iter/jbuild create mode 100644 src/monomorphic/jbuild create mode 100644 src/sexp/jbuild create mode 100644 src/threads/jbuild create mode 100644 src/top/jbuild create mode 100644 src/unix/jbuild diff --git a/.gitignore b/.gitignore index 8d2ffd6d..40f0e259 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ TAGS setup.* qtest* *.html +.merlin diff --git a/.merlin b/.merlin deleted file mode 100644 index 7cf051e1..00000000 --- a/.merlin +++ /dev/null @@ -1,23 +0,0 @@ -S src/core -S src/data/ -S src/iter/ -S src/sexp/ -S src/threads/ -S src/string -S src/monomorphic -S benchs -S examples -S tests -B _build/src/** -B _build/benchs -B _build/examples -B _build/tests -PKG oUnit -PKG benchmark -PKG result -PKG threads -PKG threads.posix -PKG lwt -PKG qcheck -FLG -w +a-4-44-48-60@8 -FLG -open CCMonomorphic diff --git a/Makefile b/Makefile index 2775f558..dceec126 100644 --- a/Makefile +++ b/Makefile @@ -1,135 +1,34 @@ # OASIS_START # DO NOT EDIT (digest: 4c293511860bb966e727ba6f0ecc8197) -SETUP = ./setup.exe +all: build test -build: setup.data $(SETUP) - $(SETUP) -build $(BUILDFLAGS) +build: + jbuilder build @install -doc: setup.data $(SETUP) build - $(SETUP) -doc $(DOCFLAGS) +test: + jbuilder runtest --no-buffer -test: setup.data $(SETUP) build - $(SETUP) -test $(TESTFLAGS) +clean: + jbuilder clean -all: $(SETUP) - $(SETUP) -all $(ALLFLAGS) +doc: + jbuilder build @doc -install: setup.data $(SETUP) - $(SETUP) -install $(INSTALLFLAGS) +BENCH_TARGETS=run_benchs.exe run_bench_hash.exe -uninstall: setup.data $(SETUP) - $(SETUP) -uninstall $(UNINSTALLFLAGS) +benchs: + jbuilder build $(addprefix bench/, $(BENCH_TARGETS)) -reinstall: setup.data $(SETUP) - $(SETUP) -reinstall $(REINSTALLFLAGS) +examples: + jbuilder build examples/id_sexp.exe -clean: $(SETUP) - $(SETUP) -clean $(CLEANFLAGS) - -distclean: $(SETUP) - $(SETUP) -distclean $(DISTCLEANFLAGS) - $(RM) $(SETUP) - -setup.data: $(SETUP) - $(SETUP) -configure $(CONFIGUREFLAGS) - -configure: $(SETUP) - $(SETUP) -configure $(CONFIGUREFLAGS) - -setup.exe: setup.ml _oasis - ocamlfind ocamlopt -o $@ -linkpkg -package oasis.dynrun setup.ml || ocamlfind ocamlc -o $@ -linkpkg -package oasis.dynrun setup.ml || true - $(RM) setup.cmi setup.cmo setup.cmx setup.o - -.PHONY: build doc test all install uninstall reinstall clean distclean configure - -# OASIS_STOP - -EXAMPLES = examples/mem_size.native examples/collatz.native \ - examples/bencode_write.native # examples/crawl.native -OPTIONS = -use-ocamlfind -I _build - -examples: all - ocamlbuild $(OPTIONS) -package unix -I . $(EXAMPLES) - -push_doc: doc - rsync -tavu containers.docdir/* cedeela.fr:~/simon/root/software/containers/ - -push_doc_gh: doc - git checkout gh-pages && \ - rm -rf dev/ && \ - mkdir -p dev && \ - cp -r containers.docdir/* dev/ && \ - git add --all dev - -DONTTEST=myocamlbuild.ml setup.ml $(wildcard src/**/*.cppo.*) $(wildcard src/**/*Labels*) -QTESTABLE=$(filter-out $(DONTTEST), \ - $(wildcard src/core/*.ml) \ - $(wildcard src/core/*.mli) \ - $(wildcard src/data/*.ml) \ - $(wildcard src/data/*.mli) \ - $(wildcard src/string/*.ml) \ - $(wildcard src/string/*.mli) \ - $(wildcard src/unix/*.ml) \ - $(wildcard src/unix/*.mli) \ - $(wildcard src/sexp/*.ml) \ - $(wildcard src/sexp/*.mli) \ - $(wildcard src/iter/*.ml) \ - $(wildcard src/iter/*.mli) \ - $(wildcard src/bigarray/*.ml) \ - $(wildcard src/bigarray/*.mli) \ - $(wildcard src/threads/*.ml) \ - $(wildcard src/threads/*.mli) \ - ) - -qtest-clean: - @rm -rf qtest/ - -QTEST_PREAMBLE='open CCFun;; ' - -#qtest-build: qtest-clean build -# @mkdir -p qtest -# @qtest extract --preamble $(QTEST_PREAMBLE) \ -# -o qtest/qtest_all.ml \ -# $(QTESTABLE) 2> /dev/null -# @ocamlbuild $(OPTIONS) -pkg oUnit,QTest2Lib,ocamlbuildlib \ -# -I core -I misc -I string \ -# qtest/qtest_all.native - -qtest-gen: - @mkdir -p qtest - @if which qtest > /dev/null ; then \ - qtest extract --preamble $(QTEST_PREAMBLE) \ - -o qtest/run_qtest.ml \ - $(QTESTABLE) 2> /dev/null ; \ - else touch qtest/run_qtest.ml ; \ - fi - -push-stable: - git checkout stable - git merge master -m 'merge from master' - oasis setup - git commit -a -m 'oasis files' - git push origin - git checkout master - -clean-generated: - rm **/*.{mldylib,mlpack,mllib} myocamlbuild.ml -f - -tags: - otags *.ml *.mli - -VERSION=$(shell awk '/^Version:/ {print $$2}' _oasis) +VERSION=$(shell awk '/^version:/ {print $$2}' containers.opam) update_next_tag: @echo "update version to $(VERSION)..." - zsh -c 'sed -i "s/NEXT_VERSION/$(VERSION)/g" **/*.ml **/*.mli' - zsh -c 'sed -i "s/NEXT_RELEASE/$(VERSION)/g" **/*.ml **/*.mli' - -devel: - ./configure --enable-bench --enable-tests --enable-unix \ - --enable-thread - make all + sed -i "s/NEXT_VERSION/$(VERSION)/g" src/*.ml src/*.mli + sed -i "s/NEXT_RELEASE/$(VERSION)/g" src/*.ml src/*.mli watch: while find src/ benchs/ -print0 | xargs -0 inotifywait -e delete_self -e modify ; do \ @@ -142,4 +41,4 @@ reindent: @find src '(' -name '*.ml' -or -name '*.mli' ')' -type f -print0 | xargs -0 echo "reindenting: " @find src '(' -name '*.ml' -or -name '*.mli' ')' -type f -print0 | xargs -0 ocp-indent -i -.PHONY: examples push_doc tags qtest-gen qtest-clean devel update_next_tag +.PHONY: all test clean build doc update_next_tag watch diff --git a/_oasis b/_oasis deleted file mode 100644 index 432d9828..00000000 --- a/_oasis +++ /dev/null @@ -1,169 +0,0 @@ -OASISFormat: 0.4 -Name: containers -Version: 1.5.2 -Homepage: https://github.com/c-cube/ocaml-containers -Authors: Simon Cruanes -License: BSD-2-clause -LicenseFile: LICENSE -Plugins: META (0.3), DevFiles (0.3) -OCamlVersion: >= 4.00.1 -BuildTools: ocamlbuild -AlphaFeatures: compiled_setup_ml, ocamlbuild_more_args - -# cygwin fails with anything else -XOCamlbuildExtraArgs: "-j 1" - -Synopsis: A modular standard library focused on data structures. -Description: - Containers is a standard library (BSD license) focused on data structures, - combinators and iterators, without dependencies on unix. Every module is - independent and is prefixed with 'CC' in the global namespace. Some modules - extend the stdlib (e.g. CCList provides safe map/fold_right/append, and - additional functions on lists). - - It also features optional libraries for dealing with strings, and - helpers for unix and threads. - -Flag "unix" - Description: Build the containers.unix library (depends on Unix) - Default: true - -Flag "thread" - Description: Build modules that depend on threads - Default: true - -Flag "bench" - Description: Build and run benchmarks - Default: true - -Library "containers" - Path: src/core - Modules: CCVector, CCHeap, CCList, CCOpt, CCPair, - CCFun, CCHash, CCInt, CCBool, CCFloat, CCArray, CCRef, CCSet, - CCOrd, CCRandom, CCString, CCHashtbl, CCMap, CCFormat, CCIO, - CCInt64, CCChar, CCResult, CCParse, CCArray_slice, - CCListLabels, CCArrayLabels, CCEqual, - Containers - BuildDepends: bytes, result, containers.monomorphic - # BuildDepends: bytes, bisect_ppx - -Library "containers_monomorphic" - Path: src/monomorphic - Modules: CCMonomorphic - FindlibParent: containers - FindlibName: monomorphic - -Library "containers_unix" - Path: src/unix - Modules: CCUnix - BuildDepends: bytes, result, unix, containers.monomorphic - FindlibParent: containers - FindlibName: unix - -Library "containers_sexp" - Path: src/sexp - Modules: CCSexp, CCSexp_lex - BuildDepends: bytes, result, containers.monomorphic - FindlibParent: containers - FindlibName: sexp - -Library "containers_data" - Path: src/data - Modules: CCMultiMap, CCMultiSet, CCTrie, CCFlatHashtbl, CCCache, - CCPersistentHashtbl, CCDeque, CCFQueue, CCBV, CCMixtbl, - CCMixmap, CCRingBuffer, CCIntMap, CCPersistentArray, - CCMixset, CCGraph, CCHashSet, CCBitField, - CCHashTrie, CCWBTree, CCRAL, CCSimple_queue, - CCImmutArray, CCHet, CCZipper - BuildDepends: bytes, containers.monomorphic - # BuildDepends: bytes, bisect_ppx - FindlibParent: containers - FindlibName: data - -Library "containers_iter" - Path: src/iter - Modules: CCKTree, CCKList, CCLazy_list - BuildDepends: containers.monomorphic - FindlibParent: containers - FindlibName: iter - -Library "containers_thread" - Path: src/threads/ - Modules: CCPool, CCLock, CCSemaphore, CCThread, CCBlockingQueue, - CCTimer - FindlibName: thread - FindlibParent: containers - Build$: flag(thread) - Install$: flag(thread) - BuildDepends: containers, threads - XMETARequires: containers, threads - -Library "containers_top" - Path: src/top/ - Modules: Containers_top - FindlibName: top - FindlibParent: containers - BuildDepends: compiler-libs.common, containers, containers.data, - containers.unix, containers.sexp, containers.iter - -Document containers - Title: Containers docs - Type: ocamlbuild (0.3) - BuildTools+: ocamldoc - Build$: flag(docs) && flag(unix) - Install: true - XOCamlbuildPath: . - XOCamlbuildExtraArgs: - "-docflags '-colorize-code -short-functors -charset utf-8'" - XOCamlbuildLibraries: - containers, containers.iter, containers.data, - containers.thread, containers.unix, containers.sexp - -Executable run_benchs - Path: benchs/ - Install: false - CompiledObject: best - Build$: flag(bench) - MainIs: run_benchs.ml - BuildDepends: containers, qcheck, - containers.data, containers.iter, containers.thread, - containers.monomorphic, - sequence, gen, benchmark - -Executable run_bench_hash - Path: benchs/ - Install: false - CompiledObject: best - Build$: flag(bench) - MainIs: run_bench_hash.ml - BuildDepends: containers - -PreBuildCommand: make qtest-gen - -Executable run_qtest - Path: qtest/ - Install: false - CompiledObject: best - MainIs: run_qtest.ml - Build$: flag(tests) && flag(unix) - BuildDepends: containers, containers.iter, - containers.sexp, containers.unix, containers.thread, - containers.data, - sequence, gen, unix, oUnit, qcheck - -Test all - Command: ./run_qtest.native - TestTools: run_qtest - Run$: flag(tests) && flag(unix) - -Executable id_sexp - Path: examples/ - Install: false - CompiledObject: best - MainIs: id_sexp.ml - BuildDepends: containers.sexp - -SourceRepository head - Type: git - Location: https://github.com/c-cube/ocaml-containers - Browser: https://github.com/c-cube/ocaml-containers/tree/master/src diff --git a/_tags b/_tags deleted file mode 100644 index 1f3db001..00000000 --- a/_tags +++ /dev/null @@ -1,164 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: 1681c391580688c2463b8457d464cf03) -# Ignore VCS directories, you can use the same kind of rule outside -# OASIS_START/STOP if you want to exclude directories that contains -# useless stuff for the build process -true: annot, bin_annot -<**/.svn>: -traverse -<**/.svn>: not_hygienic -".bzr": -traverse -".bzr": not_hygienic -".hg": -traverse -".hg": not_hygienic -".git": -traverse -".git": not_hygienic -"_darcs": -traverse -"_darcs": not_hygienic -# Library containers -"src/core/containers.cmxs": use_containers -: package(bytes) -: package(result) -# Library containers_io -"src/io/containers_io.cmxs": use_containers_io -: package(bytes) -# Library containers_unix -"src/unix/containers_unix.cmxs": use_containers_unix -: package(bytes) -: package(unix) -# Library containers_sexp -"src/sexp/containers_sexp.cmxs": use_containers_sexp -: package(bytes) -# Library containers_data -"src/data/containers_data.cmxs": use_containers_data -: package(bytes) -# Library containers_iter -"src/iter/containers_iter.cmxs": use_containers_iter -# Library containers_string -"src/string/containers_string.cmxs": use_containers_string -: package(bytes) -# Library containers_advanced -"src/advanced/containers_advanced.cmxs": use_containers_advanced -: package(bytes) -: package(result) -: package(sequence) -: use_containers -# Library containers_bigarray -"src/bigarray/containers_bigarray.cmxs": use_containers_bigarray -: package(bigarray) -: package(bytes) -: package(result) -: use_containers -# Library containers_thread -"src/threads/containers_thread.cmxs": use_containers_thread -: package(bytes) -: package(result) -: package(threads) -: use_containers -# Library containers_top -"src/top/containers_top.cmxs": use_containers_top -: package(bigarray) -: package(bytes) -: package(compiler-libs.common) -: package(result) -: package(unix) -: use_containers -: use_containers_bigarray -: use_containers_data -: use_containers_iter -: use_containers_sexp -: use_containers_string -: use_containers_unix -# Executable run_benchs -: package(benchmark) -: package(bytes) -: package(gen) -: package(hamt) -: package(result) -: package(sequence) -: package(threads) -: use_containers -: use_containers_advanced -: use_containers_data -: use_containers_iter -: use_containers_string -: use_containers_thread -: package(benchmark) -: package(gen) -: package(threads) -: use_containers_advanced -: use_containers_iter -: use_containers_string -: use_containers_thread -# Executable run_bench_hash -: package(bytes) -: package(result) -: use_containers -# Executable run_qtest -: package(QTest2Lib) -: package(bigarray) -: package(bytes) -: package(gen) -: package(oUnit) -: package(result) -: package(sequence) -: package(threads) -: package(unix) -: use_containers -: use_containers_advanced -: use_containers_bigarray -: use_containers_data -: use_containers_io -: use_containers_iter -: use_containers_sexp -: use_containers_string -: use_containers_thread -: use_containers_unix -: package(QTest2Lib) -: package(bigarray) -: package(bytes) -: package(gen) -: package(oUnit) -: package(result) -: package(sequence) -: package(threads) -: package(unix) -: use_containers -: use_containers_advanced -: use_containers_bigarray -: use_containers_data -: use_containers_io -: use_containers_iter -: use_containers_sexp -: use_containers_string -: use_containers_thread -: use_containers_unix -# Executable mem_measure -"benchs/mem_measure.native": package(bytes) -"benchs/mem_measure.native": package(hamt) -"benchs/mem_measure.native": package(result) -"benchs/mem_measure.native": package(sequence) -"benchs/mem_measure.native": package(unix) -"benchs/mem_measure.native": use_containers -"benchs/mem_measure.native": use_containers_data -: package(bytes) -: package(hamt) -: package(result) -: package(sequence) -: package(unix) -: use_containers -: use_containers_data -# Executable id_sexp -: package(bytes) -: use_containers_sexp -: package(bytes) -: use_containers_sexp -# OASIS_STOP -: thread -: thread - or : inline(25) - or or : inline(15) - or or : warn(-32) - and not : warn(+a-4-44-58-60@8) -true: no_alias_deps, safe_string, short_paths, color(always) -: nolabels -not ( or ): open(CCMonomorphic) diff --git a/benchs/jbuild b/benchs/jbuild new file mode 100644 index 00000000..82853950 --- /dev/null +++ b/benchs/jbuild @@ -0,0 +1,10 @@ + +(executables + ((names (run_benchs run_bench_hash)) + (libraries (containers containers.data containers.iter + containers.thread benchmark gen sequence)) + (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always)) + (ocamlopt_flags (:standard -O3 -color always + -unbox-closures -unbox-closures-factor 20)) + )) + diff --git a/configure b/configure deleted file mode 100755 index 7231d47f..00000000 --- a/configure +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh - -# OASIS_START -# DO NOT EDIT (digest: 7577949ceda6f9dbd4983aea8db9275b) -set -e - -FST=true -for i in "$@"; do - if $FST; then - set -- - FST=false - fi - - case $i in - --*=*) - ARG=${i%%=*} - VAL=${i##*=} - set -- "$@" "$ARG" "$VAL" - ;; - *) - set -- "$@" "$i" - ;; - esac -done - -if [ ! -e setup.exe ] || [ _oasis -nt setup.exe ] || [ setup.ml -nt setup.exe ] || [ configure -nt setup.exe ]; then - ocamlfind ocamlopt -o setup.exe -linkpkg -package oasis.dynrun setup.ml || ocamlfind ocamlc -o setup.exe -linkpkg -package oasis.dynrun setup.ml || exit 1 - rm -f setup.cmi setup.cmo setup.cmx setup.o -fi -./setup.exe -configure "$@" -# OASIS_STOP diff --git a/opam b/containers.opam similarity index 95% rename from opam rename to containers.opam index f930cfba..d43c4984 100644 --- a/opam +++ b/containers.opam @@ -23,10 +23,9 @@ remove: [ ] depends: [ "ocamlfind" {build} - "oasis" {build} + "jbuilder" {build} "base-bytes" "result" - "ocamlbuild" {build} ] depopts: [ "base-unix" diff --git a/examples/jbuild b/examples/jbuild new file mode 100644 index 00000000..e7d75a09 --- /dev/null +++ b/examples/jbuild @@ -0,0 +1,10 @@ + +(executables + ((names (id_sexp)) + (libraries (containers.sexp)) + (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always)) + (ocamlopt_flags (:standard -O3 -color always + -unbox-closures -unbox-closures-factor 20)) + )) + + diff --git a/qtest/Makefile b/qtest/Makefile new file mode 100644 index 00000000..8e41bb67 --- /dev/null +++ b/qtest/Makefile @@ -0,0 +1,31 @@ + + +QTEST_PREAMBLE='open CCFun;;' +DONTTEST=$(wildcard ../src/**/*.cppo.*) $(wildcard ../src/**/*Labels*) +QTESTABLE=$(filter-out $(DONTTEST), \ + $(wildcard ../src/core/*.ml) \ + $(wildcard ../src/core/*.mli) \ + $(wildcard ../src/data/*.ml) \ + $(wildcard ../src/data/*.mli) \ + $(wildcard ../src/string/*.ml) \ + $(wildcard ../src/string/*.mli) \ + $(wildcard ../src/unix/*.ml) \ + $(wildcard ../src/unix/*.mli) \ + $(wildcard ../src/sexp/*.ml) \ + $(wildcard ../src/sexp/*.mli) \ + $(wildcard ../src/iter/*.ml) \ + $(wildcard ../src/iter/*.mli) \ + $(wildcard ../src/bigarray/*.ml) \ + $(wildcard ../src/bigarray/*.mli) \ + $(wildcard ../src/threads/*.ml) \ + $(wildcard ../src/threads/*.mli) \ + ) + +qtest-gen: + @if which qtest > /dev/null ; then \ + echo "generate qtest"; \ + qtest extract --preamble $(QTEST_PREAMBLE) \ + -o run_qtest.ml \ + $(QTESTABLE) 2> /dev/null ; \ + else touch qtest/run_qtest.ml ; \ + fi diff --git a/qtest/jbuild b/qtest/jbuild new file mode 100644 index 00000000..124f3061 --- /dev/null +++ b/qtest/jbuild @@ -0,0 +1,23 @@ + +(rule + ((targets (run_qtest.ml)) + (deps ((file Makefile))) + (fallback) + ;(libraries (qtest qcheck)) + (action + (run make qtest-gen)) + )) + +(executable + ((name run_qtest) + (libraries (sequence gen qcheck containers containers.unix + containers.data containers.thread containers.iter + containers.sexp)) + )) + +(alias + ((name runtest) + (deps (run_qtest.exe)) + (action (run ${<})) + )) + diff --git a/setup.ml b/setup.ml deleted file mode 100644 index 28f4aab2..00000000 --- a/setup.ml +++ /dev/null @@ -1,32 +0,0 @@ -(* setup.ml generated for the first time by OASIS v0.4.4 *) - -(* OASIS_START *) -(* DO NOT EDIT (digest: 1bc19e72587da58c1e1f99f847b509aa) *) -(******************************************************************************) -(* OASIS: architecture for building OCaml libraries and applications *) -(* *) -(* Copyright (C) 2011-2016, Sylvain Le Gall *) -(* Copyright (C) 2008-2011, OCamlCore SARL *) -(* *) -(* This library is free software; you can redistribute it and/or modify it *) -(* under the terms of the GNU Lesser General Public License as published by *) -(* the Free Software Foundation; either version 2.1 of the License, or (at *) -(* your option) any later version, with the OCaml static compilation *) -(* exception. *) -(* *) -(* This library is distributed in the hope that it will be useful, but *) -(* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *) -(* or FITNESS FOR A PARTICULAR PURPOSE. See the file COPYING for more *) -(* details. *) -(* *) -(* You should have received a copy of the GNU Lesser General Public License *) -(* along with this library; if not, write to the Free Software Foundation, *) -(* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *) -(******************************************************************************) - -open OASISDynRun - -let setup_t = BaseCompat.Compat_0_4.adapt_setup_t setup_t -open BaseCompat.Compat_0_4 -(* OASIS_STOP *) -let () = setup ();; diff --git a/src/core/CCList.ml b/src/core/CCList.ml index ec33ae71..4735b6a7 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -570,9 +570,9 @@ let sorted_merge ~cmp l1 l2 = recurse cmp [] l1 l2 (*$T - List.sort Pervasives.compare ([(( * )2); ((+)1)] <*> [10;100]) \ - = [11; 20; 101; 200] - sorted_merge ~cmp:CCInt.compare [1;1;2] [1;2;3] = [1;1;1;2;2;3] + equal CCInt.equal (List.sort CCInt.compare ([(( * )2); ((+)1)] <*> [10;100])) \ + [11; 20; 101; 200] + equal CCInt.equal (sorted_merge ~cmp:CCInt.compare [1;1;2] [1;2;3]) [1;1;1;2;2;3] *) (*$Q diff --git a/src/core/CCParse.ml b/src/core/CCParse.ml index 229895f0..b66d0e6a 100644 --- a/src/core/CCParse.ml +++ b/src/core/CCParse.ml @@ -86,7 +86,7 @@ let fail_ ~err st msg = let next st ~ok ~err = if st.i = String.length st.str - then fail_ st ~err (const_ "unexpected end of input") + then fail_ ~err st (const_ "unexpected end of input") else ( let c = st.str.[st.i] in st.i <- st.i + 1; @@ -110,24 +110,24 @@ type 'a t = state -> ok:('a -> unit) -> err:(exn -> unit) -> unit let return : 'a -> 'a t = fun x _st ~ok ~err:_ -> ok x let pure = return let (>|=) : 'a t -> ('a -> 'b) -> 'b t - = fun p f st ~ok ~err -> p st ~err ~ok:(fun x -> ok (f x)) + = fun p f st ~ok ~err -> p st ~ok:(fun x -> ok (f x)) ~err let (>>=) : 'a t -> ('a -> 'b t) -> 'b t - = fun p f st ~ok ~err -> p st ~err ~ok:(fun x -> f x st ~err ~ok) + = fun p f st ~ok ~err -> p st ~ok:(fun x -> f x st ~ok ~err) ~err let (<*>) : ('a -> 'b) t -> 'a t -> 'b t = fun f x st ~ok ~err -> - f st ~err ~ok:(fun f' -> x st ~err ~ok:(fun x' -> ok (f' x'))) + f st ~ok:(fun f' -> x st ~ok:(fun x' -> ok (f' x')) ~err) ~err let (<* ) : 'a t -> _ t -> 'a t = fun x y st ~ok ~err -> - x st ~err ~ok:(fun res -> y st ~err ~ok:(fun _ -> ok res)) + x st ~ok:(fun res -> y st ~ok:(fun _ -> ok res) ~err) ~err let ( *>) : _ t -> 'a t -> 'a t = fun x y st ~ok ~err -> - x st ~err ~ok:(fun _ -> y st ~err ~ok) + x st ~ok:(fun _ -> y st ~ok ~err) ~err let map f x = x >|= f let map2 f x y = pure f <*> x <*> y let map3 f x y z = pure f <*> x <*> y <*> z -let junk_ st = next st ~err:(fun _ -> assert false) ~ok:ignore +let junk_ st = next st ~ok:ignore ~err:(fun _ -> assert false) let eoi st ~ok ~err = if is_done st @@ -148,15 +148,15 @@ let nop _ ~ok ~err:_ = ok() let char c = let msg = Printf.sprintf "expected '%c'" c in fun st ~ok ~err -> - next st ~err - ~ok:(fun c' -> if char_equal c c' then ok c else fail_ ~err st (const_ msg)) + next st + ~ok:(fun c' -> if char_equal c c' then ok c else fail_ ~err st (const_ msg)) ~err let char_if p st ~ok ~err = - next st ~err + next st ~ok:(fun c -> if p c then ok c else fail_ ~err st (fun () -> Printf.sprintf "unexpected char '%c'" c) - ) + ) ~err let chars_if p st ~ok ~err:_ = let i = st.i in @@ -165,11 +165,12 @@ let chars_if p st ~ok ~err:_ = ok (String.sub st.str i !len) let chars1_if p st ~ok ~err = - chars_if p st ~err + chars_if p st ~ok:(fun s -> if string_equal s "" then fail_ ~err st (const_ "unexpected sequence of chars") else ok s) + ~err let rec skip_chars p st ~ok ~err = if not (is_done st) && p (cur st) then ( @@ -191,10 +192,11 @@ let space = char_if is_space let white = char_if is_white let endline st ~ok ~err = - next st ~err + next st ~ok:(function | '\n' as c -> ok c | _ -> fail_ ~err st (const_ "expected end-of-line")) + ~err let skip_space = skip_chars is_space let skip_white = skip_chars is_white @@ -232,32 +234,33 @@ let string s st ~ok ~err = let rec check i = if i = String.length s then ok s else - next st ~err + next st ~ok:(fun c -> if char_equal c s.[i] then check (i+1) else fail_ ~err st (fun () -> Printf.sprintf "expected \"%s\"" s)) + ~err in check 0 let rec many_rec : 'a t -> 'a list -> 'a list t = fun p acc st ~ok ~err -> if is_done st then ok(List.rev acc) else - p st ~err + p st ~ok:(fun x -> let i = pos st in many_rec p (x :: acc) st ~ok ~err:(fun _ -> backtrack st i; ok(List.rev acc)) - ) + ) ~err let many : 'a t -> 'a list t = fun p st ~ok ~err -> many_rec p [] st ~ok ~err let many1 : 'a t -> 'a list t = fun p st ~ok ~err -> - p st ~err ~ok:(fun x -> many_rec p [x] st ~err ~ok) + p st ~ok:(fun x -> many_rec p [x] st ~ok ~err) ~err let rec skip p st ~ok ~err = let i = pos st in @@ -306,12 +309,12 @@ let memo (type a) (p:a t):a t = with Not_found -> (* parse, and save *) p st - ~err:(fun e -> - MemoTbl.H.replace tbl (i,id) (fun () -> r := Some (MemoTbl.Fail e)); - err e) ~ok:(fun x -> MemoTbl.H.replace tbl (i,id) (fun () -> r := Some (MemoTbl.Ok x)); ok x) + ~err:(fun e -> + MemoTbl.H.replace tbl (i,id) (fun () -> r := Some (MemoTbl.Fail e)); + err e) let fix_memo f = let rec p = diff --git a/src/core/CCRandom.ml b/src/core/CCRandom.ml index fc3d7d93..2879540e 100644 --- a/src/core/CCRandom.ml +++ b/src/core/CCRandom.ml @@ -117,10 +117,10 @@ let _diff_list ~last l = ∑_k y_k = ∑_k (x_{k+1} - x_k ) = x_{len} - x_0 = i. *) let split_list i ~len st = if len <= 1 then invalid_arg "Random.split_list"; - if i >= len then + if i >= len then ( let xs = sample_without_replacement ~compare (len-1) (int_range 1 (i-1)) st in - _diff_list ( 0::xs ) ~last:i - else + _diff_list ~last:i (0::xs) + ) else None (*$Q diff --git a/src/core/CCString.ml b/src/core/CCString.ml index 6e66c732..c5491971 100644 --- a/src/core/CCString.ml +++ b/src/core/CCString.ml @@ -257,14 +257,14 @@ end let find ?(start=0) ~sub = let pattern = Find.compile sub in - fun s -> Find.find ~pattern s ~start + fun s -> Find.find ~start ~pattern s let find_all ?(start=0) ~sub = let pattern = Find.compile sub in fun s -> let i = ref start in fun () -> - let res = Find.find ~pattern s ~start:!i in + let res = Find.find ~start:!i ~pattern s in if res = ~-1 then None else ( i := res + 1; (* possible overlap *) @@ -282,7 +282,7 @@ let mem ?start ~sub s = find ?start ~sub s >= 0 let rfind ~sub = let pattern = Find.rcompile sub in - fun s -> Find.rfind ~pattern s ~start:(String.length s-1) + fun s -> Find.rfind ~start:(String.length s-1) ~pattern s (* Replace substring [s.[pos]....s.[pos+len-1]] by [by] in [s] *) let replace_at_ ~pos ~len ~by s = @@ -296,7 +296,7 @@ let replace ?(which=`All) ~sub ~by s = if is_empty sub then invalid_arg "CCString.replace"; match which with | `Left -> - let i = find ~sub s ~start:0 in + let i = find ~start:0 ~sub s in if i>=0 then replace_at_ ~pos:i ~len:(String.length sub) ~by s else s | `Right -> let i = rfind ~sub s in @@ -307,7 +307,7 @@ let replace ?(which=`All) ~sub ~by s = let b = Buffer.create (String.length s) in let start = ref 0 in while !start < String.length s do - let i = Find.find ~pattern s ~start:!start in + let i = Find.find ~start:!start ~pattern s in if i>=0 then ( (* between last and cur occurrences *) Buffer.add_substring b s !start (i- !start); @@ -339,7 +339,7 @@ module Split = struct | SplitAt prev -> _split_search ~by s prev and _split_search ~by s prev = - let j = Find.find ~pattern:by s ~start:prev in + let j = Find.find ~start:prev ~pattern:by s in if j < 0 then Some (SplitStop, prev, String.length s - prev) else Some (SplitAt (j+Find.pattern_length by), prev, j-prev) diff --git a/src/core/jbuild b/src/core/jbuild new file mode 100644 index 00000000..c93cbc7e --- /dev/null +++ b/src/core/jbuild @@ -0,0 +1,10 @@ + +(library + ((name containers) + (public_name containers) + (wrapped false) + (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always -nolabels -open CCMonomorphic)) + (ocamlopt_flags (:standard -O3 -color always + -unbox-closures -unbox-closures-factor 20)) + (libraries (bytes result containers.monomorphic)) + )) diff --git a/src/data/jbuild b/src/data/jbuild new file mode 100644 index 00000000..80ac4bce --- /dev/null +++ b/src/data/jbuild @@ -0,0 +1,10 @@ + +(library + ((name containers_data) + (public_name containers.data) + (wrapped false) + (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always)) + (ocamlopt_flags (:standard -O3 -color always + -unbox-closures -unbox-closures-factor 20)) + (libraries (bytes result)) + )) diff --git a/src/iter/jbuild b/src/iter/jbuild new file mode 100644 index 00000000..60ca4553 --- /dev/null +++ b/src/iter/jbuild @@ -0,0 +1,10 @@ + +(library + ((name containers_iter) + (public_name containers.iter) + (wrapped false) + (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always)) + (ocamlopt_flags (:standard -O3 -color always + -unbox-closures -unbox-closures-factor 20)) + (libraries (bytes result)) + )) diff --git a/src/monomorphic/jbuild b/src/monomorphic/jbuild new file mode 100644 index 00000000..0944bf5f --- /dev/null +++ b/src/monomorphic/jbuild @@ -0,0 +1,10 @@ + +(library + ((name containers_monomorphic) + (public_name containers.monomorphic) + (wrapped false) + (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always)) + (ocamlopt_flags (:standard -O3 -color always + -unbox-closures -unbox-closures-factor 20)) + (libraries ()) + )) diff --git a/src/sexp/jbuild b/src/sexp/jbuild new file mode 100644 index 00000000..cc7f71c0 --- /dev/null +++ b/src/sexp/jbuild @@ -0,0 +1,12 @@ + +(library + ((name containers_sexp) + (public_name containers.sexp) + (wrapped false) + (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always)) + (ocamlopt_flags (:standard -O3 -color always + -unbox-closures -unbox-closures-factor 20)) + (libraries (bytes result)) + )) + +(ocamllex (CCSexp_lex)) diff --git a/src/threads/jbuild b/src/threads/jbuild new file mode 100644 index 00000000..4cd4e2b8 --- /dev/null +++ b/src/threads/jbuild @@ -0,0 +1,11 @@ + +(library + ((name containers_thread) + (public_name containers.thread) + (wrapped false) + (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always)) + (ocamlopt_flags (:standard -O3 -color always + -unbox-closures -unbox-closures-factor 20)) + (libraries (containers threads)) + )) + diff --git a/src/top/jbuild b/src/top/jbuild new file mode 100644 index 00000000..d42f7276 --- /dev/null +++ b/src/top/jbuild @@ -0,0 +1,12 @@ + + +(library + ((name containers_top) + (public_name containers.top) + (wrapped false) + (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always)) + (ocamlopt_flags (:standard -O3 -color always + -unbox-closures -unbox-closures-factor 20)) + (libraries (compiler-libs.common containers containers.data + containers.unix containers.sexp containers.iter)) + )) diff --git a/src/unix/.merlin b/src/unix/.merlin index 9ed5b46a..9b310e15 100644 --- a/src/unix/.merlin +++ b/src/unix/.merlin @@ -1,2 +1,5 @@ +B ../../_build/default/src/unix +FLG -w -40 -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always +PKG bytes +PKG result PKG unix -REC diff --git a/src/unix/jbuild b/src/unix/jbuild new file mode 100644 index 00000000..db46f8fa --- /dev/null +++ b/src/unix/jbuild @@ -0,0 +1,10 @@ + +(library + ((name containers_unix) + (public_name containers.unix) + (wrapped false) + (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always)) + (ocamlopt_flags (:standard -O3 -color always + -unbox-closures -unbox-closures-factor 20)) + (libraries (bytes result unix)) + ))