Skip to content

Commit efc5211

Browse files
authored
Add predefined types for tagged int8 and int16 (#3347)
added predefined types for int8 and int16, along with modules for them in Stdlib_beta
1 parent 4da0719 commit efc5211

31 files changed

+1388
-439
lines changed

otherlibs/stdlib_beta/.ocamlformat

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Please make a pull request to change this file.
2+
# Keep the remainder of this file in sync with other .ocamlformat files in this repo.
3+
assignment-operator=begin-line
4+
cases-exp-indent=2
5+
doc-comments=before
6+
dock-collection-brackets=false
7+
if-then-else=keyword-first
8+
module-item-spacing=sparse
9+
parens-tuple=multi-line-only
10+
sequence-blank-line=compact
11+
space-around-lists=false
12+
space-around-variants=false
13+
type-decl=sparse
14+
wrap-comments=true
15+
version=0.24.1
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
stdlib_beta.mli
1+
int8.ml
2+
int8.mli
3+
int16.ml
4+
int16.mli
5+
int_wrapper.ml
26
stdlib_beta.ml
3-
7+
stdlib_beta.mli

otherlibs/stdlib_beta/dune

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
-safe-string
2525
-strict-formats
2626
-extension-universe
27-
beta))
27+
beta
28+
-extension
29+
small_numbers_beta
30+
))
2831
(ocamlopt_flags
2932
(:include %{project_root}/ocamlopt_flags.sexp))
3033
(library_flags

otherlibs/stdlib_beta/int16.ml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Jacob Van Buren, Jane Street, New York *)
6+
(* *)
7+
(* Copyright 2024 Jane Street Group LLC *)
8+
(* *)
9+
(* All rights reserved. This file is distributed under the terms of *)
10+
(* the GNU Lesser General Public License version 2.1, with the *)
11+
(* special exception on linking described in the file LICENSE. *)
12+
(* *)
13+
(**************************************************************************)
14+
15+
[@@@ocaml.flambda_o3]
16+
17+
type t = int16
18+
19+
include
20+
Int_wrapper.Make
21+
(Int_wrapper)
22+
(struct
23+
type nonrec t = t
24+
25+
let int_size = 16
26+
27+
external inject : t -> int = "%identity"
28+
29+
external unchecked_project : int -> t = "%identity"
30+
end)

otherlibs/stdlib_beta/int16.mli

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Jacob Van Buren, Jane Street, New York *)
6+
(* *)
7+
(* Copyright 2024 Jane Street Group LLC *)
8+
(* *)
9+
(* All rights reserved. This file is distributed under the terms of *)
10+
(* the GNU Lesser General Public License version 2.1, with the *)
11+
(* special exception on linking described in the file LICENSE. *)
12+
(* *)
13+
(**************************************************************************)
14+
15+
(** Signed 16-bit integer values.
16+
17+
These integers are {16} bits wide and use two's complement representation.
18+
All operations are taken modulo 2{^16}. They do not fail on overflow. *)
19+
20+
(** The type for 16-bit integer values. *)
21+
type t = int16 [@@immediate]
22+
23+
(** @inline *)
24+
include Int_wrapper.S with type t := int16

otherlibs/stdlib_beta/int8.ml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Jacob Van Buren, Jane Street, New York *)
6+
(* *)
7+
(* Copyright 2024 Jane Street Group LLC *)
8+
(* *)
9+
(* All rights reserved. This file is distributed under the terms of *)
10+
(* the GNU Lesser General Public License version 2.1, with the *)
11+
(* special exception on linking described in the file LICENSE. *)
12+
(* *)
13+
(**************************************************************************)
14+
15+
[@@@ocaml.flambda_o3]
16+
17+
type t = int8
18+
19+
include
20+
Int_wrapper.Make
21+
(Int_wrapper)
22+
(struct
23+
type nonrec t = t
24+
25+
let int_size = 8
26+
27+
external inject : t -> int = "%identity"
28+
29+
external unchecked_project : int -> t = "%identity"
30+
end)

otherlibs/stdlib_beta/int8.mli

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Jacob Van Buren, Jane Street, New York *)
6+
(* *)
7+
(* Copyright 2024 Jane Street Group LLC *)
8+
(* *)
9+
(* All rights reserved. This file is distributed under the terms of *)
10+
(* the GNU Lesser General Public License version 2.1, with the *)
11+
(* special exception on linking described in the file LICENSE. *)
12+
(* *)
13+
(**************************************************************************)
14+
15+
(** Signed 8-bit integer values.
16+
17+
These integers are {8} bits wide and use two's complement representation.
18+
All operations are taken modulo 2{^8}. They do not fail on overflow. *)
19+
20+
(** The type for 8-bit integer values. *)
21+
type t = int8 [@@immediate]
22+
23+
(** @inline *)
24+
include Int_wrapper.S with type t := int8

0 commit comments

Comments
 (0)