Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file int63.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183open!Importletraise_s=Error.raise_smoduleRepr=Int63_emul.Repr(* In a world where the compiler would understand [@@immediate64] attributes on type
declarations, this module is how one would produce a [type t] with this attribute. *)moduleImmediate64:sigmoduletypeNon_immediate=sigtypetendmoduletypeImmediate=sigtypet[@@immediate]endmoduleMake(Immediate:Immediate)(Non_immediate:Non_immediate):sigtypet[@@immediate64]type'arepr=|Immediate:Immediate.trepr|Non_immediate:Non_immediate.treprvalrepr:treprendend=structmoduletypeNon_immediate=sigtypetendmoduletypeImmediate=sigtypet[@@immediate]endmoduleMake(Immediate:Immediate)(Non_immediate:Non_immediate)=structtypet[@@immediate64]type'arepr=|Immediate:Immediate.trepr|Non_immediate:Non_immediate.treprletrepr=matchWord_size.word_sizewith|W64->(Caml.Obj.magicImmediate:trepr)|W32->(Caml.Obj.magicNon_immediate:trepr);;endendincludeImmediate64.Make(Int)(Int63_emul)moduleBackend=structmoduletypeS=sigtypet[@@deriving_inlinehash]includesig[@@@ocaml.warning"-32"]valhash_fold_t:Ppx_hash_lib.Std.Hash.state->t->Ppx_hash_lib.Std.Hash.statevalhash:t->Ppx_hash_lib.Std.Hash.hash_valueend[@@ocaml.doc"@inline"][@@@end]includeInt_intf.Swithtypet:=tvalof_int:int->tvalto_int:t->intoptionvalto_int_trunc:t->intvalof_int32:int32->tvalto_int32:t->Int32.toptionvalto_int32_trunc:t->Int32.tvalof_int64:Int64.t->toptionvalof_int64_trunc:Int64.t->tvalof_nativeint:nativeint->toptionvalto_nativeint:t->nativeintoptionvalof_nativeint_trunc:nativeint->tvalto_nativeint_trunc:t->nativeintvalof_float_unchecked:float->tvalrepr:(t,t)Int63_emul.Repr.tendwithtypet:=tmoduleNative=structincludeIntletto_intx=Somexletto_int_truncx=x(* [of_int32_exn] is a safe operation on platforms with 64-bit word sizes. *)letof_int32=of_int32_exnletto_nativeint_truncx=to_nativeintxletto_nativeintx=Some(to_nativeintx)letrepr=Int63_emul.Repr.Intendletimpl:(moduleS)=matchreprwith|Immediate->(moduleNative:S)|Non_immediate->(moduleInt63_emul:S);;endinclude(valBackend.impl:Backend.S)moduleOverflow_exn=structlet(+)tu=letsum=t+uinifbit_or(bit_xortu)(bit_xort(bit_notsum))<zerothensumelseraise_s(Sexp.message"( + ) overflow"["t",sexp_of_tt;"u",sexp_of_tu;"sum",sexp_of_tsum]);;let(-)tu=letdiff=t-uinletpos_diff=t>uinift<>u&&Bool.(<>)pos_diff(is_positivediff)thenraise_s(Sexp.message"( - ) overflow"["t",sexp_of_tt;"u",sexp_of_tu;"diff",sexp_of_tdiff])elsediff;;letabst=ift=min_valuethenfailwith"abs overflow"elseabstletnegt=ift=min_valuethenfailwith"neg overflow"elsenegtendlet()=assert(Int.(=)num_bits63)letrandom_of_int?(state=Random.State.default)bound=of_int(Random.State.intstate(to_int_exnbound));;letrandom_of_int64?(state=Random.State.default)bound=of_int64_exn(Random.State.int64state(to_int64bound));;letrandom=matchWord_size.word_sizewith|W64->random_of_int|W32->random_of_int64;;letrandom_incl_of_int?(state=Random.State.default)lohi=of_int(Random.State.int_inclstate(to_int_exnlo)(to_int_exnhi));;letrandom_incl_of_int64?(state=Random.State.default)lohi=of_int64_exn(Random.State.int64_inclstate(to_int64lo)(to_int64hi));;letrandom_incl=matchWord_size.word_sizewith|W64->random_incl_of_int|W32->random_incl_of_int64;;letfloor_log2t=matchWord_size.word_sizewith|W64->t|>to_int_exn|>Int.floor_log2|W32->ift<=zerothenraise_s(Sexp.message"[Int.floor_log2] got invalid input"["",sexp_of_tt]);letfloor_log2=ref(Int.(-)num_bits2)inwhileequalzero(bit_andt(shift_leftone!floor_log2))dofloor_log2:=Int.(-)!floor_log21done;!floor_log2;;modulePrivate=structmoduleRepr=Reprletrepr=reprmoduleEmul=Int63_emulend