From 99791f55f7d3a1ab9819d8b2f2e256b6f54b74f8 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Tue, 20 Oct 2020 11:41:49 -0700 Subject: [PATCH] [sledge] Switch from Base.Int to Stdlib and Containers Reviewed By: ngorogiannis Differential Revision: D24306060 fbshipit-source-id: bbb196f5f --- sledge/nonstdlib/NS0.ml | 26 ++++++++++++---------- sledge/nonstdlib/int.ml | 47 ++++++++++++++++++++++++++++++++++++---- sledge/nonstdlib/int.mli | 36 ++++++++++++++++++++++++++++-- 3 files changed, 92 insertions(+), 17 deletions(-) diff --git a/sledge/nonstdlib/NS0.ml b/sledge/nonstdlib/NS0.ml index de4d6c40e..ff6ca805e 100644 --- a/sledge/nonstdlib/NS0.ml +++ b/sledge/nonstdlib/NS0.ml @@ -23,17 +23,21 @@ include Iter.Import (** Specialize polymorphic comparison to int *) -external ( = ) : int -> int -> bool = "%equal" -external ( <> ) : int -> int -> bool = "%notequal" -external ( < ) : int -> int -> bool = "%lessthan" -external ( > ) : int -> int -> bool = "%greaterthan" -external ( <= ) : int -> int -> bool = "%lessequal" -external ( >= ) : int -> int -> bool = "%greaterequal" -external compare : int -> int -> int = "%compare" -external equal : int -> int -> bool = "%equal" - -let min x y = if x <= y then x else y -let max x y = if x >= y then x else y +module Int_compare = struct + external ( = ) : int -> int -> bool = "%equal" + external ( <> ) : int -> int -> bool = "%notequal" + external ( < ) : int -> int -> bool = "%lessthan" + external ( > ) : int -> int -> bool = "%greaterthan" + external ( <= ) : int -> int -> bool = "%lessequal" + external ( >= ) : int -> int -> bool = "%greaterequal" + external compare : int -> int -> int = "%compare" + external equal : int -> int -> bool = "%equal" + + let min x y = if x <= y then x else y + let max x y = if x >= y then x else y +end + +include Int_compare (** Polymorphic comparison and hashing *) module Poly = struct diff --git a/sledge/nonstdlib/int.ml b/sledge/nonstdlib/int.ml index f210464a9..09170fef8 100644 --- a/sledge/nonstdlib/int.ml +++ b/sledge/nonstdlib/int.ml @@ -6,7 +6,46 @@ *) open! NS0 -include CCInt -include Base.Int -module Set = Set.Make (Base.Int) -module Map = Map.Make (Base.Int) +include Containers.Int +include Stdlib.Int + +module T = struct + type t = int [@@deriving compare, equal, hash, sexp] +end + +include T + +module Infix = struct + include Containers.Int.Infix + include Int_compare + + external ( + ) : t -> t -> t = "%addint" + external ( - ) : t -> t -> t = "%subint" + external ( ~- ) : t -> t = "%negint" + external ( * ) : t -> t -> t = "%mulint" + external ( / ) : t -> t -> t = "%divint" + + let ( ** ) = pow + + external ( mod ) : t -> t -> t = "%modint" + external ( land ) : t -> t -> t = "%andint" + external ( lor ) : t -> t -> t = "%orint" + external ( lxor ) : t -> t -> t = "%xorint" + + let lnot = lnot + + external ( lsl ) : t -> int -> t = "%lslint" + external ( lsr ) : t -> int -> t = "%lsrint" + external ( asr ) : t -> int -> t = "%asrint" +end + +include Infix + +let of_string = int_of_string_opt +let of_string_exn = int_of_string +let sign = Sign.of_int +let incr = incr +let decr = decr + +module Set = Set.Make (T) +module Map = Map.Make (T) diff --git a/sledge/nonstdlib/int.mli b/sledge/nonstdlib/int.mli index 8783af4d8..45201fad1 100644 --- a/sledge/nonstdlib/int.mli +++ b/sledge/nonstdlib/int.mli @@ -6,7 +6,39 @@ *) open! NS0 -include module type of CCInt -include module type of Base.Int +include module type of Containers.Int +include module type of Stdlib.Int + +type t = int [@@deriving compare, equal, hash, sexp] + +val of_string : string -> int option +val of_string_exn : string -> int +val sign : int -> Sign.t +val incr : int ref -> unit +val decr : int ref -> unit + +module Infix : sig + val ( -- ) : t -> t -> t iter + val ( --^ ) : t -> t -> t iter + + include module type of NS0.Int_compare + + external ( + ) : t -> t -> t = "%addint" + external ( - ) : t -> t -> t = "%subint" + external ( ~- ) : t -> t = "%negint" + external ( * ) : t -> t -> t = "%mulint" + external ( / ) : t -> t -> t = "%divint" + val ( ** ) : t -> t -> t + external ( mod ) : t -> t -> t = "%modint" + external ( land ) : t -> t -> t = "%andint" + external ( lor ) : t -> t -> t = "%orint" + external ( lxor ) : t -> t -> t = "%xorint" + val lnot : t -> t + external ( lsl ) : t -> t -> t = "%lslint" + external ( lsr ) : t -> t -> t = "%lsrint" + external ( asr ) : t -> t -> t = "%asrint" +end + +include module type of Infix module Set : Set.S with type elt = int module Map : Map.S with type key = int