123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164(*
* Copyright (c) 2013 Jeremy Yallop.
* Copyright (c) 2021 Nomadic Labs
*
* This file is distributed under the terms of the MIT License.
* See the file LICENSE for details.
*)modulePervasives=Pervasives[@@ocaml.warning"-3"]moduletypeInfix=sigtypetincludeUnsigned.Infixwithtypet:=tval(asr):t->int->tendmoduletypeS=sigtypetmoduleInfix:Infixwithtypet:=tincludeUnsigned.Swithtypet:=twithmoduleInfix:=Infixvalneg:t->tvalabs:t->tvalminus_one:tvalmin_int:tvalshift_right_logical:t->int->tvalof_nativeint:nativeint->tvalto_nativeint:t->nativeintvalof_int64:int64->tvalto_int64:t->int64endmoduletypeBasics=sigtypetvaladd:t->t->tvalsub:t->t->tvalmul:t->t->tvaldiv:t->t->tvalrem:t->t->tvallogand:t->t->tvallogor:t->t->tvallogxor:t->t->tvalshift_left:t->int->tvalshift_right:t->int->tvalshift_right_logical:t->int->tendmoduleMakeInfix(S:Basics)=structopenSlet(+)=addlet(-)=sublet(*)=mullet(/)=divlet(mod)=remlet(land)=logandlet(lor)=logorlet(lxor)=logxorlet(lsl)=shift_leftlet(lsr)=shift_right_logicallet(asr)=shift_rightendexternalformat_int:string->int->string="caml_format_int"moduleInt=structmoduleBasics=structtypet=intletadd=(+)letsub=(-)letmul=(*)letdiv=(/)letrem=(mod)letmax_int=Pervasives.max_intletmin_int=Pervasives.min_intletlogand=(land)letlogor=(lor)letlogxor=(lxor)letshift_left=(lsl)letshift_right=(asr)letshift_right_logical=(lsr)letof_intx=xletto_intx=xletof_string=int_of_stringletof_string_opt=int_of_string_optletto_string=string_of_intletto_hexstring=format_int"%x"letzero=0letone=1letminus_one=-1letlognot=lnotletsucc=Pervasives.succletpred=Pervasives.predletcompare=Pervasives.compareletequal=Pervasives.(=)letmax=Pervasives.maxletmin=Pervasives.minendincludeBasicsmoduleInfix=MakeInfix(Basics)letto_int64=Int64.of_intletof_int64=Int64.to_intletto_nativeint=Nativeint.of_intletof_nativeint=Nativeint.to_intletabs=Pervasives.absletnegx=-xletppfmtn=Format.fprintffmt"%d"nletpp_hexfmtn=Format.fprintffmt"%x"nendmoduleInt32=struct(* Int32.equal was introduced in OCaml 4.03.0 *)letequal(x:int32)(y:int32)=x=y[@@ocaml.warning"-32"]includeInt32moduleInfix=MakeInfix(Int32)letof_nativeint=Nativeint.to_int32letto_nativeint=Nativeint.of_int32letof_int64=Int64.to_int32letto_int64=Int64.of_int32letmax=Pervasives.maxletmin=Pervasives.minletppfmtn=Format.fprintffmt"%ld"nletpp_hexfmtn=Format.fprintffmt"%lx"nletto_hexstringn=Format.asprintf"%lx"nendmoduleInt64=struct(* Int64.equal was introduced in OCaml 4.03.0 *)letequal(x:int64)(y:int64)=x=y[@@ocaml.warning"-32"]includeInt64moduleInfix=MakeInfix(Int64)letof_int64x=xletto_int64x=xletmax=Pervasives.maxletmin=Pervasives.minletppfmtn=Format.fprintffmt"%Ld"nletpp_hexfmtn=Format.fprintffmt"%Lx"nletto_hexstringn=Format.asprintf"%Lx"nend(* C guarantees that sizeof(t) == sizeof(unsigned t) *)externalint_size:unit->int="integers_uint_size"externallong_size:unit->int="integers_ulong_size"externalllong_size:unit->int="integers_ulonglong_size"letof_byte_size:int->(moduleS)=function|4->(moduleInt32)|8->(moduleInt64)|_->invalid_arg"Signed.of_byte_size"moduleSInt=(valof_byte_size(int_size()))moduleLong=(valof_byte_size(long_size()))moduleLLong=(valof_byte_size(llong_size()))typesint=SInt.ttypelong=Long.ttypellong=LLong.t