Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add predefined types for tagged int8 and int16 #3347

Merged
merged 11 commits into from
Dec 20, 2024
15 changes: 15 additions & 0 deletions otherlibs/stdlib_beta/.ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Please make a pull request to change this file.
# Keep the remainder of this file in sync with other .ocamlformat files in this repo.
assignment-operator=begin-line
cases-exp-indent=2
doc-comments=before
dock-collection-brackets=false
if-then-else=keyword-first
module-item-spacing=sparse
parens-tuple=multi-line-only
sequence-blank-line=compact
space-around-lists=false
space-around-variants=false
type-decl=sparse
wrap-comments=true
version=0.24.1
8 changes: 6 additions & 2 deletions otherlibs/stdlib_beta/.ocamlformat-enable
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
stdlib_beta.mli
int8.ml
int8.mli
int16.ml
int16.mli
int_wrapper.ml
stdlib_beta.ml

stdlib_beta.mli
5 changes: 4 additions & 1 deletion otherlibs/stdlib_beta/dune
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
-safe-string
-strict-formats
-extension-universe
beta))
beta
-extension
small_numbers_beta
))
(ocamlopt_flags
(:include %{project_root}/ocamlopt_flags.sexp))
(library_flags
Expand Down
30 changes: 30 additions & 0 deletions otherlibs/stdlib_beta/int16.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(**************************************************************************)
jvanburen marked this conversation as resolved.
Show resolved Hide resolved
(* *)
(* OCaml *)
(* *)
(* Jacob Van Buren, Jane Street, New York *)
(* *)
(* Copyright 2024 Jane Street Group LLC *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)

[@@@ocaml.flambda_o3]

type t = int16

include
Int_wrapper.Make
(Int_wrapper)
(struct
type nonrec t = t

let int_size = 16

external inject : t -> int = "%identity"

external unchecked_project : int -> t = "%identity"
end)
24 changes: 24 additions & 0 deletions otherlibs/stdlib_beta/int16.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(**************************************************************************)
jvanburen marked this conversation as resolved.
Show resolved Hide resolved
(* *)
(* OCaml *)
(* *)
(* Jacob Van Buren, Jane Street, New York *)
(* *)
(* Copyright 2024 Jane Street Group LLC *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)

(** Signed 16-bit integer values.

These integers are {16} bits wide and use two's complement representation.
All operations are taken modulo 2{^16}. They do not fail on overflow. *)

(** The type for 16-bit integer values. *)
type t = int16 [@@immediate]

(** @inline *)
include Int_wrapper.S with type t := int16
30 changes: 30 additions & 0 deletions otherlibs/stdlib_beta/int8.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Jacob Van Buren, Jane Street, New York *)
(* *)
(* Copyright 2024 Jane Street Group LLC *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)

[@@@ocaml.flambda_o3]

type t = int8

include
Int_wrapper.Make
(Int_wrapper)
(struct
type nonrec t = t

let int_size = 8

external inject : t -> int = "%identity"

external unchecked_project : int -> t = "%identity"
end)
24 changes: 24 additions & 0 deletions otherlibs/stdlib_beta/int8.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Jacob Van Buren, Jane Street, New York *)
(* *)
(* Copyright 2024 Jane Street Group LLC *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)

(** Signed 8-bit integer values.

These integers are {8} bits wide and use two's complement representation.
All operations are taken modulo 2{^8}. They do not fail on overflow. *)

(** The type for 8-bit integer values. *)
type t = int8 [@@immediate]

(** @inline *)
include Int_wrapper.S with type t := int8
Loading
Loading