12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576(* [Array0] defines array functions that are primitives or can be simply defined in terms
of [Caml.Array]. [Array0] is intended to completely express the part of [Caml.Array]
that [Base] uses -- no other file in Base other than array0.ml should use [Caml.Array].
[Array0] has few dependencies, and so is available early in Base's build order. All
Base files that need to use arrays and come before [Base.Array] in build order should
do [module Array = Array0]. This includes uses of subscript syntax ([x.(i)], [x.(i) <-
e]), which the OCaml parser desugars into calls to [Array.get] and [Array.set].
Defining [module Array = Array0] is also necessary because it prevents ocamldep from
mistakenly causing a file to depend on [Base.Array]. *)open!Import0moduleSys=Sys0letinvalid_argf=Printf.invalid_argfmoduleArray=structexternalcreate:int->'a->'aarray="caml_make_vect"externalcreate_float_uninitialized:int->floatarray="caml_make_float_vect"externalget:'aarray->int->'a="%array_safe_get"externallength:'aarray->int="%array_length"externalset:'aarray->int->'a->unit="%array_safe_set"externalunsafe_get:'aarray->int->'a="%array_unsafe_get"externalunsafe_set:'aarray->int->'a->unit="%array_unsafe_set"externalunsafe_blit:src:'aarray->src_pos:int->dst:'aarray->dst_pos:int->len:int->unit="caml_array_blit"endincludeArrayletmax_length=Sys.max_array_lengthletcreate~lenx=trycreatelenxwith|Invalid_argument_->invalid_argf"Array.create ~len:%d: invalid length"len();;letcreate_float_uninitialized~len=trycreate_float_uninitializedlenwith|Invalid_argument_->invalid_argf"Array.create_float_uninitialized ~len:%d: invalid length"len();;letappend=Caml.Array.appendletblit=Caml.Array.blitletconcat=Caml.Array.concatletcopy=Caml.Array.copyletfill=Caml.Array.fillletinit=Caml.Array.initletmake_matrix=Caml.Array.make_matrixletof_list=Caml.Array.of_listletsub=Caml.Array.subletto_list=Caml.Array.to_list(* These are eta expanded in order to permute parameter order to follow Base
conventions. *)letfoldt~init~f=Caml.Array.fold_leftt~init~fletfold_rightt~f~init=Caml.Array.fold_rightt~f~initletitert~f=Caml.Array.itert~fletiterit~f=Caml.Array.iterit~fletmapt~f=Caml.Array.mapt~fletmapit~f=Caml.Array.mapit~fletstable_sortt~compare=Caml.Array.stable_sortt~cmp:compareletswaptij=letelt_i=t.(i)inletelt_j=t.(j)inunsafe_settielt_j;unsafe_settjelt_i;;