···11+v0.7.0 2022-03-23
22+-----------------
33+44+* restore dll support for cygwin64 / newer binutils versions (mingw64) (@fdopen, #40)
55+66+v0.6.0 2022-02-05
77+-----------------
88+99+* Add dependency on stdlib-shims (@kit-ty-kate, #38)
1010+1111+v0.5.1 2021-08-12
1212+-----------------
1313+1414+* Restore support for pre-4.05 OCaml versions (@yallop, #37)
1515+1616+v0.5.0 2021-07-31
1717+-----------------
1818+* Hex printing, and option-based parsing (@raphael-proust, #34)
1919+* Add stdlib-compatible string parsing (@mrmr1993, #32)
2020+2121+v0.4.0 2020-05-01
2222+-----------------
2323+* Expose Signed.S.Infix.(asr) (@dra27, #30)
2424+2525+v0.3.0 2019-02-15
2626+-----------------
2727+* Drop 4.01 support (@yallop, #23)
2828+* Add equal and pp to the output signatures (@emillon, #22)
2929+* Dune port (@rgrinberg, #21)
3030+* Add UInt64.(of|to)_uint32 (@yallop, #17)
3131+3232+v0.2.2 2016-12-19
3333+-----------------
3434+* Fix truncation in UInt64.of_int; remove other uses of `Val_int`/`Int_val`
3535+3636+v0.2.1 2016-11-14
3737+-----------------
3838+* Register the custom deserializers
3939+4040+v0.2.0 2016-10-04
4141+-----------------
4242+* Expose from_byte_size functions in Unsigned and Signed
4343+* Support for platforms where standard integer types are macros
4444+* Add 'max' and 'min' functions to Unsigned.S.
4545+* Expose private types for UChar, UInt8, UInt16.
4646+4747+0.1.0 2016-09-26
4848+----------------
4949+* Initial public release
+19
vendor/opam/integers/LICENSE.md
···11+Copyright (c) 2013-2016 Jeremy Yallop
22+33+Permission is hereby granted, free of charge, to any person obtaining a copy
44+of this software and associated documentation files (the "Software"), to deal
55+in the Software without restriction, including without limitation the rights
66+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
77+copies of the Software, and to permit persons to whom the Software is
88+furnished to do so, subject to the following conditions:
99+1010+The above copyright notice and this permission notice shall be included in
1111+all copies or substantial portions of the Software.
1212+1313+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1414+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1515+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1616+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1717+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919+THE SOFTWARE.
···11+# ocaml-integers
22+33+The `ocaml-integers` library provides a number of 8-, 16-, 32- and 64-bit signed and unsigned integer types, together with aliases such as `long` and `size_t` whose sizes depend on the host platform.
44+55+### Features
66+77+* The interfaces follow the pattern of the signatures of the [`Int32`][int32], [`Int64`][int64], and [`Nativeint`][nativeint] modules in the OCaml standard library.
88+99+ The behaviour also follows the standard library; for example, conversions such as `of_int` truncate, and operations are "modulo" in general:
1010+1111+ ```ocaml
1212+ # Unsigned.UInt8.(pred zero);;
1313+ - : Unsigned.UInt8.t = <uint8 255>
1414+ ```
1515+1616+* Top-level printers for each type are included
1717+1818+ ```ocaml
1919+ # Unsigned.UInt32.[of_int 103; one; of_string "1000"];;
2020+ - : Unsigned.UInt32.t list = [<uint32 103>; <uint32 1>; <uint32 1000>]
2121+ ```
2222+2323+* Infix operators are available:
2424+2525+ ```ocaml
2626+ # Unsigned.UInt32.(Infix.(one + one));;
2727+ - : Unsigned.UInt32.t = <uint32 2>
2828+ ```
2929+3030+* Polymorphic operations such as comparison behave correctly:
3131+3232+ ```ocaml
3333+ # open Unsigned.UInt32
3434+ # zero < one;;
3535+ - : bool = true
3636+ # max_int < zero;;
3737+ - : bool = false
3838+ ```
3939+4040+* Integers 32 bits and above are boxed; integers below 32 bits are unboxed.
4141+4242+ ```ocaml
4343+ # Obj.(tag (repr Unsigned.UInt32.zero));;
4444+ - : int = 255
4545+ # Obj.(tag (repr Unsigned.UInt16.zero));;
4646+ - : int = 1000
4747+ ```
4848+4949+### Using `integers` with js_of_ocaml
5050+5151+The [`integers_stubs_js`][integers_stubs_js] package provides JavaScript stubs that make it possible to use this library with [`js_of_ocaml`][js_of_ocaml]
5252+5353+[API documentation][doc]
5454+5555+[](https://github.com/ocamllabs/ocaml-integers/actions/workflows/test.yml)
5656+5757+[int32]: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Int32.html
5858+[int64]: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Int64.html
5959+[nativeint]: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Nativeint.html
6060+[doc]: https://yallop.github.io/ocaml-integers/api.docdir/
6161+[integers_stubs_js]: https://github.com/o1-labs/integers_stubs_js
6262+[js_of_ocaml]: https://github.com/ocsigen/js_of_ocaml
···11+(library
22+ (name integers)
33+ (public_name integers)
44+ (wrapped false)
55+ (install_c_headers ocaml_integers)
66+ (c_names unsigned_stubs)
77+ (libraries stdlib-shims)
88+ (synopsis "Signed and unsigned integers of various sizes"))
+34
vendor/opam/integers/src/ocaml_integers.h
···11+/*
22+ * Copyright (c) 2013 Jeremy Yallop.
33+ *
44+ * This file is distributed under the terms of the MIT License.
55+ * See the file LICENSE for details.
66+ */
77+88+#ifndef INTEGERS_UNSIGNED_STUBS_H
99+#define INTEGERS_UNSIGNED_STUBS_H
1010+1111+#include <caml/mlvalues.h>
1212+1313+#include <stdint.h>
1414+1515+#ifndef OCAML_INTEGERS_INTERNAL
1616+#ifdef __cplusplus
1717+extern "C" {
1818+#endif
1919+CAMLextern value integers_copy_uint32(uint32_t u);
2020+CAMLextern value integers_copy_uint64(uint64_t u);
2121+#ifdef __cplusplus
2222+}
2323+#endif
2424+#endif
2525+2626+#define Integers_val_uint8(t) ((Val_int((uint8_t)t)))
2727+#define Integers_val_uint16(t) ((Val_int((uint16_t)t)))
2828+2929+#define Uint8_val(V) ((uint8_t)(Int_val(V)))
3030+#define Uint16_val(V) ((uint16_t)(Int_val(V)))
3131+#define Uint32_val(V) (*((uint32_t *) Data_custom_val(V)))
3232+#define Uint64_val(V) (*((uint64_t *) Data_custom_val(V)))
3333+3434+#endif /* INTEGERS_UNSIGNED_STUBS_H */
+168
vendor/opam/integers/src/signed.ml
···11+(*
22+ * Copyright (c) 2013 Jeremy Yallop.
33+ * Copyright (c) 2021 Nomadic Labs
44+ *
55+ * This file is distributed under the terms of the MIT License.
66+ * See the file LICENSE for details.
77+ *)
88+99+module type Infix = sig
1010+ type t
1111+ include Unsigned.Infix with type t := t
1212+ val (asr) : t -> int -> t
1313+end
1414+1515+module type S = sig
1616+ type t
1717+1818+ module Infix : Infix with type t := t
1919+2020+ include Unsigned.S with type t := t
2121+ with module Infix := Infix
2222+2323+ val neg : t -> t
2424+ val abs : t -> t
2525+ val minus_one : t
2626+ val min_int : t
2727+ val shift_right_logical : t -> int -> t
2828+ val of_nativeint : nativeint -> t
2929+ val to_nativeint : t -> nativeint
3030+ val of_int64 : int64 -> t
3131+ val to_int64 : t -> int64
3232+end
3333+3434+module type Basics = sig
3535+ type t
3636+ val add : t -> t -> t
3737+ val sub : t -> t -> t
3838+ val mul : t -> t -> t
3939+ val div : t -> t -> t
4040+ val rem : t -> t -> t
4141+ val logand : t -> t -> t
4242+ val logor : t -> t -> t
4343+ val logxor : t -> t -> t
4444+ val shift_left : t -> int -> t
4545+ val shift_right : t -> int -> t
4646+ val shift_right_logical : t -> int -> t
4747+end
4848+4949+module MakeInfix(S : Basics) =
5050+struct
5151+ open S
5252+ let (+) = add
5353+ let (-) = sub
5454+ let ( * ) = mul
5555+ let (/) = div
5656+ let (mod) = rem
5757+ let (land) = logand
5858+ let (lor) = logor
5959+ let (lxor) = logxor
6060+ let (lsl) = shift_left
6161+ let (lsr) = shift_right_logical
6262+ let (asr) = shift_right
6363+end
6464+6565+external format_int : string -> int -> string = "caml_format_int"
6666+6767+module Int =
6868+struct
6969+ module Basics =
7070+ struct
7171+ type t = int
7272+ let add = ( + )
7373+ let sub = ( - )
7474+ let mul = ( * )
7575+ let div = ( / )
7676+ let rem = ( mod )
7777+ let max_int = Stdlib.max_int
7878+ let min_int = Stdlib.min_int
7979+ let logand = ( land )
8080+ let logor = ( lor )
8181+ let logxor = ( lxor )
8282+ let shift_left = ( lsl )
8383+ let shift_right = ( asr )
8484+ let shift_right_logical = ( lsr )
8585+ let of_int x = x
8686+ let to_int x = x
8787+ let of_string = int_of_string
8888+ let of_string_opt s = try Some (of_string s) with Failure _ -> None
8989+ let to_string = string_of_int
9090+ let to_hexstring = format_int "%x"
9191+ let zero = 0
9292+ let one = 1
9393+ let minus_one = -1
9494+ let lognot = lnot
9595+ let succ = Stdlib.succ
9696+ let pred = Stdlib.pred
9797+ let compare = Stdlib.compare
9898+ let equal = Stdlib.(=)
9999+ let max = Stdlib.max
100100+ let min = Stdlib.min
101101+ end
102102+ include Basics
103103+ module Infix = MakeInfix(Basics)
104104+ let to_int64 = Int64.of_int
105105+ let of_int64 = Int64.to_int
106106+ let to_nativeint = Nativeint.of_int
107107+ let of_nativeint = Nativeint.to_int
108108+ let abs = Stdlib.abs
109109+ let neg x = -x
110110+ let pp fmt n = Format.fprintf fmt "%d" n
111111+ let pp_hex fmt n = Format.fprintf fmt "%x" n
112112+end
113113+114114+module Int32 =
115115+struct
116116+ [@@@ocaml.warning "-32"]
117117+ (* Int32.equal was introduced in OCaml 4.03.0 *)
118118+ let equal (x:int32) (y:int32) = x = y
119119+ (* Int32.of_string_opt was introduced in OCaml 4.5b0.0 *)
120120+ let of_string_opt s = try Some (Int32.of_string s) with Failure _ -> None
121121+ include Int32
122122+ module Infix = MakeInfix(Int32)
123123+ let of_nativeint = Nativeint.to_int32
124124+ let to_nativeint = Nativeint.of_int32
125125+ let of_int64 = Int64.to_int32
126126+ let to_int64 = Int64.of_int32
127127+ let max = Stdlib.max
128128+ let min = Stdlib.min
129129+ let pp fmt n = Format.fprintf fmt "%ld" n
130130+ let pp_hex fmt n = Format.fprintf fmt "%lx" n
131131+ let to_hexstring n = Format.asprintf "%lx" n
132132+end
133133+134134+module Int64 =
135135+struct
136136+ [@@@ocaml.warning "-32"]
137137+ (* Int64.equal was introduced in OCaml 4.03.0 *)
138138+ let equal (x:int64) (y:int64) = x = y
139139+ (* Int32.of_string_opt was introduced in OCaml 4.5b0.0 *)
140140+ let of_string_opt s = try Some (Int64.of_string s) with Failure _ -> None
141141+ include Int64
142142+ module Infix = MakeInfix(Int64)
143143+ let of_int64 x = x
144144+ let to_int64 x = x
145145+ let max = Stdlib.max
146146+ let min = Stdlib.min
147147+ let pp fmt n = Format.fprintf fmt "%Ld" n
148148+ let pp_hex fmt n = Format.fprintf fmt "%Lx" n
149149+ let to_hexstring n = Format.asprintf "%Lx" n
150150+end
151151+152152+(* C guarantees that sizeof(t) == sizeof(unsigned t) *)
153153+external int_size : unit -> int = "integers_uint_size"
154154+external long_size : unit -> int = "integers_ulong_size"
155155+external llong_size : unit -> int = "integers_ulonglong_size"
156156+157157+let of_byte_size : int -> (module S) = function
158158+ | 4 -> (module Int32)
159159+ | 8 -> (module Int64)
160160+ | _ -> invalid_arg "Signed.of_byte_size"
161161+162162+module SInt = (val of_byte_size (int_size ()))
163163+module Long = (val of_byte_size (long_size ()))
164164+module LLong = (val of_byte_size (llong_size ()))
165165+166166+type sint = SInt.t
167167+type long = Long.t
168168+type llong = LLong.t
+90
vendor/opam/integers/src/signed.mli
···11+(*
22+ * Copyright (c) 2013 Jeremy Yallop.
33+ * Copyright (c) 2021 Nomadic Labs
44+ *
55+ * This file is distributed under the terms of the MIT License.
66+ * See the file LICENSE for details.
77+ *)
88+99+(** Types and operations for signed integers. *)
1010+1111+module type Infix = sig
1212+ type t
1313+1414+ include Unsigned.Infix with type t := t
1515+1616+ val (asr) : t -> int -> t
1717+ (** [x asr y] shifts [x] to the right by [y] bits. See {!shift_right}. *)
1818+end
1919+2020+2121+module type S = sig
2222+ type t
2323+2424+ module Infix : Infix with type t := t
2525+2626+ include Unsigned.S with type t := t
2727+ with module Infix := Infix
2828+2929+ val neg : t -> t
3030+ (** Unary negation. *)
3131+3232+ val abs : t -> t
3333+ (** Return the absolute value of its argument. *)
3434+3535+ val minus_one : t
3636+ (** The value -1 *)
3737+3838+ val min_int : t
3939+ (** The smallest representable integer. *)
4040+4141+ val shift_right_logical : t -> int -> t
4242+ (** {!shift_right_logical} [x] [y] shifts [x] to the right by [y] bits. See
4343+ {!Int32.shift_right_logical}. *)
4444+4545+ val of_nativeint : nativeint -> t
4646+ (** Convert the given nativeint value to a signed integer. *)
4747+4848+ val to_nativeint : t -> nativeint
4949+ (** Convert the given signed integer to a nativeint value. *)
5050+5151+ val of_int64 : int64 -> t
5252+ (** Convert the given int64 value to a signed integer. *)
5353+5454+ val to_int64 : t -> int64
5555+ (** Convert the given signed integer to an int64 value. *)
5656+end
5757+(** Signed integer operations *)
5858+5959+module Int : S with type t = int
6060+(** Signed integer type and operations. *)
6161+6262+module Int32 : S with type t = int32
6363+(** Signed 32-bit integer type and operations. *)
6464+6565+module Int64 : S with type t = int64
6666+(** Signed 64-bit integer type and operations. *)
6767+6868+module SInt : S
6969+(** C's signed integer type and operations. *)
7070+7171+module Long : S
7272+(** The signed long integer type and operations. *)
7373+7474+module LLong : S
7575+(** The signed long long integer type and operations. *)
7676+7777+type sint = SInt.t
7878+(** C's signed integer type. *)
7979+8080+type long = Long.t
8181+(** The signed long integer type. *)
8282+8383+type llong = LLong.t
8484+(** The signed long long integer type. *)
8585+8686+val of_byte_size : int -> (module S)
8787+(** [of_byte_size b] is a module of type S that implements a signed type
8888+ with [b] bytes.
8989+9090+ Raise [Invalid_argument] if no suitable type is available. *)
+313
vendor/opam/integers/src/unsigned.ml
···11+(*
22+ * Copyright (c) 2013 Jeremy Yallop.
33+ * Copyright (c) 2021 Nomadic Labs
44+ *
55+ * This file is distributed under the terms of the MIT License.
66+ * See the file LICENSE for details.
77+ *)
88+99+external init : unit -> unit = "integers_unsigned_init"
1010+let () = init ()
1111+1212+(* Boxed unsigned types *)
1313+module type Basics = sig
1414+ type t
1515+1616+ val add : t -> t -> t
1717+ val sub : t -> t -> t
1818+ val mul : t -> t -> t
1919+ val div : t -> t -> t
2020+ val rem : t -> t -> t
2121+ val max_int : t
2222+ val logand : t -> t -> t
2323+ val logor : t -> t -> t
2424+ val logxor : t -> t -> t
2525+ val shift_left : t -> int -> t
2626+ val shift_right : t -> int -> t
2727+ val of_int : int -> t
2828+ val to_int : t -> int
2929+ val of_int64 : int64 -> t
3030+ val to_int64 : t -> int64
3131+ val of_string : string -> t
3232+ val to_string : t -> string
3333+ val to_hexstring : t -> string
3434+end
3535+3636+3737+module type Extras = sig
3838+ type t
3939+4040+ val zero : t
4141+ val one : t
4242+ val lognot : t -> t
4343+ val succ : t -> t
4444+ val pred : t -> t
4545+ val compare : t -> t -> int
4646+ val equal : t -> t -> bool
4747+ val max : t -> t -> t
4848+ val min : t -> t -> t
4949+ val of_string_opt : string -> t option
5050+ val pp : Format.formatter -> t -> unit
5151+ val pp_hex : Format.formatter -> t -> unit
5252+end
5353+5454+5555+module type Infix = sig
5656+ type t
5757+ val (+) : t -> t -> t
5858+ val (-) : t -> t -> t
5959+ val ( * ) : t -> t -> t
6060+ val (/) : t -> t -> t
6161+ val (mod) : t -> t -> t
6262+ val (land) : t -> t -> t
6363+ val (lor) : t -> t -> t
6464+ val (lxor) : t -> t -> t
6565+ val (lsl) : t -> int -> t
6666+ val (lsr) : t -> int -> t
6767+end
6868+6969+7070+module type S = sig
7171+ include Basics
7272+ include Extras with type t := t
7373+7474+ module Infix : Infix with type t := t
7575+end
7676+7777+7878+module MakeInfix (B : Basics) =
7979+struct
8080+ open B
8181+ let (+) = add
8282+ let (-) = sub
8383+ let ( * ) = mul
8484+ let (/) = div
8585+ let (mod) = rem
8686+ let (land) = logand
8787+ let (lor) = logor
8888+ let (lxor) = logxor
8989+ let (lsl) = shift_left
9090+ let (lsr) = shift_right
9191+end
9292+9393+9494+module Extras(Basics : Basics) : Extras with type t := Basics.t =
9595+struct
9696+ open Basics
9797+ let zero = of_int 0
9898+ let one = of_int 1
9999+ let succ n = add n one
100100+ let pred n = sub n one
101101+ let lognot n = logxor n max_int
102102+ let compare (x : t) (y : t) = Stdlib.compare x y
103103+ let equal (x : t) (y : t) = Stdlib.(=) x y
104104+ let max (x : t) (y : t) = Stdlib.max x y
105105+ let min (x : t) (y : t) = Stdlib.min x y
106106+ let of_string_opt (s : string) = try Some (of_string s) with Failure _ -> None
107107+ let pp fmt x = Format.fprintf fmt "%s" (to_string x)
108108+ let pp_hex fmt x = Format.fprintf fmt "%s" (to_hexstring x)
109109+end
110110+111111+external format_int : string -> int -> string = "caml_format_int"
112112+113113+module UInt8 : S with type t = private int =
114114+struct
115115+ module B =
116116+ struct
117117+ type t = int
118118+ let max_int = 255
119119+ let add : t -> t -> t = fun x y -> (x + y) land max_int
120120+ let sub : t -> t -> t = fun x y -> (x - y) land max_int
121121+ let mul : t -> t -> t = fun x y -> (x * y) land max_int
122122+ let div : t -> t -> t = (/)
123123+ let rem : t -> t -> t = (mod)
124124+ let logand: t -> t -> t = (land)
125125+ let logor: t -> t -> t = (lor)
126126+ let logxor : t -> t -> t = (lxor)
127127+ let shift_left : t -> int -> t = fun x y -> (x lsl y) land max_int
128128+ let shift_right : t -> int -> t = (lsr)
129129+ let of_int (x: int): t =
130130+ (* For backwards compatibility, this wraps *)
131131+ x land max_int
132132+ external to_int : t -> int = "%identity"
133133+ let of_int64 : int64 -> t = fun x -> of_int (Int64.to_int x)
134134+ let to_int64 : t -> int64 = fun x -> Int64.of_int (to_int x)
135135+ external of_string : string -> t = "integers_uint8_of_string"
136136+ let to_string : t -> string = string_of_int
137137+ let to_hexstring : t -> string = format_int "%x"
138138+ end
139139+ include B
140140+ include Extras(B)
141141+ module Infix = MakeInfix(B)
142142+end
143143+144144+145145+module UInt16 : S with type t = private int =
146146+struct
147147+ module B =
148148+ struct
149149+ type t = int
150150+ let max_int = 65535
151151+ let add : t -> t -> t = fun x y -> (x + y) land max_int
152152+ let sub : t -> t -> t = fun x y -> (x - y) land max_int
153153+ let mul : t -> t -> t = fun x y -> (x * y) land max_int
154154+ let div : t -> t -> t = (/)
155155+ let rem : t -> t -> t = (mod)
156156+ let logand: t -> t -> t = (land)
157157+ let logor: t -> t -> t = (lor)
158158+ let logxor : t -> t -> t = (lxor)
159159+ let shift_left : t -> int -> t = fun x y -> (x lsl y) land max_int
160160+ let shift_right : t -> int -> t = (lsr)
161161+ let of_int (x: int): t =
162162+ (* For backwards compatibility, this wraps *)
163163+ x land max_int
164164+ external to_int : t -> int = "%identity"
165165+ let of_int64 : int64 -> t = fun x -> Int64.to_int x |> of_int
166166+ let to_int64 : t -> int64 = fun x -> to_int x |> Int64.of_int
167167+ external of_string : string -> t = "integers_uint16_of_string"
168168+ let to_string : t -> string = string_of_int
169169+ let to_hexstring : t -> string = format_int "%x"
170170+ end
171171+ include B
172172+ include Extras(B)
173173+ module Infix = MakeInfix(B)
174174+end
175175+176176+177177+module UInt32 : sig
178178+ include S
179179+ val of_int32 : int32 -> t
180180+ val to_int32 : t -> int32
181181+end =
182182+struct
183183+ module B =
184184+ struct
185185+ type t
186186+ external add : t -> t -> t = "integers_uint32_add"
187187+ external sub : t -> t -> t = "integers_uint32_sub"
188188+ external mul : t -> t -> t = "integers_uint32_mul"
189189+ external div : t -> t -> t = "integers_uint32_div"
190190+ external rem : t -> t -> t = "integers_uint32_rem"
191191+ external logand : t -> t -> t = "integers_uint32_logand"
192192+ external logor : t -> t -> t = "integers_uint32_logor"
193193+ external logxor : t -> t -> t = "integers_uint32_logxor"
194194+ external shift_left : t -> int -> t = "integers_uint32_shift_left"
195195+ external shift_right : t -> int -> t = "integers_uint32_shift_right"
196196+ external of_string : string -> t = "integers_uint32_of_string"
197197+ external to_string : t -> string = "integers_uint32_to_string"
198198+ external to_hexstring : t -> string = "integers_uint32_to_hexstring"
199199+ external of_int : int -> t = "integers_uint32_of_int"
200200+ external to_int : t -> int = "integers_uint32_to_int"
201201+202202+ external of_int32 : int32 -> t = "integers_uint32_of_int32"
203203+ let half_max_plus_two = of_string "0x80000001"
204204+ let half_max_minus_one_signed = 0x7fffffffl
205205+ let of_int32 i32 =
206206+ if i32 >= 0l then
207207+ of_int32 i32
208208+ else
209209+ add half_max_plus_two (of_int32 (Int32.add i32 half_max_minus_one_signed))
210210+211211+ external to_int32 : t -> int32 = "integers_int32_of_uint32"
212212+ let max_signed = of_int32 Int32.max_int
213213+ let to_int32 u32 =
214214+ if Stdlib.compare u32 max_signed <= 0 then
215215+ to_int32 u32
216216+ else
217217+ Int32.sub (to_int32 (sub u32 half_max_plus_two)) half_max_minus_one_signed
218218+219219+ external of_int64 : int64 -> t = "integers_uint32_of_int64"
220220+ external to_int64 : t -> int64 = "integers_uint32_to_int64"
221221+ external _max_int : unit -> t = "integers_uint32_max"
222222+ let max_int = _max_int ()
223223+ end
224224+ include B
225225+ include Extras(B)
226226+ module Infix = MakeInfix(B)
227227+end
228228+229229+230230+module UInt64 : sig
231231+ include S
232232+ external of_uint32 : UInt32.t -> t = "integers_uint64_of_uint32"
233233+ external to_uint32 : t -> UInt32.t = "integers_uint32_of_uint64"
234234+end =
235235+struct
236236+ module B =
237237+ struct
238238+ type t
239239+ external add : t -> t -> t = "integers_uint64_add"
240240+ external sub : t -> t -> t = "integers_uint64_sub"
241241+ external mul : t -> t -> t = "integers_uint64_mul"
242242+ external div : t -> t -> t = "integers_uint64_div"
243243+ external rem : t -> t -> t = "integers_uint64_rem"
244244+ external logand : t -> t -> t = "integers_uint64_logand"
245245+ external logor : t -> t -> t = "integers_uint64_logor"
246246+ external logxor : t -> t -> t = "integers_uint64_logxor"
247247+ external shift_left : t -> int -> t = "integers_uint64_shift_left"
248248+ external shift_right : t -> int -> t = "integers_uint64_shift_right"
249249+ external of_int : int -> t = "integers_uint64_of_int"
250250+ external to_int : t -> int = "integers_uint64_to_int"
251251+ external of_string : string -> t = "integers_uint64_of_string"
252252+ external to_string : t -> string = "integers_uint64_to_string"
253253+ external to_hexstring : t -> string = "integers_uint64_to_hexstring"
254254+255255+ external of_int64 : int64 -> t = "integers_uint64_of_int64"
256256+ let half_max_plus_two = of_string "0x8000000000000001"
257257+ let half_max_minus_one_signed = 0x7fffffffffffffffL
258258+ let of_int64 i64 =
259259+ if i64 >= 0L then
260260+ of_int64 i64
261261+ else
262262+ add half_max_plus_two (of_int64 (Int64.add i64 half_max_minus_one_signed))
263263+264264+ external to_int64 : t -> int64 = "integers_uint64_to_int64"
265265+ let max_signed = of_int64 Int64.max_int
266266+ let to_int64 u64 =
267267+ if Stdlib.compare u64 max_signed <= 0 then
268268+ to_int64 u64
269269+ else
270270+ Int64.sub (to_int64 (sub u64 half_max_plus_two)) half_max_minus_one_signed
271271+272272+ external of_uint32 : UInt32.t -> t = "integers_uint64_of_uint32"
273273+ external to_uint32 : t -> UInt32.t = "integers_uint32_of_uint64"
274274+ external _max_int : unit -> t = "integers_uint64_max"
275275+ let max_int = _max_int ()
276276+ end
277277+ include B
278278+ include Extras(B)
279279+ module Infix = MakeInfix(B)
280280+end
281281+282282+283283+let of_byte_size : int -> (module S) = function
284284+ | 1 -> (module UInt8)
285285+ | 2 -> (module UInt16)
286286+ | 4 -> (module UInt32)
287287+ | 8 -> (module UInt64)
288288+ | _ -> invalid_arg "Unsigned.of_byte_size"
289289+290290+291291+external size_t_size : unit -> int = "integers_size_t_size"
292292+external ushort_size : unit -> int = "integers_ushort_size"
293293+external uint_size : unit -> int = "integers_uint_size"
294294+external ulong_size : unit -> int = "integers_ulong_size"
295295+external ulonglong_size : unit -> int = "integers_ulonglong_size"
296296+297297+module Size_t : S = (val of_byte_size (size_t_size ()))
298298+module UChar = UInt8
299299+module UShort : S = (val of_byte_size (ushort_size ()))
300300+module UInt : S = (val of_byte_size (uint_size ()))
301301+module ULong : S = (val of_byte_size (ulong_size ()))
302302+module ULLong : S = (val of_byte_size (ulonglong_size ()))
303303+304304+type uchar = UChar.t
305305+type uint8 = UInt8.t
306306+type uint16 = UInt16.t
307307+type uint32 = UInt32.t
308308+type uint64 = UInt64.t
309309+type size_t = Size_t.t
310310+type ushort = UShort.t
311311+type uint = UInt.t
312312+type ulong = ULong.t
313313+type ullong = ULLong.t
+270
vendor/opam/integers/src/unsigned.mli
···11+(*
22+ * Copyright (c) 2013 Jeremy Yallop.
33+ * Copyright (c) 2021 Nomadic Labs
44+ *
55+ * This file is distributed under the terms of the MIT License.
66+ * See the file LICENSE for details.
77+ *)
88+99+(** Types and operations for unsigned integers. *)
1010+1111+module type Infix = sig
1212+ type t
1313+1414+ val (+) : t -> t -> t
1515+ (** Addition. See {!add}. *)
1616+1717+ val (-) : t -> t -> t
1818+ (** Subtraction. See {!sub}.*)
1919+2020+ val ( * ) : t -> t -> t
2121+ (** Multiplication. See {!mul}.*)
2222+2323+ val (/) : t -> t -> t
2424+ (** Division. See {!div}.*)
2525+2626+ val (mod) : t -> t -> t
2727+ (** Integer remainder. See {!rem}. *)
2828+2929+ val (land) : t -> t -> t
3030+ (** Bitwise logical and. See {!logand}. *)
3131+3232+ val (lor) : t -> t -> t
3333+ (** Bitwise logical or. See {!logor}. *)
3434+3535+ val (lxor) : t -> t -> t
3636+ (** Bitwise logical exclusive or. See {!logxor}. *)
3737+3838+ val (lsl) : t -> int -> t
3939+ (** [x lsl y] shifts [x] to the left by [y] bits. See {!shift_left}. *)
4040+4141+ val (lsr) : t -> int -> t
4242+ (** [x lsr y] shifts [x] to the right by [y] bits. See {!shift_right}. *)
4343+end
4444+(** Infix names for the unsigned integer operations. *)
4545+4646+4747+module type S = sig
4848+ type t
4949+5050+ val add : t -> t -> t
5151+ (** Addition. *)
5252+5353+ val sub : t -> t -> t
5454+ (** Subtraction. *)
5555+5656+ val mul : t -> t -> t
5757+ (** Multiplication. *)
5858+5959+ val div : t -> t -> t
6060+ (** Division. Raise {!Division_by_zero} if the second argument is zero. *)
6161+6262+ val rem : t -> t -> t
6363+ (** Integer remainder. Raise {!Division_by_zero} if the second argument is
6464+ zero. *)
6565+6666+ val max_int : t
6767+ (** The greatest representable integer. *)
6868+6969+ val logand : t -> t -> t
7070+ (** Bitwise logical and. *)
7171+7272+ val logor : t -> t -> t
7373+ (** Bitwise logical or. *)
7474+7575+ val logxor : t -> t -> t
7676+ (** Bitwise logical exclusive or. *)
7777+7878+ val shift_left : t -> int -> t
7979+ (** {!shift_left} [x] [y] shifts [x] to the left by [y] bits. *)
8080+8181+ val shift_right : t -> int -> t
8282+ (** {!shift_right} [x] [y] shifts [x] to the right by [y] bits. *)
8383+8484+ val of_int : int -> t
8585+ (** Convert the given int value to an unsigned integer. *)
8686+8787+ val to_int : t -> int
8888+ (** Convert the given unsigned integer value to an int. *)
8989+9090+ val of_int64 : int64 -> t
9191+ (** Convert the given int64 value to an unsigned integer. *)
9292+9393+ val to_int64 : t -> int64
9494+ (** Convert the given unsigned integer value to an int64. *)
9595+9696+ val of_string : string -> t
9797+ (** Convert the given string to an unsigned integer. Raise {!Failure}
9898+ if the given string is not a valid representation of an unsigned
9999+ integer. *)
100100+101101+ val to_string : t -> string
102102+ (** Return the string representation of its argument. *)
103103+104104+ val to_hexstring : t -> string
105105+ (** Return the hexadecimal string representation of its argument. *)
106106+107107+ val zero : t
108108+ (** The integer 0. *)
109109+110110+ val one : t
111111+ (** The integer 1. *)
112112+113113+ val lognot : t -> t
114114+ (** Bitwise logical negation. *)
115115+116116+ val succ : t -> t
117117+ (** Successor. *)
118118+119119+ val pred : t -> t
120120+ (** Predecessor. *)
121121+122122+ val compare : t -> t -> int
123123+ (** The comparison function for unsigned integers, with the same
124124+ specification as {!Stdlib.compare}. *)
125125+126126+ val equal : t -> t -> bool
127127+ (** Tests for equality, with the same specification as {!Stdlib.(=)}. *)
128128+129129+ val max : t -> t -> t
130130+ (** [max x y] is the greater of [x] and [y] *)
131131+132132+ val min : t -> t -> t
133133+ (** [min x y] is the lesser of [x] and [y] *)
134134+135135+ val of_string_opt : string -> t option
136136+ (** Convert the given string to an unsigned integer. Returns [None] if the
137137+ given string is not a valid representation of an unsigned integer. *)
138138+139139+ val pp : Format.formatter -> t -> unit
140140+ (** Output the result of {!to_string} on a formatter. *)
141141+142142+ val pp_hex : Format.formatter -> t -> unit
143143+ (** Output the result of {!to_hexstring} on a formatter. *)
144144+145145+ module Infix : Infix with type t := t
146146+end
147147+(** Unsigned integer operations. *)
148148+149149+module UChar : S with type t = private int
150150+(** Unsigned char type and operations. *)
151151+152152+module UInt8 : S with type t = private int
153153+(** Unsigned 8-bit integer type and operations. *)
154154+155155+module UInt16 : S with type t = private int
156156+(** Unsigned 16-bit integer type and operations. *)
157157+158158+module UInt32 : sig
159159+ include S
160160+ val of_int32 : int32 -> t
161161+ (** Convert the given 32-bit signed integer to an unsigned 32-bit integer.
162162+163163+ If the signed integer fits within the unsigned range (in other words, if
164164+ the signed integer is positive) then the numerical values represented by
165165+ the signed and unsigned integers are the same.
166166+167167+ Whether the signed integer fits or not, the function [of_int32] is always
168168+ the inverse of the function {!to_int32}. In other words,
169169+ [to_int32 (of_int32 x) = x] holds for all [x : int32]. *)
170170+171171+ val to_int32 : t -> int32
172172+ (** Convert the given 32-bit unsigned integer to a signed 32-bit integer.
173173+174174+ If the unsigned integer fits within the signed range (in other words, if
175175+ the unsigned integer is less than {!Int32.max_int}) then the numerical
176176+ values represented by unsigned and signed integers are the same.
177177+178178+ Whether the unsigned integer fits or not, the function [to_int32] is
179179+ always the inverse of the function {!of_int32}. In other words,
180180+ [of_int32 (to_int32 x) = x] holds for all [x : t]. *)
181181+end
182182+(** Unsigned 32-bit integer type and operations. *)
183183+184184+module UInt64 : sig
185185+ include S
186186+187187+ val of_int64 : int64 -> t
188188+ (** Convert the given 64-bit signed integer to an unsigned 64-bit integer.
189189+190190+ If the signed integer fits within the unsigned range (in other words, if
191191+ the signed integer is positive) then the numerical values represented by
192192+ the signed and unsigned integers are the same.
193193+194194+ Whether the signed integer fits or not, the function [of_int64] is always
195195+ the inverse of the function {!to_int64}. In other words,
196196+ [to_int64 (of_int64 x) = x] holds for all [x : int64]. *)
197197+198198+ val to_int64 : t -> int64
199199+ (** Convert the given 64-bit unsigned integer to a signed 64-bit integer.
200200+201201+ If the unsigned integer fits within the signed range (in other words, if
202202+ the unsigned integer is less than {!Int64.max_int}) then the numerical
203203+ values represented by unsigned and signed integers are the same.
204204+205205+ Whether the unsigned integer fits or not, the function [to_int64] is
206206+ always the inverse of the function {!of_int64}. In other words,
207207+ [of_int64 (to_int64 x) = x] holds for all [x : t]. *)
208208+209209+ val of_uint32 : UInt32.t -> t
210210+ (** Convert the given 32-bit unsigned integer to a 64-bit unsigned
211211+ integer. *)
212212+213213+ val to_uint32 : t -> UInt32.t
214214+ (** Convert the given 64-bit unsigned integer to a 32-bit unsigned integer.
215215+ The 64-bit unsigned integer is taken modulo 2{^32}, i.e. the top 32 bits
216216+ are lost during the conversion. *)
217217+end
218218+(** Unsigned 64-bit integer type and operations. *)
219219+220220+module Size_t : S
221221+(** The size_t unsigned integer type and operations. *)
222222+223223+module UShort : S
224224+(** The unsigned short integer type and operations. *)
225225+226226+module UInt : S
227227+(** The unsigned int type and operations. *)
228228+229229+module ULong : S
230230+(** The unsigned long integer type and operations. *)
231231+232232+module ULLong : S
233233+(** The unsigned long long integer type and operations. *)
234234+235235+236236+type uchar = UChar.t
237237+(** The unsigned char type. *)
238238+239239+type uint8 = UInt8.t
240240+(** Unsigned 8-bit integer type. *)
241241+242242+type uint16 = UInt16.t
243243+(** Unsigned 16-bit integer type. *)
244244+245245+type uint32 = UInt32.t
246246+(** Unsigned 32-bit integer type. *)
247247+248248+type uint64 = UInt64.t
249249+(** Unsigned 64-bit integer type. *)
250250+251251+type size_t = Size_t.t
252252+(** The size_t unsigned integer type. *)
253253+254254+type ushort = UShort.t
255255+(** The unsigned short unsigned integer type. *)
256256+257257+type uint = UInt.t
258258+(** The unsigned int type. *)
259259+260260+type ulong = ULong.t
261261+(** The unsigned long integer type. *)
262262+263263+type ullong = ULLong.t
264264+(** The unsigned long long integer type. *)
265265+266266+val of_byte_size : int -> (module S)
267267+(** [of_byte_size b] is a module of type S that implements an unsigned type
268268+ with [b] bytes.
269269+270270+ Raise [Invalid_argument] if no suitable type is available. *)
+347
vendor/opam/integers/src/unsigned_stubs.c
···11+/*
22+ * Copyright (c) 2013 Jeremy Yallop.
33+ *
44+ * This file is distributed under the terms of the MIT License.
55+ * See the file LICENSE for details.
66+ */
77+88+#if !__USE_MINGW_ANSI_STDIO && (defined(__MINGW32__) || defined(__MINGW64__))
99+#define __USE_MINGW_ANSI_STDIO 1
1010+#endif
1111+1212+#include <caml/mlvalues.h>
1313+#include <caml/custom.h>
1414+#include <caml/alloc.h>
1515+#include <caml/intext.h>
1616+#include <caml/fail.h>
1717+1818+#include <inttypes.h>
1919+#include <stdint.h>
2020+#include <limits.h>
2121+#include <stdio.h>
2222+2323+#define OCAML_INTEGERS_INTERNAL 1
2424+#include "ocaml_integers.h"
2525+2626+#define UINT_DECLS(BITS) \
2727+ extern value integers_copy_uint ## BITS(uint ## BITS ## _t u); \
2828+ /* uintX_add : t -> t -> t */ \
2929+ extern value integers_uint ## BITS ## _ ## add(value a, value b); \
3030+ /* uintX_sub : t -> t -> t */ \
3131+ extern value integers_uint ## BITS ## _ ## sub(value a, value b); \
3232+ /* uintX_mul : t -> t -> t */ \
3333+ extern value integers_uint ## BITS ## _ ## mul(value a, value b); \
3434+ /* uintX_div : t -> t -> t */ \
3535+ extern value integers_uint ## BITS ## _ ## div(value a, value b); \
3636+ /* uintX_rem : t -> t -> t */ \
3737+ extern value integers_uint ## BITS ## _ ## rem(value a, value b); \
3838+ /* uintX_logand : t -> t -> t */ \
3939+ extern value integers_uint ## BITS ## _ ## logand(value a, value b); \
4040+ /* uintX_logor : t -> t -> t */ \
4141+ extern value integers_uint ## BITS ## _ ## logor(value a, value b); \
4242+ /* uintX_logxor : t -> t -> t */ \
4343+ extern value integers_uint ## BITS ## _ ## logxor(value a, value b); \
4444+ /* uintX_shift_left : t -> t -> t */ \
4545+ extern value integers_uint ## BITS ## _ ## shift_left(value a, value b); \
4646+ /* uintX_shift_right : t -> t -> t */ \
4747+ extern value integers_uint ## BITS ## _ ## shift_right(value a, value b); \
4848+ /* of_int : int -> t */ \
4949+ extern value integers_uint ## BITS ## _of_int(value a); \
5050+ /* to_int : t -> int */ \
5151+ extern value integers_uint ## BITS ## _to_int(value a); \
5252+ /* of_string : string -> t */ \
5353+ extern value integers_uint ## BITS ## _of_string(value a); \
5454+ /* to_string : t -> string */ \
5555+ extern value integers_uint ## BITS ## _to_string(value a); \
5656+ /* max : unit -> t */ \
5757+ extern value integers_uint ## BITS ## _max(value a);
5858+5959+#define UINT_SMALL_DECLS(BITS) \
6060+ /* of_string : string -> t */ \
6161+ extern value integers_uint ## BITS ## _of_string(value a); \
6262+ /* to_string : t -> string */ \
6363+ extern value integers_uint ## BITS ## _to_string(value a); \
6464+ /* max : unit -> t */ \
6565+ extern value integers_uint ## BITS ## _max(value a);
6666+6767+UINT_SMALL_DECLS(8)
6868+UINT_SMALL_DECLS(16)
6969+UINT_DECLS(32)
7070+UINT_DECLS(64)
7171+7272+/* X_size : unit -> int */
7373+extern value integers_size_t_size (value _);
7474+extern value integers_ushort_size (value _);
7575+extern value integers_uint_size (value _);
7676+extern value integers_ulong_size (value _);
7777+extern value integers_ulonglong_size (value _);
7878+7979+8080+static int parse_digit(char c)
8181+{
8282+ if (c >= '0' && c <= '9')
8383+ return c - '0';
8484+ else if (c >= 'A' && c <= 'F')
8585+ return c - 'A' + 10;
8686+ else if (c >= 'a' && c <= 'f')
8787+ return c - 'a' + 10;
8888+ else
8989+ return -1;
9090+}
9191+9292+#define Uint_custom_val(SIZE, V) Uint_custom_val_(SIZE, V)
9393+#define Uint_custom_val_(SIZE, V) \
9494+ (*(uint ## SIZE ## _t *)(Data_custom_val(V)))
9595+9696+#define TYPE(SIZE) uint ## SIZE ## _t
9797+#define BUF_SIZE(TYPE) ((sizeof(TYPE) * CHAR_BIT + 2) / 3 + 1)
9898+9999+#define UINT_PRIMOP(NAME, SIZE, OP) \
100100+ /* OP : t -> t -> t */ \
101101+ value integers_uint ## SIZE ## _ ## NAME(value a, value b) \
102102+ { \
103103+ return integers_copy_uint ## SIZE(Uint_custom_val(SIZE, a) \
104104+ OP Uint_custom_val(SIZE, b)); \
105105+ }
106106+107107+#define UINT_OF_STRING(BITS, COPY) \
108108+ value integers_uint ## BITS ## _of_string(value a) \
109109+ { \
110110+ TYPE(BITS) u, max_prefix; \
111111+ const char *pos = String_val(a); \
112112+ int base = 10, d; \
113113+ \
114114+ /* Strip a leading + sign, if given */ \
115115+ if (*pos == '+') pos++; \
116116+ if (*pos == '0') { \
117117+ switch (pos[1]) { \
118118+ case 'x': case 'X': \
119119+ base = 16; pos += 2; break; \
120120+ case 'o': case 'O': \
121121+ base = 8; pos += 2; break; \
122122+ case 'b': case 'B': \
123123+ base = 2; pos += 2; break; \
124124+ case 'u': case 'U': /* Unsigned prefix. No-op for unsigned types */ \
125125+ pos += 2; break; \
126126+ } \
127127+ } \
128128+ \
129129+ max_prefix = ((TYPE(BITS)) -1) / base; \
130130+ \
131131+ d = parse_digit(*pos); \
132132+ if (d < 0 || d >= base) { \
133133+ caml_failwith("UInt"#BITS".of_string"); \
134134+ } \
135135+ u = (TYPE(BITS)) d; \
136136+ pos++; \
137137+ \
138138+ for (;; pos++) { \
139139+ if (*pos == '_') continue; \
140140+ d = parse_digit(*pos); \
141141+ /* Halt if the digit isn't valid (or this is the string terminator) */ \
142142+ if (d < 0 || d >= base) break; \
143143+ /* Check that we can add another digit */ \
144144+ if (u > max_prefix) break; \
145145+ u = d + u * base; \
146146+ /* Check for overflow */ \
147147+ if (u < (TYPE(BITS)) d) break; \
148148+ } \
149149+ \
150150+ if (pos != String_val(a) + caml_string_length(a)){ \
151151+ caml_failwith("UInt"#BITS".of_string"); \
152152+ } \
153153+ \
154154+ return COPY(u); \
155155+ } \
156156+157157+#define UINT_DEFS(BITS, BYTES) \
158158+ static int uint ## BITS ## _cmp(value v1, value v2) \
159159+ { \
160160+ TYPE(BITS) u1 = Uint_custom_val(BITS, v1); \
161161+ TYPE(BITS) u2 = Uint_custom_val(BITS, v2); \
162162+ return (u1 > u2) - (u1 < u2); \
163163+ } \
164164+ \
165165+ static intnat uint ## BITS ## _hash(value v) \
166166+ { \
167167+ return Uint_custom_val(BITS, v); \
168168+ } \
169169+ \
170170+ static void uint ## BITS ## _serialize(value v, \
171171+ uintnat *wsize_32, \
172172+ uintnat *wsize_64) \
173173+ { \
174174+ caml_serialize_int_ ## BYTES(Uint_custom_val(BITS, v)); \
175175+ *wsize_32 = *wsize_64 = BYTES; \
176176+ } \
177177+ \
178178+ static uintnat uint ## BITS ## _deserialize(void *dst) \
179179+ { \
180180+ *(TYPE(BITS) *)dst = caml_deserialize_uint_ ## BYTES(); \
181181+ return BYTES; \
182182+ } \
183183+ \
184184+ static struct custom_operations caml_uint ## BITS ## _ops = { \
185185+ "integers:uint" #BITS, \
186186+ custom_finalize_default, \
187187+ uint ## BITS ## _cmp, \
188188+ uint ## BITS ## _hash, \
189189+ uint ## BITS ## _serialize, \
190190+ uint ## BITS ## _deserialize, \
191191+ custom_compare_ext_default \
192192+ }; \
193193+ \
194194+ value integers_copy_uint ## BITS(TYPE(BITS) u) \
195195+ { \
196196+ value res = caml_alloc_custom(&caml_uint ## BITS ## _ops, BYTES, 0, 1); \
197197+ Uint_custom_val(BITS, res) = u; \
198198+ return res; \
199199+ } \
200200+ UINT_PRIMOP(add, BITS, +) \
201201+ UINT_PRIMOP(sub, BITS, -) \
202202+ UINT_PRIMOP(mul, BITS, *) \
203203+ UINT_PRIMOP(logand, BITS, &) \
204204+ UINT_PRIMOP(logor, BITS, |) \
205205+ UINT_PRIMOP(logxor, BITS, ^) \
206206+ \
207207+ /* div : t -> t -> t */ \
208208+ value integers_uint ## BITS ## _div(value n_, value d_) \
209209+ { \
210210+ TYPE(BITS) n = Uint_custom_val(BITS, n_); \
211211+ TYPE(BITS) d = Uint_custom_val(BITS, d_); \
212212+ if (d == (TYPE(BITS)) 0) \
213213+ caml_raise_zero_divide(); \
214214+ return integers_copy_uint ## BITS (n / d); \
215215+ } \
216216+ \
217217+ /* rem : t -> t -> t */ \
218218+ value integers_uint ## BITS ## _rem(value n_, value d_) \
219219+ { \
220220+ TYPE(BITS) n = Uint_custom_val(BITS, n_); \
221221+ TYPE(BITS) d = Uint_custom_val(BITS, d_); \
222222+ if (d == (TYPE(BITS)) 0) \
223223+ caml_raise_zero_divide(); \
224224+ return integers_copy_uint ## BITS (n % d); \
225225+ } \
226226+ \
227227+ /* shift_left : t -> int -> t */ \
228228+ value integers_uint ## BITS ## _shift_left(value a, value b) \
229229+ { \
230230+ return integers_copy_uint ## BITS(Uint_custom_val(BITS, a) \
231231+ << Long_val(b)); \
232232+ } \
233233+ \
234234+ /* shift_right : t -> int -> t */ \
235235+ value integers_uint ## BITS ## _shift_right(value a, value b) \
236236+ { \
237237+ return integers_copy_uint ## BITS(Uint_custom_val(BITS, a) \
238238+ >> Long_val(b)); \
239239+ } \
240240+ \
241241+ /* of_int : int -> t */ \
242242+ value integers_uint ## BITS ## _of_int(value a) \
243243+ { \
244244+ return integers_copy_uint ## BITS (Long_val(a)); \
245245+ } \
246246+ \
247247+ /* to_int : t -> int */ \
248248+ value integers_uint ## BITS ## _to_int(value a) \
249249+ { \
250250+ return Val_long(Uint_custom_val(BITS, a)); \
251251+ } \
252252+ \
253253+ /* of_int64 : int64 -> t */ \
254254+ value integers_uint ## BITS ## _of_int64(value a) \
255255+ { \
256256+ return integers_copy_uint ## BITS(Int64_val(a)); \
257257+ } \
258258+ \
259259+ /* to_int64 : t -> int64 */ \
260260+ value integers_uint ## BITS ## _to_int64(value a) \
261261+ { \
262262+ return caml_copy_int64(Uint_custom_val(BITS, a)); \
263263+ } \
264264+ \
265265+ /* of_string : string -> t */ \
266266+ UINT_OF_STRING(BITS, integers_copy_uint ## BITS) \
267267+ \
268268+ /* to_string : t -> string */ \
269269+ value integers_uint ## BITS ## _to_string(value a) \
270270+ { \
271271+ char buf[BUF_SIZE(TYPE(BITS))]; \
272272+ if (sprintf(buf, "%" PRIu ## BITS , Uint_custom_val(BITS, a)) < 0) \
273273+ caml_failwith("UInt ## BITS ## .to_string"); \
274274+ else \
275275+ return caml_copy_string(buf); \
276276+ } \
277277+ \
278278+ /* to_hexstring : t -> string */ \
279279+ value integers_uint ## BITS ## _to_hexstring(value a) \
280280+ { \
281281+ char buf[BUF_SIZE(TYPE(BITS))]; \
282282+ if (sprintf(buf, "%" PRIx ## BITS , Uint_custom_val(BITS, a)) < 0) \
283283+ caml_failwith("UInt ## BITS ## .to_hexstring"); \
284284+ else \
285285+ return caml_copy_string(buf); \
286286+ } \
287287+ \
288288+ /* max : unit -> t */ \
289289+ value integers_uint ## BITS ## _max(value a) \
290290+ { \
291291+ return integers_copy_uint ## BITS ((TYPE(BITS))(-1)); \
292292+ }
293293+294294+#define UINT_SMALL_DEFS(BITS, BYTES) \
295295+ /* of_string : string -> t */ \
296296+ UINT_OF_STRING(BITS, Integers_val_uint ## BITS) \
297297+ \
298298+ /* to_string : t -> string */ \
299299+ value integers_uint ## BITS ## _to_string(value a) \
300300+ { \
301301+ char buf[BUF_SIZE(TYPE(BITS))]; \
302302+ if (sprintf(buf, "%" PRIu ## BITS , Uint ## BITS ##_val(a)) < 0) \
303303+ caml_failwith("UInt ## BITS ## .to_string"); \
304304+ else \
305305+ return caml_copy_string(buf); \
306306+ } \
307307+ \
308308+ /* to_hexstring : t -> string */ \
309309+ value integers_uint ## BITS ## _to_hexstring(value a) \
310310+ { \
311311+ char buf[BUF_SIZE(TYPE(BITS))]; \
312312+ if (sprintf(buf, "%" PRIx ## BITS , Uint ## BITS ##_val(a)) < 0) \
313313+ caml_failwith("UInt ## BITS ## .to_hexstring"); \
314314+ else \
315315+ return caml_copy_string(buf); \
316316+ } \
317317+ \
318318+ /* max : unit -> t */ \
319319+ value integers_uint ## BITS ## _max(value unit) \
320320+ { \
321321+ return Integers_val_uint ## BITS((TYPE(BITS))(-1)); \
322322+ }
323323+324324+UINT_SMALL_DEFS(8, 1)
325325+UINT_SMALL_DEFS(16, 2)
326326+UINT_DEFS(32, 4)
327327+UINT_DEFS(64, 8)
328328+329329+value integers_size_t_size (value _) { return Val_long(sizeof (size_t)); }
330330+value integers_ushort_size (value _) { return Val_long(sizeof (unsigned short)); }
331331+value integers_uint_size (value _) { return Val_long(sizeof (unsigned int)); }
332332+value integers_ulong_size (value _) { return Val_long(sizeof (unsigned long)); }
333333+value integers_ulonglong_size (value _) { return Val_long(sizeof (unsigned long long)); }
334334+value integers_uint32_of_int32 (value i) { return integers_copy_uint32(Int32_val(i)); }
335335+value integers_int32_of_uint32 (value u) { return caml_copy_int32(Uint_custom_val(32, u)); }
336336+value integers_uintptr_t_size (value _) { return Val_long(sizeof (uintptr_t)); }
337337+value integers_intptr_t_size (value _) { return Val_long(sizeof (intptr_t)); }
338338+value integers_ptrdiff_t_size (value _) { return Val_long(sizeof (ptrdiff_t)); }
339339+value integers_uint32_of_uint64 (value u) { return integers_copy_uint32(Uint_custom_val(64,u)); }
340340+value integers_uint64_of_uint32 (value u) { return integers_copy_uint64(Uint_custom_val(32,u)); }
341341+342342+value integers_unsigned_init(value unit)
343343+{
344344+ caml_register_custom_operations(&caml_uint32_ops);
345345+ caml_register_custom_operations(&caml_uint64_ops);
346346+ return Val_unit;
347347+}