My working unpac space for OCaml projects in development
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge opam/patches/integers

+1692
+56
vendor/opam/integers/.github/workflows/test.yml
··· 1 + name: Integers 2 + 3 + on: 4 + - pull_request 5 + - push 6 + - workflow_dispatch 7 + 8 + jobs: 9 + tests: 10 + strategy: 11 + fail-fast: false 12 + matrix: 13 + include: 14 + - os: ubuntu-latest 15 + ocaml-compiler: 4.03.x 16 + - os: ubuntu-latest 17 + ocaml-compiler: 4.04.x 18 + - os: ubuntu-latest 19 + ocaml-compiler: 4.05.x 20 + - os: ubuntu-latest 21 + ocaml-compiler: 4.06.x 22 + - os: ubuntu-latest 23 + ocaml-compiler: 4.07.x 24 + - os: ubuntu-latest 25 + ocaml-compiler: 4.08.x 26 + - os: ubuntu-latest 27 + ocaml-compiler: 4.09.x 28 + - os: ubuntu-latest 29 + ocaml-compiler: 4.10.x 30 + - os: ubuntu-latest 31 + ocaml-compiler: 4.11.x 32 + - os: ubuntu-latest 33 + ocaml-compiler: 4.12.x 34 + - os: ubuntu-latest 35 + ocaml-compiler: 4.13.x 36 + - os: windows-latest 37 + ocaml-compiler: 4.13.1 38 + - os: macos-latest 39 + ocaml-compiler: 4.13.1 40 + 41 + runs-on: ${{ matrix.os }} 42 + 43 + steps: 44 + - name: Checkout code 45 + uses: actions/checkout@v2 46 + 47 + - name: Use OCaml ${{ matrix.ocaml-compiler }} 48 + uses: ocaml/setup-ocaml@v2 49 + with: 50 + ocaml-compiler: ${{ matrix.ocaml-compiler }} 51 + 52 + - run: opam install . --deps-only --with-test 53 + 54 + - run: opam exec -- dune build 55 + 56 + - run: opam exec -- dune runtest
+4
vendor/opam/integers/.gitignore
··· 1 + *~ 2 + _build 3 + integers.install 4 + .merlin
+35
vendor/opam/integers/.travis.yml
··· 1 + language: c 2 + sudo: required 3 + install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-opam.sh 4 + script: bash -ex .travis-opam.sh 5 + env: 6 + - OCAML_VERSION=4.02 7 + - OCAML_VERSION=4.03 8 + - OCAML_VERSION=4.04 9 + - OCAML_VERSION=4.05 10 + - OCAML_VERSION=4.06 11 + - OCAML_VERSION=4.07 12 + - OCAML_VERSION=4.08 13 + - OCAML_VERSION=4.09 14 + - OCAML_VERSION=4.10 15 + os: 16 + - linux 17 + - osx 18 + matrix: 19 + exclude: 20 + - os: osx 21 + env: OCAML_VERSION=4.02 22 + - os: osx 23 + env: OCAML_VERSION=4.03 24 + - os: osx 25 + env: OCAML_VERSION=4.04 26 + - os: osx 27 + env: OCAML_VERSION=4.05 28 + - os: osx 29 + env: OCAML_VERSION=4.06 30 + - os: osx 31 + env: OCAML_VERSION=4.07 32 + - os: osx 33 + env: OCAML_VERSION=4.08 34 + - os: osx 35 + env: OCAML_VERSION=4.09
+49
vendor/opam/integers/CHANGES.md
··· 1 + v0.7.0 2022-03-23 2 + ----------------- 3 + 4 + * restore dll support for cygwin64 / newer binutils versions (mingw64) (@fdopen, #40) 5 + 6 + v0.6.0 2022-02-05 7 + ----------------- 8 + 9 + * Add dependency on stdlib-shims (@kit-ty-kate, #38) 10 + 11 + v0.5.1 2021-08-12 12 + ----------------- 13 + 14 + * Restore support for pre-4.05 OCaml versions (@yallop, #37) 15 + 16 + v0.5.0 2021-07-31 17 + ----------------- 18 + * Hex printing, and option-based parsing (@raphael-proust, #34) 19 + * Add stdlib-compatible string parsing (@mrmr1993, #32) 20 + 21 + v0.4.0 2020-05-01 22 + ----------------- 23 + * Expose Signed.S.Infix.(asr) (@dra27, #30) 24 + 25 + v0.3.0 2019-02-15 26 + ----------------- 27 + * Drop 4.01 support (@yallop, #23) 28 + * Add equal and pp to the output signatures (@emillon, #22) 29 + * Dune port (@rgrinberg, #21) 30 + * Add UInt64.(of|to)_uint32 (@yallop, #17) 31 + 32 + v0.2.2 2016-12-19 33 + ----------------- 34 + * Fix truncation in UInt64.of_int; remove other uses of `Val_int`/`Int_val` 35 + 36 + v0.2.1 2016-11-14 37 + ----------------- 38 + * Register the custom deserializers 39 + 40 + v0.2.0 2016-10-04 41 + ----------------- 42 + * Expose from_byte_size functions in Unsigned and Signed 43 + * Support for platforms where standard integer types are macros 44 + * Add 'max' and 'min' functions to Unsigned.S. 45 + * Expose private types for UChar, UInt8, UInt16. 46 + 47 + 0.1.0 2016-09-26 48 + ---------------- 49 + * Initial public release
+19
vendor/opam/integers/LICENSE.md
··· 1 + Copyright (c) 2013-2016 Jeremy Yallop 2 + 3 + Permission is hereby granted, free of charge, to any person obtaining a copy 4 + of this software and associated documentation files (the "Software"), to deal 5 + in the Software without restriction, including without limitation the rights 6 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 + copies of the Software, and to permit persons to whom the Software is 8 + furnished to do so, subject to the following conditions: 9 + 10 + The above copyright notice and this permission notice shall be included in 11 + all copies or substantial portions of the Software. 12 + 13 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 + THE SOFTWARE.
+13
vendor/opam/integers/Makefile
··· 1 + .PHONY: all clean test doc 2 + 3 + all: 4 + dune build 5 + 6 + test: 7 + dune runtest 8 + 9 + doc: 10 + dune build @doc 11 + 12 + clean: 13 + dune clean
+62
vendor/opam/integers/README.md
··· 1 + # ocaml-integers 2 + 3 + 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. 4 + 5 + ### Features 6 + 7 + * The interfaces follow the pattern of the signatures of the [`Int32`][int32], [`Int64`][int64], and [`Nativeint`][nativeint] modules in the OCaml standard library. 8 + 9 + The behaviour also follows the standard library; for example, conversions such as `of_int` truncate, and operations are "modulo" in general: 10 + 11 + ```ocaml 12 + # Unsigned.UInt8.(pred zero);; 13 + - : Unsigned.UInt8.t = <uint8 255> 14 + ``` 15 + 16 + * Top-level printers for each type are included 17 + 18 + ```ocaml 19 + # Unsigned.UInt32.[of_int 103; one; of_string "1000"];; 20 + - : Unsigned.UInt32.t list = [<uint32 103>; <uint32 1>; <uint32 1000>] 21 + ``` 22 + 23 + * Infix operators are available: 24 + 25 + ```ocaml 26 + # Unsigned.UInt32.(Infix.(one + one));; 27 + - : Unsigned.UInt32.t = <uint32 2> 28 + ``` 29 + 30 + * Polymorphic operations such as comparison behave correctly: 31 + 32 + ```ocaml 33 + # open Unsigned.UInt32 34 + # zero < one;; 35 + - : bool = true 36 + # max_int < zero;; 37 + - : bool = false 38 + ``` 39 + 40 + * Integers 32 bits and above are boxed; integers below 32 bits are unboxed. 41 + 42 + ```ocaml 43 + # Obj.(tag (repr Unsigned.UInt32.zero));; 44 + - : int = 255 45 + # Obj.(tag (repr Unsigned.UInt16.zero));; 46 + - : int = 1000 47 + ``` 48 + 49 + ### Using `integers` with js_of_ocaml 50 + 51 + 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] 52 + 53 + [API documentation][doc] 54 + 55 + [![Main workflow](https://github.com/ocamllabs/ocaml-integers/actions/workflows/test.yml/badge.svg)](https://github.com/ocamllabs/ocaml-integers/actions/workflows/test.yml) 56 + 57 + [int32]: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Int32.html 58 + [int64]: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Int64.html 59 + [nativeint]: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Nativeint.html 60 + [doc]: https://yallop.github.io/ocaml-integers/api.docdir/ 61 + [integers_stubs_js]: https://github.com/o1-labs/integers_stubs_js 62 + [js_of_ocaml]: https://github.com/ocsigen/js_of_ocaml
+2
vendor/opam/integers/dune-project
··· 1 + (lang dune 1.0) 2 + (name integers)
+24
vendor/opam/integers/integers.opam
··· 1 + opam-version: "2.0" 2 + maintainer: "yallop@gmail.com" 3 + authors: ["Jeremy Yallop" 4 + "Demi Obenour" 5 + "Stephane Glondu" 6 + "Andreas Hauptmann"] 7 + homepage: "https://github.com/ocamllabs/ocaml-integers" 8 + bug-reports: "https://github.com/ocamllabs/ocaml-integers/issues" 9 + dev-repo: "git+https://github.com/ocamllabs/ocaml-integers.git" 10 + license: "MIT" 11 + 12 + build: [ 13 + ["dune" "subst"] {dev} 14 + ["dune" "build" "-p" name "-j" jobs] 15 + ["dune" "runtest" "-p" name "-j" jobs] {with-test} 16 + ] 17 + 18 + depends: [ 19 + "ocaml" {>= "4.02"} 20 + "dune" {>= "1.0"} 21 + "stdlib-shims" 22 + ] 23 + 24 + synopsis: "Various signed and unsigned integer types for OCaml"
+8
vendor/opam/integers/src/dune
··· 1 + (library 2 + (name integers) 3 + (public_name integers) 4 + (wrapped false) 5 + (install_c_headers ocaml_integers) 6 + (c_names unsigned_stubs) 7 + (libraries stdlib-shims) 8 + (synopsis "Signed and unsigned integers of various sizes"))
+34
vendor/opam/integers/src/ocaml_integers.h
··· 1 + /* 2 + * Copyright (c) 2013 Jeremy Yallop. 3 + * 4 + * This file is distributed under the terms of the MIT License. 5 + * See the file LICENSE for details. 6 + */ 7 + 8 + #ifndef INTEGERS_UNSIGNED_STUBS_H 9 + #define INTEGERS_UNSIGNED_STUBS_H 10 + 11 + #include <caml/mlvalues.h> 12 + 13 + #include <stdint.h> 14 + 15 + #ifndef OCAML_INTEGERS_INTERNAL 16 + #ifdef __cplusplus 17 + extern "C" { 18 + #endif 19 + CAMLextern value integers_copy_uint32(uint32_t u); 20 + CAMLextern value integers_copy_uint64(uint64_t u); 21 + #ifdef __cplusplus 22 + } 23 + #endif 24 + #endif 25 + 26 + #define Integers_val_uint8(t) ((Val_int((uint8_t)t))) 27 + #define Integers_val_uint16(t) ((Val_int((uint16_t)t))) 28 + 29 + #define Uint8_val(V) ((uint8_t)(Int_val(V))) 30 + #define Uint16_val(V) ((uint16_t)(Int_val(V))) 31 + #define Uint32_val(V) (*((uint32_t *) Data_custom_val(V))) 32 + #define Uint64_val(V) (*((uint64_t *) Data_custom_val(V))) 33 + 34 + #endif /* INTEGERS_UNSIGNED_STUBS_H */
+168
vendor/opam/integers/src/signed.ml
··· 1 + (* 2 + * Copyright (c) 2013 Jeremy Yallop. 3 + * Copyright (c) 2021 Nomadic Labs 4 + * 5 + * This file is distributed under the terms of the MIT License. 6 + * See the file LICENSE for details. 7 + *) 8 + 9 + module type Infix = sig 10 + type t 11 + include Unsigned.Infix with type t := t 12 + val (asr) : t -> int -> t 13 + end 14 + 15 + module type S = sig 16 + type t 17 + 18 + module Infix : Infix with type t := t 19 + 20 + include Unsigned.S with type t := t 21 + with module Infix := Infix 22 + 23 + val neg : t -> t 24 + val abs : t -> t 25 + val minus_one : t 26 + val min_int : t 27 + val shift_right_logical : t -> int -> t 28 + val of_nativeint : nativeint -> t 29 + val to_nativeint : t -> nativeint 30 + val of_int64 : int64 -> t 31 + val to_int64 : t -> int64 32 + end 33 + 34 + module type Basics = sig 35 + type t 36 + val add : t -> t -> t 37 + val sub : t -> t -> t 38 + val mul : t -> t -> t 39 + val div : t -> t -> t 40 + val rem : t -> t -> t 41 + val logand : t -> t -> t 42 + val logor : t -> t -> t 43 + val logxor : t -> t -> t 44 + val shift_left : t -> int -> t 45 + val shift_right : t -> int -> t 46 + val shift_right_logical : t -> int -> t 47 + end 48 + 49 + module MakeInfix(S : Basics) = 50 + struct 51 + open S 52 + let (+) = add 53 + let (-) = sub 54 + let ( * ) = mul 55 + let (/) = div 56 + let (mod) = rem 57 + let (land) = logand 58 + let (lor) = logor 59 + let (lxor) = logxor 60 + let (lsl) = shift_left 61 + let (lsr) = shift_right_logical 62 + let (asr) = shift_right 63 + end 64 + 65 + external format_int : string -> int -> string = "caml_format_int" 66 + 67 + module Int = 68 + struct 69 + module Basics = 70 + struct 71 + type t = int 72 + let add = ( + ) 73 + let sub = ( - ) 74 + let mul = ( * ) 75 + let div = ( / ) 76 + let rem = ( mod ) 77 + let max_int = Stdlib.max_int 78 + let min_int = Stdlib.min_int 79 + let logand = ( land ) 80 + let logor = ( lor ) 81 + let logxor = ( lxor ) 82 + let shift_left = ( lsl ) 83 + let shift_right = ( asr ) 84 + let shift_right_logical = ( lsr ) 85 + let of_int x = x 86 + let to_int x = x 87 + let of_string = int_of_string 88 + let of_string_opt s = try Some (of_string s) with Failure _ -> None 89 + let to_string = string_of_int 90 + let to_hexstring = format_int "%x" 91 + let zero = 0 92 + let one = 1 93 + let minus_one = -1 94 + let lognot = lnot 95 + let succ = Stdlib.succ 96 + let pred = Stdlib.pred 97 + let compare = Stdlib.compare 98 + let equal = Stdlib.(=) 99 + let max = Stdlib.max 100 + let min = Stdlib.min 101 + end 102 + include Basics 103 + module Infix = MakeInfix(Basics) 104 + let to_int64 = Int64.of_int 105 + let of_int64 = Int64.to_int 106 + let to_nativeint = Nativeint.of_int 107 + let of_nativeint = Nativeint.to_int 108 + let abs = Stdlib.abs 109 + let neg x = -x 110 + let pp fmt n = Format.fprintf fmt "%d" n 111 + let pp_hex fmt n = Format.fprintf fmt "%x" n 112 + end 113 + 114 + module Int32 = 115 + struct 116 + [@@@ocaml.warning "-32"] 117 + (* Int32.equal was introduced in OCaml 4.03.0 *) 118 + let equal (x:int32) (y:int32) = x = y 119 + (* Int32.of_string_opt was introduced in OCaml 4.5b0.0 *) 120 + let of_string_opt s = try Some (Int32.of_string s) with Failure _ -> None 121 + include Int32 122 + module Infix = MakeInfix(Int32) 123 + let of_nativeint = Nativeint.to_int32 124 + let to_nativeint = Nativeint.of_int32 125 + let of_int64 = Int64.to_int32 126 + let to_int64 = Int64.of_int32 127 + let max = Stdlib.max 128 + let min = Stdlib.min 129 + let pp fmt n = Format.fprintf fmt "%ld" n 130 + let pp_hex fmt n = Format.fprintf fmt "%lx" n 131 + let to_hexstring n = Format.asprintf "%lx" n 132 + end 133 + 134 + module Int64 = 135 + struct 136 + [@@@ocaml.warning "-32"] 137 + (* Int64.equal was introduced in OCaml 4.03.0 *) 138 + let equal (x:int64) (y:int64) = x = y 139 + (* Int32.of_string_opt was introduced in OCaml 4.5b0.0 *) 140 + let of_string_opt s = try Some (Int64.of_string s) with Failure _ -> None 141 + include Int64 142 + module Infix = MakeInfix(Int64) 143 + let of_int64 x = x 144 + let to_int64 x = x 145 + let max = Stdlib.max 146 + let min = Stdlib.min 147 + let pp fmt n = Format.fprintf fmt "%Ld" n 148 + let pp_hex fmt n = Format.fprintf fmt "%Lx" n 149 + let to_hexstring n = Format.asprintf "%Lx" n 150 + end 151 + 152 + (* C guarantees that sizeof(t) == sizeof(unsigned t) *) 153 + external int_size : unit -> int = "integers_uint_size" 154 + external long_size : unit -> int = "integers_ulong_size" 155 + external llong_size : unit -> int = "integers_ulonglong_size" 156 + 157 + let of_byte_size : int -> (module S) = function 158 + | 4 -> (module Int32) 159 + | 8 -> (module Int64) 160 + | _ -> invalid_arg "Signed.of_byte_size" 161 + 162 + module SInt = (val of_byte_size (int_size ())) 163 + module Long = (val of_byte_size (long_size ())) 164 + module LLong = (val of_byte_size (llong_size ())) 165 + 166 + type sint = SInt.t 167 + type long = Long.t 168 + type llong = LLong.t
+90
vendor/opam/integers/src/signed.mli
··· 1 + (* 2 + * Copyright (c) 2013 Jeremy Yallop. 3 + * Copyright (c) 2021 Nomadic Labs 4 + * 5 + * This file is distributed under the terms of the MIT License. 6 + * See the file LICENSE for details. 7 + *) 8 + 9 + (** Types and operations for signed integers. *) 10 + 11 + module type Infix = sig 12 + type t 13 + 14 + include Unsigned.Infix with type t := t 15 + 16 + val (asr) : t -> int -> t 17 + (** [x asr y] shifts [x] to the right by [y] bits. See {!shift_right}. *) 18 + end 19 + 20 + 21 + module type S = sig 22 + type t 23 + 24 + module Infix : Infix with type t := t 25 + 26 + include Unsigned.S with type t := t 27 + with module Infix := Infix 28 + 29 + val neg : t -> t 30 + (** Unary negation. *) 31 + 32 + val abs : t -> t 33 + (** Return the absolute value of its argument. *) 34 + 35 + val minus_one : t 36 + (** The value -1 *) 37 + 38 + val min_int : t 39 + (** The smallest representable integer. *) 40 + 41 + val shift_right_logical : t -> int -> t 42 + (** {!shift_right_logical} [x] [y] shifts [x] to the right by [y] bits. See 43 + {!Int32.shift_right_logical}. *) 44 + 45 + val of_nativeint : nativeint -> t 46 + (** Convert the given nativeint value to a signed integer. *) 47 + 48 + val to_nativeint : t -> nativeint 49 + (** Convert the given signed integer to a nativeint value. *) 50 + 51 + val of_int64 : int64 -> t 52 + (** Convert the given int64 value to a signed integer. *) 53 + 54 + val to_int64 : t -> int64 55 + (** Convert the given signed integer to an int64 value. *) 56 + end 57 + (** Signed integer operations *) 58 + 59 + module Int : S with type t = int 60 + (** Signed integer type and operations. *) 61 + 62 + module Int32 : S with type t = int32 63 + (** Signed 32-bit integer type and operations. *) 64 + 65 + module Int64 : S with type t = int64 66 + (** Signed 64-bit integer type and operations. *) 67 + 68 + module SInt : S 69 + (** C's signed integer type and operations. *) 70 + 71 + module Long : S 72 + (** The signed long integer type and operations. *) 73 + 74 + module LLong : S 75 + (** The signed long long integer type and operations. *) 76 + 77 + type sint = SInt.t 78 + (** C's signed integer type. *) 79 + 80 + type long = Long.t 81 + (** The signed long integer type. *) 82 + 83 + type llong = LLong.t 84 + (** The signed long long integer type. *) 85 + 86 + val of_byte_size : int -> (module S) 87 + (** [of_byte_size b] is a module of type S that implements a signed type 88 + with [b] bytes. 89 + 90 + Raise [Invalid_argument] if no suitable type is available. *)
+313
vendor/opam/integers/src/unsigned.ml
··· 1 + (* 2 + * Copyright (c) 2013 Jeremy Yallop. 3 + * Copyright (c) 2021 Nomadic Labs 4 + * 5 + * This file is distributed under the terms of the MIT License. 6 + * See the file LICENSE for details. 7 + *) 8 + 9 + external init : unit -> unit = "integers_unsigned_init" 10 + let () = init () 11 + 12 + (* Boxed unsigned types *) 13 + module type Basics = sig 14 + type t 15 + 16 + val add : t -> t -> t 17 + val sub : t -> t -> t 18 + val mul : t -> t -> t 19 + val div : t -> t -> t 20 + val rem : t -> t -> t 21 + val max_int : t 22 + val logand : t -> t -> t 23 + val logor : t -> t -> t 24 + val logxor : t -> t -> t 25 + val shift_left : t -> int -> t 26 + val shift_right : t -> int -> t 27 + val of_int : int -> t 28 + val to_int : t -> int 29 + val of_int64 : int64 -> t 30 + val to_int64 : t -> int64 31 + val of_string : string -> t 32 + val to_string : t -> string 33 + val to_hexstring : t -> string 34 + end 35 + 36 + 37 + module type Extras = sig 38 + type t 39 + 40 + val zero : t 41 + val one : t 42 + val lognot : t -> t 43 + val succ : t -> t 44 + val pred : t -> t 45 + val compare : t -> t -> int 46 + val equal : t -> t -> bool 47 + val max : t -> t -> t 48 + val min : t -> t -> t 49 + val of_string_opt : string -> t option 50 + val pp : Format.formatter -> t -> unit 51 + val pp_hex : Format.formatter -> t -> unit 52 + end 53 + 54 + 55 + module type Infix = sig 56 + type t 57 + val (+) : t -> t -> t 58 + val (-) : t -> t -> t 59 + val ( * ) : t -> t -> t 60 + val (/) : t -> t -> t 61 + val (mod) : t -> t -> t 62 + val (land) : t -> t -> t 63 + val (lor) : t -> t -> t 64 + val (lxor) : t -> t -> t 65 + val (lsl) : t -> int -> t 66 + val (lsr) : t -> int -> t 67 + end 68 + 69 + 70 + module type S = sig 71 + include Basics 72 + include Extras with type t := t 73 + 74 + module Infix : Infix with type t := t 75 + end 76 + 77 + 78 + module MakeInfix (B : Basics) = 79 + struct 80 + open B 81 + let (+) = add 82 + let (-) = sub 83 + let ( * ) = mul 84 + let (/) = div 85 + let (mod) = rem 86 + let (land) = logand 87 + let (lor) = logor 88 + let (lxor) = logxor 89 + let (lsl) = shift_left 90 + let (lsr) = shift_right 91 + end 92 + 93 + 94 + module Extras(Basics : Basics) : Extras with type t := Basics.t = 95 + struct 96 + open Basics 97 + let zero = of_int 0 98 + let one = of_int 1 99 + let succ n = add n one 100 + let pred n = sub n one 101 + let lognot n = logxor n max_int 102 + let compare (x : t) (y : t) = Stdlib.compare x y 103 + let equal (x : t) (y : t) = Stdlib.(=) x y 104 + let max (x : t) (y : t) = Stdlib.max x y 105 + let min (x : t) (y : t) = Stdlib.min x y 106 + let of_string_opt (s : string) = try Some (of_string s) with Failure _ -> None 107 + let pp fmt x = Format.fprintf fmt "%s" (to_string x) 108 + let pp_hex fmt x = Format.fprintf fmt "%s" (to_hexstring x) 109 + end 110 + 111 + external format_int : string -> int -> string = "caml_format_int" 112 + 113 + module UInt8 : S with type t = private int = 114 + struct 115 + module B = 116 + struct 117 + type t = int 118 + let max_int = 255 119 + let add : t -> t -> t = fun x y -> (x + y) land max_int 120 + let sub : t -> t -> t = fun x y -> (x - y) land max_int 121 + let mul : t -> t -> t = fun x y -> (x * y) land max_int 122 + let div : t -> t -> t = (/) 123 + let rem : t -> t -> t = (mod) 124 + let logand: t -> t -> t = (land) 125 + let logor: t -> t -> t = (lor) 126 + let logxor : t -> t -> t = (lxor) 127 + let shift_left : t -> int -> t = fun x y -> (x lsl y) land max_int 128 + let shift_right : t -> int -> t = (lsr) 129 + let of_int (x: int): t = 130 + (* For backwards compatibility, this wraps *) 131 + x land max_int 132 + external to_int : t -> int = "%identity" 133 + let of_int64 : int64 -> t = fun x -> of_int (Int64.to_int x) 134 + let to_int64 : t -> int64 = fun x -> Int64.of_int (to_int x) 135 + external of_string : string -> t = "integers_uint8_of_string" 136 + let to_string : t -> string = string_of_int 137 + let to_hexstring : t -> string = format_int "%x" 138 + end 139 + include B 140 + include Extras(B) 141 + module Infix = MakeInfix(B) 142 + end 143 + 144 + 145 + module UInt16 : S with type t = private int = 146 + struct 147 + module B = 148 + struct 149 + type t = int 150 + let max_int = 65535 151 + let add : t -> t -> t = fun x y -> (x + y) land max_int 152 + let sub : t -> t -> t = fun x y -> (x - y) land max_int 153 + let mul : t -> t -> t = fun x y -> (x * y) land max_int 154 + let div : t -> t -> t = (/) 155 + let rem : t -> t -> t = (mod) 156 + let logand: t -> t -> t = (land) 157 + let logor: t -> t -> t = (lor) 158 + let logxor : t -> t -> t = (lxor) 159 + let shift_left : t -> int -> t = fun x y -> (x lsl y) land max_int 160 + let shift_right : t -> int -> t = (lsr) 161 + let of_int (x: int): t = 162 + (* For backwards compatibility, this wraps *) 163 + x land max_int 164 + external to_int : t -> int = "%identity" 165 + let of_int64 : int64 -> t = fun x -> Int64.to_int x |> of_int 166 + let to_int64 : t -> int64 = fun x -> to_int x |> Int64.of_int 167 + external of_string : string -> t = "integers_uint16_of_string" 168 + let to_string : t -> string = string_of_int 169 + let to_hexstring : t -> string = format_int "%x" 170 + end 171 + include B 172 + include Extras(B) 173 + module Infix = MakeInfix(B) 174 + end 175 + 176 + 177 + module UInt32 : sig 178 + include S 179 + val of_int32 : int32 -> t 180 + val to_int32 : t -> int32 181 + end = 182 + struct 183 + module B = 184 + struct 185 + type t 186 + external add : t -> t -> t = "integers_uint32_add" 187 + external sub : t -> t -> t = "integers_uint32_sub" 188 + external mul : t -> t -> t = "integers_uint32_mul" 189 + external div : t -> t -> t = "integers_uint32_div" 190 + external rem : t -> t -> t = "integers_uint32_rem" 191 + external logand : t -> t -> t = "integers_uint32_logand" 192 + external logor : t -> t -> t = "integers_uint32_logor" 193 + external logxor : t -> t -> t = "integers_uint32_logxor" 194 + external shift_left : t -> int -> t = "integers_uint32_shift_left" 195 + external shift_right : t -> int -> t = "integers_uint32_shift_right" 196 + external of_string : string -> t = "integers_uint32_of_string" 197 + external to_string : t -> string = "integers_uint32_to_string" 198 + external to_hexstring : t -> string = "integers_uint32_to_hexstring" 199 + external of_int : int -> t = "integers_uint32_of_int" 200 + external to_int : t -> int = "integers_uint32_to_int" 201 + 202 + external of_int32 : int32 -> t = "integers_uint32_of_int32" 203 + let half_max_plus_two = of_string "0x80000001" 204 + let half_max_minus_one_signed = 0x7fffffffl 205 + let of_int32 i32 = 206 + if i32 >= 0l then 207 + of_int32 i32 208 + else 209 + add half_max_plus_two (of_int32 (Int32.add i32 half_max_minus_one_signed)) 210 + 211 + external to_int32 : t -> int32 = "integers_int32_of_uint32" 212 + let max_signed = of_int32 Int32.max_int 213 + let to_int32 u32 = 214 + if Stdlib.compare u32 max_signed <= 0 then 215 + to_int32 u32 216 + else 217 + Int32.sub (to_int32 (sub u32 half_max_plus_two)) half_max_minus_one_signed 218 + 219 + external of_int64 : int64 -> t = "integers_uint32_of_int64" 220 + external to_int64 : t -> int64 = "integers_uint32_to_int64" 221 + external _max_int : unit -> t = "integers_uint32_max" 222 + let max_int = _max_int () 223 + end 224 + include B 225 + include Extras(B) 226 + module Infix = MakeInfix(B) 227 + end 228 + 229 + 230 + module UInt64 : sig 231 + include S 232 + external of_uint32 : UInt32.t -> t = "integers_uint64_of_uint32" 233 + external to_uint32 : t -> UInt32.t = "integers_uint32_of_uint64" 234 + end = 235 + struct 236 + module B = 237 + struct 238 + type t 239 + external add : t -> t -> t = "integers_uint64_add" 240 + external sub : t -> t -> t = "integers_uint64_sub" 241 + external mul : t -> t -> t = "integers_uint64_mul" 242 + external div : t -> t -> t = "integers_uint64_div" 243 + external rem : t -> t -> t = "integers_uint64_rem" 244 + external logand : t -> t -> t = "integers_uint64_logand" 245 + external logor : t -> t -> t = "integers_uint64_logor" 246 + external logxor : t -> t -> t = "integers_uint64_logxor" 247 + external shift_left : t -> int -> t = "integers_uint64_shift_left" 248 + external shift_right : t -> int -> t = "integers_uint64_shift_right" 249 + external of_int : int -> t = "integers_uint64_of_int" 250 + external to_int : t -> int = "integers_uint64_to_int" 251 + external of_string : string -> t = "integers_uint64_of_string" 252 + external to_string : t -> string = "integers_uint64_to_string" 253 + external to_hexstring : t -> string = "integers_uint64_to_hexstring" 254 + 255 + external of_int64 : int64 -> t = "integers_uint64_of_int64" 256 + let half_max_plus_two = of_string "0x8000000000000001" 257 + let half_max_minus_one_signed = 0x7fffffffffffffffL 258 + let of_int64 i64 = 259 + if i64 >= 0L then 260 + of_int64 i64 261 + else 262 + add half_max_plus_two (of_int64 (Int64.add i64 half_max_minus_one_signed)) 263 + 264 + external to_int64 : t -> int64 = "integers_uint64_to_int64" 265 + let max_signed = of_int64 Int64.max_int 266 + let to_int64 u64 = 267 + if Stdlib.compare u64 max_signed <= 0 then 268 + to_int64 u64 269 + else 270 + Int64.sub (to_int64 (sub u64 half_max_plus_two)) half_max_minus_one_signed 271 + 272 + external of_uint32 : UInt32.t -> t = "integers_uint64_of_uint32" 273 + external to_uint32 : t -> UInt32.t = "integers_uint32_of_uint64" 274 + external _max_int : unit -> t = "integers_uint64_max" 275 + let max_int = _max_int () 276 + end 277 + include B 278 + include Extras(B) 279 + module Infix = MakeInfix(B) 280 + end 281 + 282 + 283 + let of_byte_size : int -> (module S) = function 284 + | 1 -> (module UInt8) 285 + | 2 -> (module UInt16) 286 + | 4 -> (module UInt32) 287 + | 8 -> (module UInt64) 288 + | _ -> invalid_arg "Unsigned.of_byte_size" 289 + 290 + 291 + external size_t_size : unit -> int = "integers_size_t_size" 292 + external ushort_size : unit -> int = "integers_ushort_size" 293 + external uint_size : unit -> int = "integers_uint_size" 294 + external ulong_size : unit -> int = "integers_ulong_size" 295 + external ulonglong_size : unit -> int = "integers_ulonglong_size" 296 + 297 + module Size_t : S = (val of_byte_size (size_t_size ())) 298 + module UChar = UInt8 299 + module UShort : S = (val of_byte_size (ushort_size ())) 300 + module UInt : S = (val of_byte_size (uint_size ())) 301 + module ULong : S = (val of_byte_size (ulong_size ())) 302 + module ULLong : S = (val of_byte_size (ulonglong_size ())) 303 + 304 + type uchar = UChar.t 305 + type uint8 = UInt8.t 306 + type uint16 = UInt16.t 307 + type uint32 = UInt32.t 308 + type uint64 = UInt64.t 309 + type size_t = Size_t.t 310 + type ushort = UShort.t 311 + type uint = UInt.t 312 + type ulong = ULong.t 313 + type ullong = ULLong.t
+270
vendor/opam/integers/src/unsigned.mli
··· 1 + (* 2 + * Copyright (c) 2013 Jeremy Yallop. 3 + * Copyright (c) 2021 Nomadic Labs 4 + * 5 + * This file is distributed under the terms of the MIT License. 6 + * See the file LICENSE for details. 7 + *) 8 + 9 + (** Types and operations for unsigned integers. *) 10 + 11 + module type Infix = sig 12 + type t 13 + 14 + val (+) : t -> t -> t 15 + (** Addition. See {!add}. *) 16 + 17 + val (-) : t -> t -> t 18 + (** Subtraction. See {!sub}.*) 19 + 20 + val ( * ) : t -> t -> t 21 + (** Multiplication. See {!mul}.*) 22 + 23 + val (/) : t -> t -> t 24 + (** Division. See {!div}.*) 25 + 26 + val (mod) : t -> t -> t 27 + (** Integer remainder. See {!rem}. *) 28 + 29 + val (land) : t -> t -> t 30 + (** Bitwise logical and. See {!logand}. *) 31 + 32 + val (lor) : t -> t -> t 33 + (** Bitwise logical or. See {!logor}. *) 34 + 35 + val (lxor) : t -> t -> t 36 + (** Bitwise logical exclusive or. See {!logxor}. *) 37 + 38 + val (lsl) : t -> int -> t 39 + (** [x lsl y] shifts [x] to the left by [y] bits. See {!shift_left}. *) 40 + 41 + val (lsr) : t -> int -> t 42 + (** [x lsr y] shifts [x] to the right by [y] bits. See {!shift_right}. *) 43 + end 44 + (** Infix names for the unsigned integer operations. *) 45 + 46 + 47 + module type S = sig 48 + type t 49 + 50 + val add : t -> t -> t 51 + (** Addition. *) 52 + 53 + val sub : t -> t -> t 54 + (** Subtraction. *) 55 + 56 + val mul : t -> t -> t 57 + (** Multiplication. *) 58 + 59 + val div : t -> t -> t 60 + (** Division. Raise {!Division_by_zero} if the second argument is zero. *) 61 + 62 + val rem : t -> t -> t 63 + (** Integer remainder. Raise {!Division_by_zero} if the second argument is 64 + zero. *) 65 + 66 + val max_int : t 67 + (** The greatest representable integer. *) 68 + 69 + val logand : t -> t -> t 70 + (** Bitwise logical and. *) 71 + 72 + val logor : t -> t -> t 73 + (** Bitwise logical or. *) 74 + 75 + val logxor : t -> t -> t 76 + (** Bitwise logical exclusive or. *) 77 + 78 + val shift_left : t -> int -> t 79 + (** {!shift_left} [x] [y] shifts [x] to the left by [y] bits. *) 80 + 81 + val shift_right : t -> int -> t 82 + (** {!shift_right} [x] [y] shifts [x] to the right by [y] bits. *) 83 + 84 + val of_int : int -> t 85 + (** Convert the given int value to an unsigned integer. *) 86 + 87 + val to_int : t -> int 88 + (** Convert the given unsigned integer value to an int. *) 89 + 90 + val of_int64 : int64 -> t 91 + (** Convert the given int64 value to an unsigned integer. *) 92 + 93 + val to_int64 : t -> int64 94 + (** Convert the given unsigned integer value to an int64. *) 95 + 96 + val of_string : string -> t 97 + (** Convert the given string to an unsigned integer. Raise {!Failure} 98 + if the given string is not a valid representation of an unsigned 99 + integer. *) 100 + 101 + val to_string : t -> string 102 + (** Return the string representation of its argument. *) 103 + 104 + val to_hexstring : t -> string 105 + (** Return the hexadecimal string representation of its argument. *) 106 + 107 + val zero : t 108 + (** The integer 0. *) 109 + 110 + val one : t 111 + (** The integer 1. *) 112 + 113 + val lognot : t -> t 114 + (** Bitwise logical negation. *) 115 + 116 + val succ : t -> t 117 + (** Successor. *) 118 + 119 + val pred : t -> t 120 + (** Predecessor. *) 121 + 122 + val compare : t -> t -> int 123 + (** The comparison function for unsigned integers, with the same 124 + specification as {!Stdlib.compare}. *) 125 + 126 + val equal : t -> t -> bool 127 + (** Tests for equality, with the same specification as {!Stdlib.(=)}. *) 128 + 129 + val max : t -> t -> t 130 + (** [max x y] is the greater of [x] and [y] *) 131 + 132 + val min : t -> t -> t 133 + (** [min x y] is the lesser of [x] and [y] *) 134 + 135 + val of_string_opt : string -> t option 136 + (** Convert the given string to an unsigned integer. Returns [None] if the 137 + given string is not a valid representation of an unsigned integer. *) 138 + 139 + val pp : Format.formatter -> t -> unit 140 + (** Output the result of {!to_string} on a formatter. *) 141 + 142 + val pp_hex : Format.formatter -> t -> unit 143 + (** Output the result of {!to_hexstring} on a formatter. *) 144 + 145 + module Infix : Infix with type t := t 146 + end 147 + (** Unsigned integer operations. *) 148 + 149 + module UChar : S with type t = private int 150 + (** Unsigned char type and operations. *) 151 + 152 + module UInt8 : S with type t = private int 153 + (** Unsigned 8-bit integer type and operations. *) 154 + 155 + module UInt16 : S with type t = private int 156 + (** Unsigned 16-bit integer type and operations. *) 157 + 158 + module UInt32 : sig 159 + include S 160 + val of_int32 : int32 -> t 161 + (** Convert the given 32-bit signed integer to an unsigned 32-bit integer. 162 + 163 + If the signed integer fits within the unsigned range (in other words, if 164 + the signed integer is positive) then the numerical values represented by 165 + the signed and unsigned integers are the same. 166 + 167 + Whether the signed integer fits or not, the function [of_int32] is always 168 + the inverse of the function {!to_int32}. In other words, 169 + [to_int32 (of_int32 x) = x] holds for all [x : int32]. *) 170 + 171 + val to_int32 : t -> int32 172 + (** Convert the given 32-bit unsigned integer to a signed 32-bit integer. 173 + 174 + If the unsigned integer fits within the signed range (in other words, if 175 + the unsigned integer is less than {!Int32.max_int}) then the numerical 176 + values represented by unsigned and signed integers are the same. 177 + 178 + Whether the unsigned integer fits or not, the function [to_int32] is 179 + always the inverse of the function {!of_int32}. In other words, 180 + [of_int32 (to_int32 x) = x] holds for all [x : t]. *) 181 + end 182 + (** Unsigned 32-bit integer type and operations. *) 183 + 184 + module UInt64 : sig 185 + include S 186 + 187 + val of_int64 : int64 -> t 188 + (** Convert the given 64-bit signed integer to an unsigned 64-bit integer. 189 + 190 + If the signed integer fits within the unsigned range (in other words, if 191 + the signed integer is positive) then the numerical values represented by 192 + the signed and unsigned integers are the same. 193 + 194 + Whether the signed integer fits or not, the function [of_int64] is always 195 + the inverse of the function {!to_int64}. In other words, 196 + [to_int64 (of_int64 x) = x] holds for all [x : int64]. *) 197 + 198 + val to_int64 : t -> int64 199 + (** Convert the given 64-bit unsigned integer to a signed 64-bit integer. 200 + 201 + If the unsigned integer fits within the signed range (in other words, if 202 + the unsigned integer is less than {!Int64.max_int}) then the numerical 203 + values represented by unsigned and signed integers are the same. 204 + 205 + Whether the unsigned integer fits or not, the function [to_int64] is 206 + always the inverse of the function {!of_int64}. In other words, 207 + [of_int64 (to_int64 x) = x] holds for all [x : t]. *) 208 + 209 + val of_uint32 : UInt32.t -> t 210 + (** Convert the given 32-bit unsigned integer to a 64-bit unsigned 211 + integer. *) 212 + 213 + val to_uint32 : t -> UInt32.t 214 + (** Convert the given 64-bit unsigned integer to a 32-bit unsigned integer. 215 + The 64-bit unsigned integer is taken modulo 2{^32}, i.e. the top 32 bits 216 + are lost during the conversion. *) 217 + end 218 + (** Unsigned 64-bit integer type and operations. *) 219 + 220 + module Size_t : S 221 + (** The size_t unsigned integer type and operations. *) 222 + 223 + module UShort : S 224 + (** The unsigned short integer type and operations. *) 225 + 226 + module UInt : S 227 + (** The unsigned int type and operations. *) 228 + 229 + module ULong : S 230 + (** The unsigned long integer type and operations. *) 231 + 232 + module ULLong : S 233 + (** The unsigned long long integer type and operations. *) 234 + 235 + 236 + type uchar = UChar.t 237 + (** The unsigned char type. *) 238 + 239 + type uint8 = UInt8.t 240 + (** Unsigned 8-bit integer type. *) 241 + 242 + type uint16 = UInt16.t 243 + (** Unsigned 16-bit integer type. *) 244 + 245 + type uint32 = UInt32.t 246 + (** Unsigned 32-bit integer type. *) 247 + 248 + type uint64 = UInt64.t 249 + (** Unsigned 64-bit integer type. *) 250 + 251 + type size_t = Size_t.t 252 + (** The size_t unsigned integer type. *) 253 + 254 + type ushort = UShort.t 255 + (** The unsigned short unsigned integer type. *) 256 + 257 + type uint = UInt.t 258 + (** The unsigned int type. *) 259 + 260 + type ulong = ULong.t 261 + (** The unsigned long integer type. *) 262 + 263 + type ullong = ULLong.t 264 + (** The unsigned long long integer type. *) 265 + 266 + val of_byte_size : int -> (module S) 267 + (** [of_byte_size b] is a module of type S that implements an unsigned type 268 + with [b] bytes. 269 + 270 + Raise [Invalid_argument] if no suitable type is available. *)
+347
vendor/opam/integers/src/unsigned_stubs.c
··· 1 + /* 2 + * Copyright (c) 2013 Jeremy Yallop. 3 + * 4 + * This file is distributed under the terms of the MIT License. 5 + * See the file LICENSE for details. 6 + */ 7 + 8 + #if !__USE_MINGW_ANSI_STDIO && (defined(__MINGW32__) || defined(__MINGW64__)) 9 + #define __USE_MINGW_ANSI_STDIO 1 10 + #endif 11 + 12 + #include <caml/mlvalues.h> 13 + #include <caml/custom.h> 14 + #include <caml/alloc.h> 15 + #include <caml/intext.h> 16 + #include <caml/fail.h> 17 + 18 + #include <inttypes.h> 19 + #include <stdint.h> 20 + #include <limits.h> 21 + #include <stdio.h> 22 + 23 + #define OCAML_INTEGERS_INTERNAL 1 24 + #include "ocaml_integers.h" 25 + 26 + #define UINT_DECLS(BITS) \ 27 + extern value integers_copy_uint ## BITS(uint ## BITS ## _t u); \ 28 + /* uintX_add : t -> t -> t */ \ 29 + extern value integers_uint ## BITS ## _ ## add(value a, value b); \ 30 + /* uintX_sub : t -> t -> t */ \ 31 + extern value integers_uint ## BITS ## _ ## sub(value a, value b); \ 32 + /* uintX_mul : t -> t -> t */ \ 33 + extern value integers_uint ## BITS ## _ ## mul(value a, value b); \ 34 + /* uintX_div : t -> t -> t */ \ 35 + extern value integers_uint ## BITS ## _ ## div(value a, value b); \ 36 + /* uintX_rem : t -> t -> t */ \ 37 + extern value integers_uint ## BITS ## _ ## rem(value a, value b); \ 38 + /* uintX_logand : t -> t -> t */ \ 39 + extern value integers_uint ## BITS ## _ ## logand(value a, value b); \ 40 + /* uintX_logor : t -> t -> t */ \ 41 + extern value integers_uint ## BITS ## _ ## logor(value a, value b); \ 42 + /* uintX_logxor : t -> t -> t */ \ 43 + extern value integers_uint ## BITS ## _ ## logxor(value a, value b); \ 44 + /* uintX_shift_left : t -> t -> t */ \ 45 + extern value integers_uint ## BITS ## _ ## shift_left(value a, value b); \ 46 + /* uintX_shift_right : t -> t -> t */ \ 47 + extern value integers_uint ## BITS ## _ ## shift_right(value a, value b); \ 48 + /* of_int : int -> t */ \ 49 + extern value integers_uint ## BITS ## _of_int(value a); \ 50 + /* to_int : t -> int */ \ 51 + extern value integers_uint ## BITS ## _to_int(value a); \ 52 + /* of_string : string -> t */ \ 53 + extern value integers_uint ## BITS ## _of_string(value a); \ 54 + /* to_string : t -> string */ \ 55 + extern value integers_uint ## BITS ## _to_string(value a); \ 56 + /* max : unit -> t */ \ 57 + extern value integers_uint ## BITS ## _max(value a); 58 + 59 + #define UINT_SMALL_DECLS(BITS) \ 60 + /* of_string : string -> t */ \ 61 + extern value integers_uint ## BITS ## _of_string(value a); \ 62 + /* to_string : t -> string */ \ 63 + extern value integers_uint ## BITS ## _to_string(value a); \ 64 + /* max : unit -> t */ \ 65 + extern value integers_uint ## BITS ## _max(value a); 66 + 67 + UINT_SMALL_DECLS(8) 68 + UINT_SMALL_DECLS(16) 69 + UINT_DECLS(32) 70 + UINT_DECLS(64) 71 + 72 + /* X_size : unit -> int */ 73 + extern value integers_size_t_size (value _); 74 + extern value integers_ushort_size (value _); 75 + extern value integers_uint_size (value _); 76 + extern value integers_ulong_size (value _); 77 + extern value integers_ulonglong_size (value _); 78 + 79 + 80 + static int parse_digit(char c) 81 + { 82 + if (c >= '0' && c <= '9') 83 + return c - '0'; 84 + else if (c >= 'A' && c <= 'F') 85 + return c - 'A' + 10; 86 + else if (c >= 'a' && c <= 'f') 87 + return c - 'a' + 10; 88 + else 89 + return -1; 90 + } 91 + 92 + #define Uint_custom_val(SIZE, V) Uint_custom_val_(SIZE, V) 93 + #define Uint_custom_val_(SIZE, V) \ 94 + (*(uint ## SIZE ## _t *)(Data_custom_val(V))) 95 + 96 + #define TYPE(SIZE) uint ## SIZE ## _t 97 + #define BUF_SIZE(TYPE) ((sizeof(TYPE) * CHAR_BIT + 2) / 3 + 1) 98 + 99 + #define UINT_PRIMOP(NAME, SIZE, OP) \ 100 + /* OP : t -> t -> t */ \ 101 + value integers_uint ## SIZE ## _ ## NAME(value a, value b) \ 102 + { \ 103 + return integers_copy_uint ## SIZE(Uint_custom_val(SIZE, a) \ 104 + OP Uint_custom_val(SIZE, b)); \ 105 + } 106 + 107 + #define UINT_OF_STRING(BITS, COPY) \ 108 + value integers_uint ## BITS ## _of_string(value a) \ 109 + { \ 110 + TYPE(BITS) u, max_prefix; \ 111 + const char *pos = String_val(a); \ 112 + int base = 10, d; \ 113 + \ 114 + /* Strip a leading + sign, if given */ \ 115 + if (*pos == '+') pos++; \ 116 + if (*pos == '0') { \ 117 + switch (pos[1]) { \ 118 + case 'x': case 'X': \ 119 + base = 16; pos += 2; break; \ 120 + case 'o': case 'O': \ 121 + base = 8; pos += 2; break; \ 122 + case 'b': case 'B': \ 123 + base = 2; pos += 2; break; \ 124 + case 'u': case 'U': /* Unsigned prefix. No-op for unsigned types */ \ 125 + pos += 2; break; \ 126 + } \ 127 + } \ 128 + \ 129 + max_prefix = ((TYPE(BITS)) -1) / base; \ 130 + \ 131 + d = parse_digit(*pos); \ 132 + if (d < 0 || d >= base) { \ 133 + caml_failwith("UInt"#BITS".of_string"); \ 134 + } \ 135 + u = (TYPE(BITS)) d; \ 136 + pos++; \ 137 + \ 138 + for (;; pos++) { \ 139 + if (*pos == '_') continue; \ 140 + d = parse_digit(*pos); \ 141 + /* Halt if the digit isn't valid (or this is the string terminator) */ \ 142 + if (d < 0 || d >= base) break; \ 143 + /* Check that we can add another digit */ \ 144 + if (u > max_prefix) break; \ 145 + u = d + u * base; \ 146 + /* Check for overflow */ \ 147 + if (u < (TYPE(BITS)) d) break; \ 148 + } \ 149 + \ 150 + if (pos != String_val(a) + caml_string_length(a)){ \ 151 + caml_failwith("UInt"#BITS".of_string"); \ 152 + } \ 153 + \ 154 + return COPY(u); \ 155 + } \ 156 + 157 + #define UINT_DEFS(BITS, BYTES) \ 158 + static int uint ## BITS ## _cmp(value v1, value v2) \ 159 + { \ 160 + TYPE(BITS) u1 = Uint_custom_val(BITS, v1); \ 161 + TYPE(BITS) u2 = Uint_custom_val(BITS, v2); \ 162 + return (u1 > u2) - (u1 < u2); \ 163 + } \ 164 + \ 165 + static intnat uint ## BITS ## _hash(value v) \ 166 + { \ 167 + return Uint_custom_val(BITS, v); \ 168 + } \ 169 + \ 170 + static void uint ## BITS ## _serialize(value v, \ 171 + uintnat *wsize_32, \ 172 + uintnat *wsize_64) \ 173 + { \ 174 + caml_serialize_int_ ## BYTES(Uint_custom_val(BITS, v)); \ 175 + *wsize_32 = *wsize_64 = BYTES; \ 176 + } \ 177 + \ 178 + static uintnat uint ## BITS ## _deserialize(void *dst) \ 179 + { \ 180 + *(TYPE(BITS) *)dst = caml_deserialize_uint_ ## BYTES(); \ 181 + return BYTES; \ 182 + } \ 183 + \ 184 + static struct custom_operations caml_uint ## BITS ## _ops = { \ 185 + "integers:uint" #BITS, \ 186 + custom_finalize_default, \ 187 + uint ## BITS ## _cmp, \ 188 + uint ## BITS ## _hash, \ 189 + uint ## BITS ## _serialize, \ 190 + uint ## BITS ## _deserialize, \ 191 + custom_compare_ext_default \ 192 + }; \ 193 + \ 194 + value integers_copy_uint ## BITS(TYPE(BITS) u) \ 195 + { \ 196 + value res = caml_alloc_custom(&caml_uint ## BITS ## _ops, BYTES, 0, 1); \ 197 + Uint_custom_val(BITS, res) = u; \ 198 + return res; \ 199 + } \ 200 + UINT_PRIMOP(add, BITS, +) \ 201 + UINT_PRIMOP(sub, BITS, -) \ 202 + UINT_PRIMOP(mul, BITS, *) \ 203 + UINT_PRIMOP(logand, BITS, &) \ 204 + UINT_PRIMOP(logor, BITS, |) \ 205 + UINT_PRIMOP(logxor, BITS, ^) \ 206 + \ 207 + /* div : t -> t -> t */ \ 208 + value integers_uint ## BITS ## _div(value n_, value d_) \ 209 + { \ 210 + TYPE(BITS) n = Uint_custom_val(BITS, n_); \ 211 + TYPE(BITS) d = Uint_custom_val(BITS, d_); \ 212 + if (d == (TYPE(BITS)) 0) \ 213 + caml_raise_zero_divide(); \ 214 + return integers_copy_uint ## BITS (n / d); \ 215 + } \ 216 + \ 217 + /* rem : t -> t -> t */ \ 218 + value integers_uint ## BITS ## _rem(value n_, value d_) \ 219 + { \ 220 + TYPE(BITS) n = Uint_custom_val(BITS, n_); \ 221 + TYPE(BITS) d = Uint_custom_val(BITS, d_); \ 222 + if (d == (TYPE(BITS)) 0) \ 223 + caml_raise_zero_divide(); \ 224 + return integers_copy_uint ## BITS (n % d); \ 225 + } \ 226 + \ 227 + /* shift_left : t -> int -> t */ \ 228 + value integers_uint ## BITS ## _shift_left(value a, value b) \ 229 + { \ 230 + return integers_copy_uint ## BITS(Uint_custom_val(BITS, a) \ 231 + << Long_val(b)); \ 232 + } \ 233 + \ 234 + /* shift_right : t -> int -> t */ \ 235 + value integers_uint ## BITS ## _shift_right(value a, value b) \ 236 + { \ 237 + return integers_copy_uint ## BITS(Uint_custom_val(BITS, a) \ 238 + >> Long_val(b)); \ 239 + } \ 240 + \ 241 + /* of_int : int -> t */ \ 242 + value integers_uint ## BITS ## _of_int(value a) \ 243 + { \ 244 + return integers_copy_uint ## BITS (Long_val(a)); \ 245 + } \ 246 + \ 247 + /* to_int : t -> int */ \ 248 + value integers_uint ## BITS ## _to_int(value a) \ 249 + { \ 250 + return Val_long(Uint_custom_val(BITS, a)); \ 251 + } \ 252 + \ 253 + /* of_int64 : int64 -> t */ \ 254 + value integers_uint ## BITS ## _of_int64(value a) \ 255 + { \ 256 + return integers_copy_uint ## BITS(Int64_val(a)); \ 257 + } \ 258 + \ 259 + /* to_int64 : t -> int64 */ \ 260 + value integers_uint ## BITS ## _to_int64(value a) \ 261 + { \ 262 + return caml_copy_int64(Uint_custom_val(BITS, a)); \ 263 + } \ 264 + \ 265 + /* of_string : string -> t */ \ 266 + UINT_OF_STRING(BITS, integers_copy_uint ## BITS) \ 267 + \ 268 + /* to_string : t -> string */ \ 269 + value integers_uint ## BITS ## _to_string(value a) \ 270 + { \ 271 + char buf[BUF_SIZE(TYPE(BITS))]; \ 272 + if (sprintf(buf, "%" PRIu ## BITS , Uint_custom_val(BITS, a)) < 0) \ 273 + caml_failwith("UInt ## BITS ## .to_string"); \ 274 + else \ 275 + return caml_copy_string(buf); \ 276 + } \ 277 + \ 278 + /* to_hexstring : t -> string */ \ 279 + value integers_uint ## BITS ## _to_hexstring(value a) \ 280 + { \ 281 + char buf[BUF_SIZE(TYPE(BITS))]; \ 282 + if (sprintf(buf, "%" PRIx ## BITS , Uint_custom_val(BITS, a)) < 0) \ 283 + caml_failwith("UInt ## BITS ## .to_hexstring"); \ 284 + else \ 285 + return caml_copy_string(buf); \ 286 + } \ 287 + \ 288 + /* max : unit -> t */ \ 289 + value integers_uint ## BITS ## _max(value a) \ 290 + { \ 291 + return integers_copy_uint ## BITS ((TYPE(BITS))(-1)); \ 292 + } 293 + 294 + #define UINT_SMALL_DEFS(BITS, BYTES) \ 295 + /* of_string : string -> t */ \ 296 + UINT_OF_STRING(BITS, Integers_val_uint ## BITS) \ 297 + \ 298 + /* to_string : t -> string */ \ 299 + value integers_uint ## BITS ## _to_string(value a) \ 300 + { \ 301 + char buf[BUF_SIZE(TYPE(BITS))]; \ 302 + if (sprintf(buf, "%" PRIu ## BITS , Uint ## BITS ##_val(a)) < 0) \ 303 + caml_failwith("UInt ## BITS ## .to_string"); \ 304 + else \ 305 + return caml_copy_string(buf); \ 306 + } \ 307 + \ 308 + /* to_hexstring : t -> string */ \ 309 + value integers_uint ## BITS ## _to_hexstring(value a) \ 310 + { \ 311 + char buf[BUF_SIZE(TYPE(BITS))]; \ 312 + if (sprintf(buf, "%" PRIx ## BITS , Uint ## BITS ##_val(a)) < 0) \ 313 + caml_failwith("UInt ## BITS ## .to_hexstring"); \ 314 + else \ 315 + return caml_copy_string(buf); \ 316 + } \ 317 + \ 318 + /* max : unit -> t */ \ 319 + value integers_uint ## BITS ## _max(value unit) \ 320 + { \ 321 + return Integers_val_uint ## BITS((TYPE(BITS))(-1)); \ 322 + } 323 + 324 + UINT_SMALL_DEFS(8, 1) 325 + UINT_SMALL_DEFS(16, 2) 326 + UINT_DEFS(32, 4) 327 + UINT_DEFS(64, 8) 328 + 329 + value integers_size_t_size (value _) { return Val_long(sizeof (size_t)); } 330 + value integers_ushort_size (value _) { return Val_long(sizeof (unsigned short)); } 331 + value integers_uint_size (value _) { return Val_long(sizeof (unsigned int)); } 332 + value integers_ulong_size (value _) { return Val_long(sizeof (unsigned long)); } 333 + value integers_ulonglong_size (value _) { return Val_long(sizeof (unsigned long long)); } 334 + value integers_uint32_of_int32 (value i) { return integers_copy_uint32(Int32_val(i)); } 335 + value integers_int32_of_uint32 (value u) { return caml_copy_int32(Uint_custom_val(32, u)); } 336 + value integers_uintptr_t_size (value _) { return Val_long(sizeof (uintptr_t)); } 337 + value integers_intptr_t_size (value _) { return Val_long(sizeof (intptr_t)); } 338 + value integers_ptrdiff_t_size (value _) { return Val_long(sizeof (ptrdiff_t)); } 339 + value integers_uint32_of_uint64 (value u) { return integers_copy_uint32(Uint_custom_val(64,u)); } 340 + value integers_uint64_of_uint32 (value u) { return integers_copy_uint64(Uint_custom_val(32,u)); } 341 + 342 + value integers_unsigned_init(value unit) 343 + { 344 + caml_register_custom_operations(&caml_uint32_ops); 345 + caml_register_custom_operations(&caml_uint64_ops); 346 + return Val_unit; 347 + }
+5
vendor/opam/integers/test/dune
··· 1 + (tests 2 + (package integers) 3 + (libraries integers) 4 + (names hexprinting uint64conversions uint32conversions)) 5 +
+37
vendor/opam/integers/test/hexprinting.ml
··· 1 + (* 2 + * Copyright (c) 2021 Nomadic Labs 3 + * 4 + * This file is distributed under the terms of the MIT License. 5 + * See the file LICENSE for details. 6 + *) 7 + 8 + let () = print_endline "Hexstring test: ?" 9 + 10 + let () = 11 + assert Signed.Int.(to_hexstring (of_string "0x23") = "23"); 12 + assert Signed.Int32.(to_hexstring (of_string "0x23") = "23"); 13 + assert Signed.Int64.(to_hexstring (of_string "0x23") = "23"); 14 + assert Unsigned.UInt8.(to_hexstring (of_string "0x23") = "23"); 15 + assert Unsigned.UInt16.(to_hexstring (of_string "0x23") = "23"); 16 + assert Unsigned.UInt32.(to_hexstring (of_string "0x23") = "23"); 17 + assert Unsigned.UInt64.(to_hexstring (of_string "0x23") = "23"); 18 + () 19 + 20 + let () = 21 + assert Signed.Int32.(to_hexstring (of_string "0xDeadBeef") = "deadbeef"); 22 + assert Signed.Int64.(to_hexstring (of_string "0xDeadBeef") = "deadbeef"); 23 + assert Unsigned.UInt32.(to_hexstring (of_string "0xDeadBeef") = "deadbeef"); 24 + assert Unsigned.UInt64.(to_hexstring (of_string "0xDeadBeef") = "deadbeef"); 25 + () 26 + 27 + let () = 28 + assert Signed.Int.(to_hexstring (of_string "0x0") = "0"); 29 + assert Signed.Int32.(to_hexstring (of_string "0x0") = "0"); 30 + assert Signed.Int64.(to_hexstring (of_string "0x0") = "0"); 31 + assert Unsigned.UInt8.(to_hexstring (of_string "0x0") = "0"); 32 + assert Unsigned.UInt16.(to_hexstring (of_string "0x0") = "0"); 33 + assert Unsigned.UInt32.(to_hexstring (of_string "0x0") = "0"); 34 + assert Unsigned.UInt64.(to_hexstring (of_string "0x0") = "0"); 35 + () 36 + 37 + let () = print_endline "Hexstring test: ✓"
+55
vendor/opam/integers/test/uint32conversions.ml
··· 1 + (* 2 + * Copyright (c) 2021 Nomadic Labs 3 + * 4 + * This file is distributed under the terms of the MIT License. 5 + * See the file LICENSE for details. 6 + *) 7 + 8 + let () = print_endline "UInt32-Int32 conversion test: ?" 9 + 10 + (* Asserting that signed->unsigned conversion is trivial when within range *) 11 + let () = 12 + let check i32 = 13 + let s32 = Int32.to_string i32 in 14 + Unsigned.UInt32.(equal (of_int32 i32) (of_string s32)) 15 + in 16 + assert (check 0l); 17 + assert (check 1l); 18 + assert (check 23l); 19 + assert (check 112783646l); 20 + assert (check Int32.max_int) 21 + 22 + (* Asserting that unsinged->signed conversion is trivial when within range *) 23 + let () = 24 + let check u32 = 25 + let s32 = Unsigned.UInt32.to_string u32 in 26 + Int32.equal (Unsigned.UInt32.to_int32 u32) (Int32.of_string s32) 27 + in 28 + assert (check Unsigned.UInt32.zero); 29 + assert (check Unsigned.UInt32.one); 30 + assert (check (Unsigned.UInt32.of_string "23")); 31 + assert (check (Unsigned.UInt32.of_string "112783646")); 32 + assert (check (Unsigned.UInt32.of_string "2147483647")); 33 + () 34 + 35 + (* Asserting that signed->unsigned->signed roundtrips *) 36 + let () = 37 + assert Unsigned.UInt32.(to_int32 (of_int32 23l) = 23l); 38 + assert Unsigned.UInt32.(to_int32 (of_int32 0l) = 0l); 39 + assert Unsigned.UInt32.(to_int32 (of_int32 (-1l)) = -1l); 40 + assert Unsigned.UInt32.(to_int32 (of_int32 (-23l)) = -23l); 41 + assert Unsigned.UInt32.(to_int32 (of_int32 Int32.max_int) = Int32.max_int); 42 + assert Unsigned.UInt32.(to_int32 (of_int32 Int32.min_int) = Int32.min_int); 43 + () 44 + 45 + (* Asserting that unsigned->signed->unsigned roundtrips *) 46 + let () = 47 + assert Unsigned.UInt32.(equal (of_int32 (to_int32 (of_string "0"))) (of_string "0")); 48 + assert Unsigned.UInt32.(equal (of_int32 (to_int32 (of_string "23"))) (of_string "23")); 49 + assert Unsigned.UInt32.(equal (of_int32 (to_int32 (of_string "2147483647"))) (of_string "2147483647")); 50 + assert Unsigned.UInt32.(equal (of_int32 (to_int32 (of_string "2147483648"))) (of_string "2147483648")); 51 + assert Unsigned.UInt32.(equal (of_int32 (to_int32 (of_string "2147493648"))) (of_string "2147493648")); 52 + assert Unsigned.UInt32.(equal (of_int32 (to_int32 max_int)) max_int); 53 + () 54 + 55 + let () = print_endline "UInt32-Int32 conversion test: ✓"
+55
vendor/opam/integers/test/uint64conversions.ml
··· 1 + (* 2 + * Copyright (c) 2021 Nomadic Labs 3 + * 4 + * This file is distributed under the terms of the MIT License. 5 + * See the file LICENSE for details. 6 + *) 7 + 8 + let () = print_endline "UInt64-Int64 conversion test: ?" 9 + 10 + (* Asserting that signed->unsigned conversion is trivial when within range *) 11 + let () = 12 + let check i64 = 13 + let s64 = Int64.to_string i64 in 14 + Unsigned.UInt64.(equal (of_int64 i64) (of_string s64)) 15 + in 16 + assert (check 0L); 17 + assert (check 1L); 18 + assert (check 23L); 19 + assert (check 709182743098L); 20 + assert (check Int64.max_int) 21 + 22 + (* Asserting that unsinged->signed conversion is trivial when within range *) 23 + let () = 24 + let check u64 = 25 + let s64 = Unsigned.UInt64.to_string u64 in 26 + Int64.equal (Unsigned.UInt64.to_int64 u64) (Int64.of_string s64) 27 + in 28 + assert (check Unsigned.UInt64.zero); 29 + assert (check Unsigned.UInt64.one); 30 + assert (check (Unsigned.UInt64.of_string "23")); 31 + assert (check (Unsigned.UInt64.of_string "709182743098")); 32 + assert (check (Unsigned.UInt64.of_string "9223372036854775807")); 33 + () 34 + 35 + (* Asserting that signed->unsigned->signed roundtrips *) 36 + let () = 37 + assert Unsigned.UInt64.(to_int64 (of_int64 23L) = 23L); 38 + assert Unsigned.UInt64.(to_int64 (of_int64 0L) = 0L); 39 + assert Unsigned.UInt64.(to_int64 (of_int64 (-1L)) = -1L); 40 + assert Unsigned.UInt64.(to_int64 (of_int64 (-23L)) = -23L); 41 + assert Unsigned.UInt64.(to_int64 (of_int64 Int64.max_int) = Int64.max_int); 42 + assert Unsigned.UInt64.(to_int64 (of_int64 Int64.min_int) = Int64.min_int); 43 + () 44 + 45 + (* Asserting that unsigned->signed->unsigned roundtrips *) 46 + let () = 47 + assert Unsigned.UInt64.(equal (of_int64 (to_int64 (of_string "0"))) (of_string "0")); 48 + assert Unsigned.UInt64.(equal (of_int64 (to_int64 (of_string "23"))) (of_string "23")); 49 + assert Unsigned.UInt64.(equal (of_int64 (to_int64 (of_string "9223372036854775807"))) (of_string "9223372036854775807")); 50 + assert Unsigned.UInt64.(equal (of_int64 (to_int64 (of_string "9223372036854775808"))) (of_string "9223372036854775808")); 51 + assert Unsigned.UInt64.(equal (of_int64 (to_int64 (of_string "9223372036954775808"))) (of_string "9223372036954775808")); 52 + assert Unsigned.UInt64.(equal (of_int64 (to_int64 max_int)) max_int); 53 + () 54 + 55 + let () = print_endline "UInt64-Int64 conversion test: ✓"
+6
vendor/opam/integers/top/dune
··· 1 + (library 2 + (name integers_top) 3 + (public_name integers.top) 4 + (modes byte) 5 + (synopsis "toplevel pretty printers") 6 + (libraries integers compiler-libs))
+40
vendor/opam/integers/top/install_integer_printers.ml
··· 1 + (* Adapted from Anil Madhavapeddy's ocaml-uri package. *) 2 + 3 + let printers = [ "fun fmt v -> Format.fprintf fmt \"<sint %s>\" (Signed.SInt.to_string v)"; 4 + "fun fmt v -> Format.fprintf fmt \"<long %s>\" (Signed.Long.to_string v)"; 5 + "fun fmt v -> Format.fprintf fmt \"<llong %s>\" (Signed.LLong.to_string v)"; 6 + "fun fmt v -> Format.fprintf fmt \"<uchar %s>\" (Unsigned.UChar.to_string v)"; 7 + "fun fmt v -> Format.fprintf fmt \"<uint8 %s>\" (Unsigned.UInt8.to_string v)"; 8 + "fun fmt v -> Format.fprintf fmt \"<uint16 %s>\" (Unsigned.UInt16.to_string v)"; 9 + "fun fmt v -> Format.fprintf fmt \"<uint32 %s>\" (Unsigned.UInt32.to_string v)"; 10 + "fun fmt v -> Format.fprintf fmt \"<uint64 %s>\" (Unsigned.UInt64.to_string v)"; 11 + "fun fmt v -> Format.fprintf fmt \"<ushort %s>\" (Unsigned.UShort.to_string v)"; 12 + "fun fmt v -> Format.fprintf fmt \"<uint %s>\" (Unsigned.UInt.to_string v)"; 13 + "fun fmt v -> Format.fprintf fmt \"<ulong %s>\" (Unsigned.ULong.to_string v)"; 14 + "fun fmt v -> Format.fprintf fmt \"<ullong %s>\" (Unsigned.ULLong.to_string v)";] 15 + 16 + let eval_string 17 + ?(print_outcome = false) ?(err_formatter = Format.err_formatter) str = 18 + let lexbuf = Lexing.from_string str in 19 + let phrase = !Toploop.parse_toplevel_phrase lexbuf in 20 + Toploop.execute_phrase print_outcome err_formatter phrase 21 + 22 + let install_printer printer = 23 + begin 24 + ignore (eval_string (Printf.sprintf "let _printer = %s;;" printer)); 25 + ignore (eval_string (Printf.sprintf "#install_printer _printer;;")); 26 + end 27 + 28 + let is_utop () = 29 + Hashtbl.mem Toploop.directive_table "utop_help" [@@ocaml.warning "-3"] 30 + 31 + let () = 32 + (* Preload the toplevel environment and integers library if we are in utop. 33 + This is done to ensure the required modules are in scope before the 34 + printers are installed, as dune will not do this automatically. *) 35 + if is_utop () then begin 36 + Toploop.initialize_toplevel_env (); 37 + ignore (eval_string "#require \"integers\";;"); 38 + end; 39 + 40 + List.iter install_printer printers