mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
add shims for Atomic and Unit
This commit is contained in:
parent
4e0f35c078
commit
64ecd0c3ba
3 changed files with 43 additions and 1 deletions
|
|
@ -45,6 +45,8 @@ module String = CCString
|
||||||
module Vector = CCVector
|
module Vector = CCVector
|
||||||
module Monomorphic = CCMonomorphic
|
module Monomorphic = CCMonomorphic
|
||||||
module Utf8_string = CCUtf8_string
|
module Utf8_string = CCUtf8_string
|
||||||
|
module Unit = CCUnit
|
||||||
|
module Atomic = CCAtomic
|
||||||
|
|
||||||
module Sexp = CCSexp
|
module Sexp = CCSexp
|
||||||
module Sexp_intf = CCSexp_intf
|
module Sexp_intf = CCSexp_intf
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
(rule
|
(rule
|
||||||
(targets CCShims_.ml CCShimsList_.ml CCShimsFun_.ml CCShimsFun_.mli
|
(targets CCShims_.ml CCShimsList_.ml CCShimsFun_.ml CCShimsFun_.mli
|
||||||
CCShimsArray_.ml CCShimsFormat_.ml CCShimsMkLet_.ml CCShimsMkLetList_.ml
|
CCShimsArray_.ml CCShimsFormat_.ml CCShimsMkLet_.ml CCShimsMkLetList_.ml
|
||||||
CCShimsArrayLabels_.ml CCShimsInt_.ml)
|
CCShimsArrayLabels_.ml CCShimsInt_.ml CCAtomic.ml CCUnit.ml)
|
||||||
(deps ./mkshims.exe)
|
(deps ./mkshims.exe)
|
||||||
(action
|
(action
|
||||||
(run ./mkshims.exe)))
|
(run ./mkshims.exe)))
|
||||||
|
|
|
||||||
|
|
@ -204,6 +204,42 @@ let shims_int_post_408 = "
|
||||||
(** {{: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Int.html} Documentation for the standard Int module}*)
|
(** {{: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Int.html} Documentation for the standard Int module}*)
|
||||||
"
|
"
|
||||||
|
|
||||||
|
let shims_unit_before_408 = {|
|
||||||
|
type t = unit
|
||||||
|
let[@inline] equal (_:t) (_:t) = true
|
||||||
|
let[@inline] compare (_:t) (_:t) = 0
|
||||||
|
let to_string () = "()"
|
||||||
|
|}
|
||||||
|
|
||||||
|
let shims_unit_after_408 = "include Unit"
|
||||||
|
|
||||||
|
let shims_atomic_before_412 = {|
|
||||||
|
type 'a t = {mutable x: 'a}
|
||||||
|
let[@inline] make x = {x}
|
||||||
|
let[@inline] get {x} = x
|
||||||
|
let[@inline] set r x = r.x <- x
|
||||||
|
let[@inline] exchange r x =
|
||||||
|
let y = r.x in
|
||||||
|
r.x <- x;
|
||||||
|
y
|
||||||
|
|
||||||
|
let[@inline] compare_and_set r seen v =
|
||||||
|
if r.x == seen then (
|
||||||
|
r.x <- v;
|
||||||
|
true
|
||||||
|
) else false
|
||||||
|
|
||||||
|
let[@inline] fetch_and_add r x =
|
||||||
|
let v = r.x in
|
||||||
|
r.x <- x + r.x;
|
||||||
|
v
|
||||||
|
|
||||||
|
let[@inline] incr r = r.x <- 1 + r.x
|
||||||
|
let[@inline] decr r = r.x <- r.x - 1
|
||||||
|
|}
|
||||||
|
|
||||||
|
let shims_atomic_after_412 = {|include Atomic|}
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
C.main ~name:"mkshims" (fun c ->
|
C.main ~name:"mkshims" (fun c ->
|
||||||
let version = C.ocaml_config_var_exn c "version" in
|
let version = C.ocaml_config_var_exn c "version" in
|
||||||
|
|
@ -225,4 +261,8 @@ let () =
|
||||||
write_file "CCShimsMkLetList_.ml" (if (major, minor) >= (4,8) then shims_let_op_list_post_408 else shims_let_op_list_pre_408);
|
write_file "CCShimsMkLetList_.ml" (if (major, minor) >= (4,8) then shims_let_op_list_post_408 else shims_let_op_list_pre_408);
|
||||||
write_file "CCShimsInt_.ml"
|
write_file "CCShimsInt_.ml"
|
||||||
(if (major, minor) >= (4,8) then shims_int_post_408 else shims_int_pre_408);
|
(if (major, minor) >= (4,8) then shims_int_post_408 else shims_int_pre_408);
|
||||||
|
write_file "CCAtomic.ml"
|
||||||
|
(if (major, minor) >= (4,12) then shims_atomic_after_412 else shims_atomic_before_412);
|
||||||
|
write_file "CCUnit.ml"
|
||||||
|
(if (major, minor) >= (4,8) then shims_unit_after_408 else shims_unit_before_408);
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue