123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175(* [Bytes0] defines string functions that are primitives or can be simply
defined in terms of [Stdlib.Bytes]. [Bytes0] is intended to completely express
the part of [Stdlib.Bytes] that [Base] uses -- no other file in Base other
than bytes0.ml should use [Stdlib.Bytes]. [Bytes0] has few dependencies, and
so is available early in Base's build order.
All Base files that need to use strings and come before [Base.Bytes] in
build order should do:
{[
module Bytes = Bytes0
]}
Defining [module Bytes = Bytes0] is also necessary because it prevents
ocamldep from mistakenly causing a file to depend on [Base.Bytes]. *)open!Import0moduleUchar=Uchar0moduleSys=Sys0modulePrimitives=structexternalget:(bytes[@local_opt])->(int[@local_opt])->char="%bytes_safe_get"externallength:(bytes[@local_opt])->int="%bytes_length"externalunsafe_get:(bytes[@local_opt])->(int[@local_opt])->char="%bytes_unsafe_get"externalset:(bytes[@local_opt])->(int[@local_opt])->(char[@local_opt])->unit="%bytes_safe_set"externalunsafe_set:(bytes[@local_opt])->(int[@local_opt])->(char[@local_opt])->unit="%bytes_unsafe_set"(* [unsafe_blit_string] is not exported in the [stdlib] so we export it here *)externalunsafe_blit_string:src:(string[@local_opt])->src_pos:int->dst:(bytes[@local_opt])->dst_pos:int->len:int->unit="caml_blit_string"[@@noalloc]externalunsafe_get_int64:(bytes[@local_opt])->(int[@local_opt])->int64="%caml_bytes_get64u"externalunsafe_set_int64:(bytes[@local_opt])->(int[@local_opt])->(int64[@local_opt])->unit="%caml_bytes_set64u"externalunsafe_get_int32:(bytes[@local_opt])->(int[@local_opt])->int32="%caml_bytes_get32u"externalunsafe_set_int32:(bytes[@local_opt])->(int[@local_opt])->(int32[@local_opt])->unit="%caml_bytes_set32u"externalunsafe_get_int16:(bytes[@local_opt])->(int[@local_opt])->int="%caml_bytes_get16u"externalunsafe_set_int16:(bytes[@local_opt])->(int[@local_opt])->(int[@local_opt])->unit="%caml_bytes_set16u"endincludePrimitivesletmax_length=Sys.max_string_lengthletblit=Stdlib.Bytes.blitletblit_string=Stdlib.Bytes.blit_stringletcompare=Stdlib.Bytes.compareletcopy=Stdlib.Bytes.copyletcreate=Stdlib.Bytes.createletset_uchar_utf_8=Stdlib.Bytes.set_utf_8_ucharletset_uchar_utf_16le=Stdlib.Bytes.set_utf_16le_ucharletset_uchar_utf_16be=Stdlib.Bytes.set_utf_16be_ucharletset_utf_32_uchar~set_int32bytesidxuchar=Uchar.to_intuchar|>Int_conversions.int_to_int32_trunc(* should never have anything to truncate *)|>set_int32bytesidx;4;;letset_uchar_utf_32le=set_utf_32_uchar~set_int32:Stdlib.Bytes.set_int32_leletset_uchar_utf_32be=set_utf_32_uchar~set_int32:Stdlib.Bytes.set_int32_beexternalunsafe_create_local:int->bytes="Base_unsafe_create_local_bytes"letcreate_locallen=iflen>Sys0.max_string_lengththeninvalid_arg"Bytes.create_local";unsafe_create_locallen;;letfill=Stdlib.Bytes.fillletmake=Stdlib.Bytes.makeletmapt~(f:_->_)=letl=lengthtinifl=0thentelse(letr=createlinfori=0tol-1dounsafe_setri(f(unsafe_getti))done;r);;letmapit~(f:_->_->_)=letl=lengthtinifl=0thentelse(letr=createlinfori=0tol-1dounsafe_setri(fi(unsafe_getti))done;r);;letsub=Stdlib.Bytes.subexternalunsafe_blit:src:(bytes[@local_opt])->src_pos:int->dst:(bytes[@local_opt])->dst_pos:int->len:int->unit="caml_blit_bytes"[@@noalloc]letto_string=Stdlib.Bytes.to_stringletof_string=Stdlib.Bytes.of_stringexternalunsafe_to_string:no_mutation_while_string_reachable:(bytes[@local_opt])->(string[@local_opt])="%bytes_to_string"externalunsafe_of_string_promise_no_mutation:(string[@local_opt])->(bytes[@local_opt])="%bytes_of_string"