Skip to content
Snippets Groups Projects
Commit fc28ab09 authored by Virgile Prevosto's avatar Virgile Prevosto Committed by Andre Maroneze
Browse files

[stdlib] Transitioning support for 4.05 List functions

parent 36042690
No related branches found
No related tags found
No related merge requests found
...@@ -134,13 +134,30 @@ else ...@@ -134,13 +134,30 @@ else
SPLIT_ON_CHAR=split_on_char SPLIT_ON_CHAR=split_on_char
endif endif
ifeq ($(HAS_OCAML405),yes)
NTH_OPT=List.nth_opt
FIND_OPT=List.find_opt
ASSOC_OPT=List.assoc_opt
ASSQ_OPT=List.assq_opt
else
NTH_OPT=nth_opt
FIND_OPT=find_opt
ASSOC_OPT=assoc_opt
ASSQ_OPT=assq_opt
endif
src/libraries/stdlib/transitioning.ml: \ src/libraries/stdlib/transitioning.ml: \
src/libraries/stdlib/transitioning.ml.in \ src/libraries/stdlib/transitioning.ml.in \
Makefile.generating share/Makefile.config Makefile.generating share/Makefile.config
$(PRINT_MAKING) $@
rm -f $@ rm -f $@
sed \ sed \
-e 's/@SPLIT_ON_CHAR@/$(SPLIT_ON_CHAR)/g' \ -e 's/@SPLIT_ON_CHAR@/$(SPLIT_ON_CHAR)/g' \
-e 's/@STACK_FOLD@/$(STACK_FOLD)/g' \ -e 's/@STACK_FOLD@/$(STACK_FOLD)/g' \
-e 's/@NTH_OPT@/$(NTH_OPT)/g' \
-e 's/@FIND_OPT@/$(FIND_OPT)/g' \
-e 's/@ASSOC_OPT@/$(ASSOC_OPT)/g' \
-e 's/@ASSQ_OPT@/$(ASSQ_OPT)/g' \
$< > $@ $< > $@
$(CHMOD_RO) $@ $(CHMOD_RO) $@
......
...@@ -119,6 +119,7 @@ AC_SUBST(OCAMLPATCHNB) ...@@ -119,6 +119,7 @@ AC_SUBST(OCAMLPATCHNB)
AC_SUBST(HAS_OCAML403) AC_SUBST(HAS_OCAML403)
AC_SUBST(HAS_OCAML404) AC_SUBST(HAS_OCAML404)
AC_SUBST(HAS_OCAML405)
AC_SUBST(HAS_OCAML407) AC_SUBST(HAS_OCAML407)
OCAMLMAJORNB=$(echo $OCAMLVERSION | cut -f 1 -d .) OCAMLMAJORNB=$(echo $OCAMLVERSION | cut -f 1 -d .)
...@@ -127,22 +128,26 @@ OCAMLPATCHNB=$(echo $OCAMLVERSION | cut -f 3 -d .) ...@@ -127,22 +128,26 @@ OCAMLPATCHNB=$(echo $OCAMLVERSION | cut -f 3 -d .)
if test $OCAMLMAJORNB -gt 4; then if test $OCAMLMAJORNB -gt 4; then
HAS_OCAML403=yes; HAS_OCAML403=yes;
HAS_OCAML404=yes;
HAS_OCAML405=yes;
HAS_OCAML407=yes; HAS_OCAML407=yes;
else if test $OCAMLMINORNB -lt 3; then else
HAS_OCAML403=no; HAS_OCAML403=no;
HAS_OCAML404=no;
HAS_OCAML405=no;
HAS_OCAML407=no; HAS_OCAML407=no;
else if test $OCAMLMINORNB -ge 3; then
HAS_OCAML403=yes; HAS_OCAML403=yes;
if test $OCAMLMINORNB -lt 4; then fi;
HAS_OCAML404=no; if test $OCAMLMINORNB -ge 4; then
HAS_OCAML407=no; HAS_OCAML404=yes;
else if test $OCAMLMINORNB -lt 7; then fi;
HAS_OCAML407=no; if test $OCAMLMINORNB -ge 5; then
else HAS_OCAML405=yes;
fi;
if test $OCAMLMINORNB -ge 7; then
HAS_OCAML407=yes; HAS_OCAML407=yes;
fi; fi;
fi; # 404
fi; # 403
fi; # MAJORNB -gt 4 fi; # MAJORNB -gt 4
# Ocaml library path # Ocaml library path
......
...@@ -85,6 +85,7 @@ OCAMLPATCHNB ?=@OCAMLPATCHNB@ ...@@ -85,6 +85,7 @@ OCAMLPATCHNB ?=@OCAMLPATCHNB@
HAS_OCAML403 ?=@HAS_OCAML403@ HAS_OCAML403 ?=@HAS_OCAML403@
HAS_OCAML404 ?=@HAS_OCAML404@ HAS_OCAML404 ?=@HAS_OCAML404@
HAS_OCAML405 ?=@HAS_OCAML405@
HAS_OCAML407 ?=@HAS_OCAML407@ HAS_OCAML407 ?=@HAS_OCAML407@
NATIVE_THREADS ?=@HAS_NATIVE_THREADS@ NATIVE_THREADS ?=@HAS_NATIVE_THREADS@
......
...@@ -37,10 +37,25 @@ let stack_fold f x s = ...@@ -37,10 +37,25 @@ let stack_fold f x s =
Stack.iter do_it s; Stack.iter do_it s;
!res !res
let nth_opt l n =
try Some (List.nth l n)
with Failure _ when n >= 0 -> None
(* OCaml manual states that a negative argument still raises a Failure. *)
let find_opt f l = try Some (List.find f l) with Not_found -> None
let assoc_opt x l = try Some (List.assoc x l) with Not_found -> None
let assq_opt x l = try Some (List.assq x l) with Not_found -> None
(* the implementations above are only used in case we compile against an (* the implementations above are only used in case we compile against an
old OCaml version. Avoid unused warning in other cases. *) old OCaml version. Avoid unused warning in other cases. *)
let _: char -> string -> string list = split_on_char let _: char -> string -> string list = split_on_char
let _: ('a -> 'b -> 'a) -> 'a -> 'b Stack.t -> 'a = stack_fold let _: ('a -> 'b -> 'a) -> 'a -> 'b Stack.t -> 'a = stack_fold
let _: 'a list -> int -> 'a option = nth_opt
let _: ('a -> bool) -> 'a list -> 'a option = find_opt
let _: 'a -> ('a * 'b) list -> 'b option = assoc_opt
let _: 'a -> ('a * 'b) list -> 'b option = assq_opt
[@@@ warning "-3"] [@@@ warning "-3"]
...@@ -61,6 +76,13 @@ module Stack = struct ...@@ -61,6 +76,13 @@ module Stack = struct
let fold = @STACK_FOLD@ let fold = @STACK_FOLD@
end end
module List = struct
let nth_opt = @NTH_OPT@
let find_opt = @FIND_OPT@
let assoc_opt = @ASSOC_OPT@
let assq_opt = @ASSQ_OPT@
end
module Q = struct module Q = struct
let round_to_float x exact = let round_to_float x exact =
......
...@@ -58,6 +58,13 @@ module Stack: sig ...@@ -58,6 +58,13 @@ module Stack: sig
val fold: ('a -> 'b -> 'a) -> 'a -> 'b Stack.t -> 'a (** 4.03 *) val fold: ('a -> 'b -> 'a) -> 'a -> 'b Stack.t -> 'a (** 4.03 *)
end end
module List: sig
val nth_opt: 'a list -> int -> 'a option (** 4.05 *)
val find_opt: ('a -> bool) -> 'a list -> 'a option (** 4.05 *)
val assoc_opt: 'a -> ('a * 'b) list -> 'b option (** 4.05 *)
val assq_opt: 'a -> ('a * 'b) list -> 'b option (** 4.05 *)
end
(** {1 Zarith} *) (** {1 Zarith} *)
(** Function [Q.to_float] was introduced in Zarith 1.5 *) (** Function [Q.to_float] was introduced in Zarith 1.5 *)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment