123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630(*Generated by Lem from missing_pervasives.lem.*)openLem_basic_classesopenLem_boolopenLem_listopenLem_maybeopenLem_numopenLem_stringopenLem_assert_extraopenShowopenLem_sorting(*val naturalZero : natural*)(*let naturalZero:natural= 0*)(*val id : forall 'a. 'a -> 'a*)letid0x:'a=x(*type byte*)(*val natural_of_byte : byte -> natural*)letcompare_byteb1b2:int=(Nat_big_num.compare(Nat_big_num.of_int(Char.codeb1))(Nat_big_num.of_int(Char.codeb2)))letinstance_Basic_classes_Ord_Missing_pervasives_byte_dict:(char)ord_class=({compare_method=compare_byte;isLess_method=(funf1->(funf2->(Lem.orderingEqual(compare_bytef1f2)(-1))));isLessEqual_method=(funf1->(funf2->letresult=(compare_bytef1f2)inLem.orderingEqualresult(-1)||Lem.orderingEqualresult0));isGreater_method=(funf1->(funf2->(Lem.orderingEqual(compare_bytef1f2)1)));isGreaterEqual_method=(funf1->(funf2->letresult=(compare_bytef1f2)inLem.orderingEqualresult1||Lem.orderingEqualresult0))})(*val char_of_byte : byte -> char*)(*val byte_of_char : char -> byte*)(* Define how to print a byte in hex *)(*val hex_char_of_nibble : natural -> char*)lethex_char_of_nibblen:char=(ifNat_big_num.equaln((Nat_big_num.of_int0))then'0'elseifNat_big_num.equaln((Nat_big_num.of_int1))then'1'elseifNat_big_num.equaln((Nat_big_num.of_int2))then'2'elseifNat_big_num.equaln((Nat_big_num.of_int3))then'3'elseifNat_big_num.equaln((Nat_big_num.of_int4))then'4'elseifNat_big_num.equaln((Nat_big_num.of_int5))then'5'elseifNat_big_num.equaln((Nat_big_num.of_int6))then'6'elseifNat_big_num.equaln((Nat_big_num.of_int7))then'7'elseifNat_big_num.equaln((Nat_big_num.of_int8))then'8'elseifNat_big_num.equaln((Nat_big_num.of_int9))then'9'elseifNat_big_num.equaln((Nat_big_num.of_int10))then'a'elseifNat_big_num.equaln((Nat_big_num.of_int11))then'b'elseifNat_big_num.equaln((Nat_big_num.of_int12))then'c'elseifNat_big_num.equaln((Nat_big_num.of_int13))then'd'elseifNat_big_num.equaln((Nat_big_num.of_int14))then'e'elseifNat_big_num.equaln((Nat_big_num.of_int15))then'f'else(assertfalse))lethex_string_of_byteb:string=(Xstring.implode[hex_char_of_nibble(Nat_big_num.div(Nat_big_num.of_int(Char.codeb))((Nat_big_num.of_int16)));hex_char_of_nibble(Nat_big_num.modulus(Nat_big_num.of_int(Char.codeb))((Nat_big_num.of_int16)))])letinstance_Show_Show_Missing_pervasives_byte_dict:(char)show_class=({show_method=hex_string_of_byte})(*val natural_of_decimal_digit : char -> maybe natural*)letnatural_of_decimal_digitc:(Nat_big_num.num)option=(ifc='0'thenSome((Nat_big_num.of_int0))elseifc='1'thenSome((Nat_big_num.of_int1))elseifc='2'thenSome((Nat_big_num.of_int2))elseifc='3'thenSome((Nat_big_num.of_int3))elseifc='4'thenSome((Nat_big_num.of_int4))elseifc='5'thenSome((Nat_big_num.of_int5))elseifc='6'thenSome((Nat_big_num.of_int6))elseifc='7'thenSome((Nat_big_num.of_int7))elseifc='8'thenSome((Nat_big_num.of_int8))elseifc='9'thenSome((Nat_big_num.of_int9))elseNone)(*val natural_of_decimal_string_helper : natural -> list char -> natural*)letrecnatural_of_decimal_string_helperaccchars:Nat_big_num.num=((matchcharswith[]->acc|c::cs->(matchnatural_of_decimal_digitcwithSomedig->natural_of_decimal_string_helper(Nat_big_num.add(Nat_big_num.mul((Nat_big_num.of_int10))acc)dig)cs|None->acc)))(*val natural_of_decimal_string : string -> natural*)letnatural_of_decimal_strings:Nat_big_num.num=(natural_of_decimal_string_helper((Nat_big_num.of_int0))(Xstring.explodes))(*val hex_string_of_natural : natural -> string*)letrechex_string_of_naturaln:string=(ifNat_big_num.lessn((Nat_big_num.of_int16))thenXstring.implode[hex_char_of_nibblen]else(hex_string_of_natural(Nat_big_num.divn((Nat_big_num.of_int16))))^(Xstring.implode[hex_char_of_nibble(Nat_big_num.modulusn((Nat_big_num.of_int16)))]))(*val natural_of_bool : bool -> natural*)letnatural_of_boolb:Nat_big_num.num=((matchbwith|true->(Nat_big_num.of_int1)|false->(Nat_big_num.of_int0)))(*val unsafe_nat_of_natural : natural -> nat*)(*val unsafe_int_of_natural : natural -> int*)(*val byte_of_natural : natural -> byte*)(*val natural_ordering : natural -> natural -> ordering*)(*let natural_ordering left right:ordering=
if (Instance_Basic_classes_Eq_Num_natural.=) left right then
EQ
else if (Instance_Basic_classes_Ord_Num_natural.<) left right then
LT
else
GT*)(*val merge_by : forall 'a. ('a -> 'a -> ordering) -> list 'a -> list 'a -> list 'a*)letrecmerge_bycompxsys:'alist=((match(xs,ys)with|([],ys)->ys|(xs,[])->xs|(x::xs,y::ys)->ifLem.orderingEqual(compxy)(-1)thenx::(merge_bycompxs(y::ys))elsey::(merge_bycomp(x::xs)ys)))(*val sort_by : forall 'a. ('a -> 'a -> ordering) -> list 'a -> list 'a*)(*let rec sort_by comp xs:list 'a=
match xs with
| [] -> []
| [x] -> [x]
| xs ->
let ls = List.take (Instance_Num_NumIntegerDivision_nat.div List.length xs 2) xs in
let rs = List.drop (Instance_Num_NumIntegerDivision_nat.div List.length xs 2) xs in
merge_by comp (sort_by comp ls) (sort_by comp rs)
end*)(** [mapMaybei f xs] maps a function expecting an index (the position in the list
* [xs] that it is currently viewing) and producing a [maybe] type across a list.
* Elements that produce [Nothing] under [f] are discarded in the output, whilst
* those producing [Just e] for some [e] are kept.
*)(*val mapMaybei' : forall 'a 'b. (natural -> 'a -> maybe 'b) -> natural -> list 'a -> list 'b*)letrecmapMaybei'fidx1xs:'blist=((matchxswith|[]->[]|x::xs->(matchfidx1xwith|None->mapMaybei'f(Nat_big_num.add((Nat_big_num.of_int1))idx1)xs|Somee->e::mapMaybei'f(Nat_big_num.add((Nat_big_num.of_int1))idx1)xs)))(*val mapMaybei : forall 'a 'b. (natural -> 'a -> maybe 'b) -> list 'a -> list 'b*)letmapMaybeifxs:'blist=(mapMaybei'f((Nat_big_num.of_int0))xs)(** [partitionii is xs] returns a pair of lists: firstly those elements in [xs] that are
at indices in [is], and secondly the remaining elements.
It preserves the order of elements in xs. *)(*val partitionii' : forall 'a. natural -> list natural -> list 'a
-> list (natural * 'a) (* accumulates the 'in' partition *)
-> list (natural * 'a) (* accumulates the 'out' partition *)
-> (list (natural * 'a) * list (natural * 'a))*)letrecpartitionii'(offset:Nat_big_num.num)sorted_isxsreverse_accumreverse_accum_compl:(Nat_big_num.num*'a)list*(Nat_big_num.num*'a)list=((* offset o means "xs begins at index o, as reckoned by the indices in sorted_is" *)(matchsorted_iswith[]->(List.revreverse_accum,List.revreverse_accum_compl)|i::more_is->let(length_to_split_off:int)=(Nat_big_num.to_int(Nat_big_num.sub_natioffset))inlet(left,right)=(Lem_list.split_atlength_to_split_offxs)inletleft_indices:Nat_big_num.numlist=(Lem_list.genlist(funj->Nat_big_num.add(Nat_big_num.of_intj)offset)(List.lengthleft))inletleft_with_indices=(list_combineleft_indicesleft)in(* left begins at offset, right begins at offset + i *)(matchrightwith[]->(* We got to the end of the list before the target index. *)(List.revreverse_accum,List.rev_appendreverse_accum_complleft_with_indices)|x::more_xs->(* x is at index i by definition, so more_xs starts with index i + 1 *)partitionii'(Nat_big_num.addi((Nat_big_num.of_int1)))more_ismore_xs((i,x)::reverse_accum)(List.rev_appendleft_with_indicesreverse_accum_compl))))(*val filteri : forall 'a. list natural -> list 'a -> list 'a*)letfilteriisxs:'alist=(letsorted_is=(List.sortNat_big_num.compareis)inlet(accum,accum_compl)=(partitionii'((Nat_big_num.of_int0))sorted_isxs[][])inlet(just_indices,just_items)=(List.splitaccum)injust_items)(*val filterii : forall 'a. list natural -> list 'a -> list (natural * 'a)*)letfilteriiisxs:(Nat_big_num.num*'a)list=(letsorted_is=(List.sortNat_big_num.compareis)inlet(accum,accum_compl)=(partitionii'((Nat_big_num.of_int0))sorted_isxs[][])inaccum)(*val partitioni : forall 'a. list natural -> list 'a -> (list 'a * list 'a)*)letpartitioniisxs:'alist*'alist=(letsorted_is=(List.sortNat_big_num.compareis)inlet(accum,accum_compl)=(partitionii'((Nat_big_num.of_int0))sorted_isxs[][])inlet(just_indices,just_items)=(List.splitaccum)inlet(just_indices_compl,just_items_compl)=(List.splitaccum_compl)in(just_items,just_items_compl))(*val partitionii : forall 'a. list natural -> list 'a -> (list (natural * 'a) * list (natural * 'a))*)letpartitioniiisxs:(Nat_big_num.num*'a)list*(Nat_big_num.num*'a)list=(letsorted_is=(List.sortNat_big_num.compareis)inpartitionii'((Nat_big_num.of_int0))sorted_isxs[][])(** [unzip3 ls] takes a list of triples and returns a triple of lists. *)(*val unzip3: forall 'a 'b 'c. list ('a * 'b * 'c) -> (list 'a * list 'b * list 'c)*)letrecunzip3l:'alist*'blist*'clist=((matchlwith|[]->([],[],[])|(x,y,z)::xyzs->let(xs,ys,zs)=(unzip3xyzs)in((x::xs),(y::ys),(z::zs))))(** [zip3 ls] takes a triple of lists and returns a list of triples. *)(*val zip3: forall 'a 'b 'c. list 'a -> list 'b -> list 'c -> list ('a * 'b * 'c)*)letreczip3alistblistclist:('a*'b*'c)list=((match(alist,blist,clist)with|([],[],[])->[]|(x::morex,y::morey,z::morez)->letmore_xyz=(zip3morexmoreymorez)in(x,y,z)::more_xyz))(** [null_byte] is the null character a a byte. *)(*val null_byte : byte*)(** [null_char] is the null character. *)(*val null_char : char*)letnull_char:char=('\000')(** [println s] prints [s] to stdout, adding a trailing newline. *)(* val println : string -> unit *)(* declare ocaml target_rep function println = `print_endline` *)(** [prints s] prints [s] to stdout, without adding a trailing newline. *)(* val prints : string -> unit *)(* declare ocaml target_rep function prints = `print_string` *)(** [errln s] prints [s] to stderr, adding a trailing newline. *)(*val errln : string -> unit*)(** [errs s] prints [s] to stderr, without adding a trailing newline. *)(*val errs : string -> unit*)(** [outln s] prints [s] to stdout, adding a trailing newline. *)(*val outln : string -> unit*)(** [outs s] prints [s] to stdout, without adding a trailing newline. *)(*val outs : string -> unit*)(** [intercalate sep xs] places [sep] between all elements of [xs].
* Made tail recursive and unrolled slightly to improve performance on large
* lists.*)(*val intercalate' : forall 'a. 'a -> list 'a -> list 'a -> list 'a*)letrecintercalate'sepxsaccum:'alist=((matchxswith|[]->List.revaccum|[x]->List.rev_append(List.rev(List.revaccum))[x]|[x;y]->List.rev_append(List.rev(List.revaccum))[x;sep;y]|x::y::xs->intercalate'sepxs(sep::(y::(sep::(x::accum))))))(*val intercalate : forall 'a. 'a -> list 'a -> list 'a*)letintercalatesepxs:'alist=(intercalate'sepxs[])(** [unlines xs] concatenates a list of strings [xs], placing each entry
* on a new line.
*)(*val unlines : list string -> string*)letunlinesxs:string=(List.fold_left(^)""(intercalate"\n"xs))(** [bracket xs] concatenates a list of strings [xs], separating each entry with a
* space, and bracketing the resulting string.
*)(*val bracket : list string -> string*)letbracketxs:string=("("^(List.fold_left(^)""(intercalate" "xs)^")"))(** [string_of_list l] produces a string representation of list [l].
*)(*val string_of_list : forall 'a. Show 'a => list 'a -> string*)letstring_of_listdict_Show_Show_al:string=(letresult=(intercalate","(Lem_list.mapdict_Show_Show_a.show_methodl))inletfolded=(List.fold_left(^)""result)in"["^(folded^"]"))letinstance_Show_Show_list_dictdict_Show_Show_a:('alist)show_class=({show_method=(string_of_listdict_Show_Show_a)})(** [split_string_on_char s c] splits a string [s] into a list of substrings
* on character [c], otherwise returning the singleton list containing [s]
* if [c] is not found in [s].
*
* NOTE: quirkily, this doesn't discard separators (e.g. because NUL characters
* are significant when indexing into string tables). FIXME: given this, is this
* function really reusable? I suspect not.
*)(*val split_string_on_char : string -> char -> list string*)(* [find_substring sub s] returns the index at which *)(*val find_substring : string -> string -> maybe natural*)(*val string_contains : string -> string -> bool*)letstring_containsssubstr:bool=(not((Lem.option_equalNat_big_num.equal(Ml_bindings.find_substringsubstrs)None)))(*val string_replace : string -> string -> string -> string*)(** [string_of_nat m] produces a string representation of natural number [m]. *)(*val string_of_nat : nat -> string*)(** [string_suffix i s] returns all but the first [i] characters of [s].
* Fails if the index is negative, or beyond the end of the string.
*)(*val string_suffix : natural -> string -> maybe string*)(*val nat_length : forall 'a. list 'a -> nat*)(*val length : forall 'a. list 'a -> natural*)letlengthxs:Nat_big_num.num=(Nat_big_num.of_int(List.lengthxs))(*val takeRevAcc : forall 'a. natural -> list 'a -> list 'a -> list 'a*)letrectakeRevAccmxsrev_acc:'alist=((matchxswith|[]->List.revrev_acc|x::xs->ifNat_big_num.equalm((Nat_big_num.of_int0))thenList.revrev_accelsetakeRevAcc(Nat_big_num.sub_natm((Nat_big_num.of_int1)))xs(x::rev_acc)))(** [take cnt xs] takes the first [cnt] elements of list [xs]. Returns a truncation
* if [cnt] is greater than the length of [xs].
*)(*val take : forall 'a. natural -> list 'a -> list 'a*)letrectake0mxs:'alist=(takeRevAccmxs[])(** [drop cnt xs] returns all but the first [cnt] elements of list [xs]. Returns an empty list
* if [cnt] is greater than the length of [xs].
*)(*val drop : forall 'a. natural -> list 'a -> list 'a*)letrecdrop0mxs:'alist=((matchxswith|[]->[]|x::xs->ifNat_big_num.equalm((Nat_big_num.of_int0))thenx::xselsedrop0(Nat_big_num.sub_natm((Nat_big_num.of_int1)))xs))(** [string_prefix i s] returns the first [i] characters of [s].
* Fails if the index is negative, or beyond the end of the string.
*)(*val string_prefix : natural -> string -> maybe string*)(*let string_prefix m s:maybe(string)=
let cs = String.toCharList s in
if (Instance_Basic_classes_Ord_Num_natural.>) m (length cs) then
Nothing
else
Just (String.toString (take m cs))*)(* FIXME: isabelle *)(** [string_index_of c s] returns [Just(i)] where [i] is the index of the first
* occurrence if [c] in [s], if it exists, otherwise returns [Nothing]. *)(*val string_index_of' : char -> list char -> natural -> maybe natural*)letrecstring_index_of'essidx1:(Nat_big_num.num)option=((matchsswith|[]->None|s::ss->ifs=ethenSomeidx1elsestring_index_of'ess(Nat_big_num.add((Nat_big_num.of_int1))idx1)))(*val string_index_of : char -> string -> maybe natural*)(*let string_index_of e s:maybe(natural)= string_index_of' e (String.toCharList s) 0*)(*val index : forall 'a. natural -> list 'a -> maybe 'a*)(*let rec index m xs:maybe 'a=
match xs with
| [] -> Nothing
| x::xs ->
if (Instance_Basic_classes_Eq_Num_natural.=) m 0 then
Just x
else
index ((Instance_Num_NumMinus_Num_natural.-) m 1) xs
end*)(*val find_index_helper : forall 'a. natural -> ('a -> bool) -> list 'a -> maybe natural*)letrecfind_index_helpercountpxs:(Nat_big_num.num)option=((matchxswith|[]->None|y::ys->ifpythenSomecountelsefind_index_helper(Nat_big_num.addcount((Nat_big_num.of_int1)))pys))(*val find_index : forall 'a. ('a -> bool) -> list 'a -> maybe natural*)letfind_index0pxs:(Nat_big_num.num)option=(find_index_helper((Nat_big_num.of_int0))pxs)(*val argv : list string*)(*val replicate_revacc : forall 'a. list 'a -> natural -> 'a -> list 'a*)letrecreplicate_revaccrevacclene:'alist=(if(Nat_big_num.equallen((Nat_big_num.of_int0)))then(List.revrevacc)else(replicate_revacc(e::revacc)(Nat_big_num.sub_natlen((Nat_big_num.of_int1)))e))(*val replicate : forall 'a. natural -> 'a -> list 'a*)letrecreplicate0lene:'alist=(replicate_revacc[]lene)(* We want a tail-recursive append. reverse_append l1 l2 appends l2 to the
* reverse of l1. So we get [l1-backwards] [l2]. So just reverse l1. *)(*val list_append : forall 'a. list 'a -> list 'a -> list 'a*)letlist_appendl1l2:'alist=(List.rev_append(List.revl1)l2)(*val list_concat : forall 'a. list (list 'a) -> list 'a*)letlist_concatll:'alist=(List.fold_leftlist_append[]ll)(*val list_concat_map : forall 'a 'b. ('a -> list 'b) -> list 'a -> list 'b*)letlist_concat_mapfl:'blist=(list_concat(Lem_list.mapfl))(*val list_reverse_concat_map_helper : forall 'a 'b. ('a -> list 'b) -> list 'b -> list 'a -> list 'b*)letreclist_reverse_concat_map_helperfaccll:'blist=(letlcons=(funl->(funi->i::l))in(matchllwith|[]->acc|item::items->(* item is a thing that maps to a list. it needn't be a list yet *)letmapped_list=(fitem)in(* let _ = Missing_pervasives.errln ("Map function gave us a list of " ^ (show (List.length mapped_list)) ^ " items") in *)list_reverse_concat_map_helperf(List.fold_leftlconsacc(fitem))items))(*val list_reverse_concat_map : forall 'a 'b. ('a -> list 'b) -> list 'a -> list 'b*)letlist_reverse_concat_mapfll:'blist=(list_reverse_concat_map_helperf[]ll)(*val list_take_with_accum : forall 'a. nat -> list 'a -> list 'a -> list 'a*)letreclist_take_with_accumnreverse_accl:'alist=((* let _ = Missing_pervasives.errs ("Taking a byte; have accumulated " ^ (show (List.length acc) ^ " so far\n"))
in *)(matchnwith0->List.revreverse_acc|_->(matchlwith[]->failwith"list_take_with_accum: not enough elements"|x::xs->list_take_with_accum(Nat_num.nat_monusn1)(x::reverse_acc)xs)))(*val unsafe_string_take : natural -> string -> string*)letunsafe_string_takemstr:string=(letm=(Nat_big_num.to_intm)inXstring.implode(Lem_list.takem(Xstring.explodestr)))(** [padding_and_maybe_newline c w s] creates enough of char [c] to pad string [s] to [w] characters,
* unless [s] is of length [w - 1] or greater, in which case it generates [w] copies preceded by a newline.
* This style of formatting is used by the GNU linker in its link map output, so we
* reproduce it using this function. Note that string [s] does not appear in the
* output. *)(*val padding_and_maybe_newline : char -> natural -> string -> string*)letpadding_and_maybe_newlinecwidthstr:string=(letpadlen=(Nat_big_num.sub_natwidth(Nat_big_num.of_int(String.lengthstr)))in(ifNat_big_num.less_equalpadlen((Nat_big_num.of_int1))then"\n"else"")^(Xstring.implode(replicate0(ifNat_big_num.less_equalpadlen((Nat_big_num.of_int1))thenwidthelsepadlen)c)))(** [space_padding_and_maybe_newline w s] creates enoughspaces to pad string [s] to [w] characters,
* unless [s] is of length [w - 1] or greater, in which case it generates [w] copies preceded by a newline.
* This style of formatting is used by the GNU linker in its link map output, so we
* reproduce it using this function. Note that string [s] does not appear in the
* output. *)(*val space_padding_and_maybe_newline : natural -> string -> string*)letspace_padding_and_maybe_newlinewidthstr:string=(padding_and_maybe_newline' 'widthstr)(** [padded_and_maybe_newline w s] pads string [s] to [w] characters, using char [c]
* unless [s] is of length [w - 1] or greater, in which case the padding consists of
* [w] copies of [c] preceded by a newline.
* This style of formatting is used by the GNU linker in its link map output, so we
* reproduce it using this function. *)(*val padded_and_maybe_newline : char -> natural -> string -> string*)letpadded_and_maybe_newlinecwidthstr:string=(str^(padding_and_maybe_newlinecwidthstr))(** [padding_to c w s] creates enough copies of [c] to pad string [s] to [w] characters,
* or 0 characters if [s] is of length [w] or greater. Note that string [s] does not appear in the
* output. *)(*val padding_to : char -> natural -> string -> string*)letpadding_tocwidthstr:string=(letpadlen=(Nat_big_num.sub_natwidth(Nat_big_num.of_int(String.lengthstr)))inifNat_big_num.less_equalpadlen((Nat_big_num.of_int0))then""else(Xstring.implode(replicate0padlenc)))(** [left_padded_to c w s] left-pads string [s] to [w] characters using [c],
* returning it unchanged if [s] is of length [w] or greater. *)(*val left_padded_to : char -> natural -> string -> string*)letleft_padded_tocwidthstr:string=((padding_tocwidthstr)^str)(** [right_padded_to c w s] right-pads string [s] to [w] characters using [c],
* returning it unchanged if [s] is of length [w] or greater. *)(*val right_padded_to : char -> natural -> string -> string*)letright_padded_tocwidthstr:string=(str^(padding_tocwidthstr))(** [space_padded_and_maybe_newline w s] pads string [s] to [w] characters, using spaces,
* unless [s] is of length [w - 1] or greater, in which case the padding consists of
* [w] spaces preceded by a newline.
* This style of formatting is used by the GNU linker in its link map output, so we
* reproduce it using this function. *)(*val space_padded_and_maybe_newline : natural -> string -> string*)letspace_padded_and_maybe_newlinewidthstr:string=(str^(padding_and_maybe_newline' 'widthstr))(** [left_space_padded_to w s] left-pads string [s] to [w] characters using spaces,
* returning it unchanged if [s] is of length [w] or greater. *)(*val left_space_padded_to : natural -> string -> string*)letleft_space_padded_towidthstr:string=((padding_to' 'widthstr)^str)(** [right_space_padded_to w s] right-pads string [s] to [w] characters using spaces,
* returning it unchanged if [s] is of length [w] or greater. *)(*val right_space_padded_to : natural -> string -> string*)letright_space_padded_towidthstr:string=(str^(padding_to' 'widthstr))(** [left_zero_padded_to w s] left-pads string [s] to [w] characters using zeroes,
* returning it unchanged if [s] is of length [w] or greater. *)(*val left_zero_padded_to : natural -> string -> string*)letleft_zero_padded_towidthstr:string=((padding_to'0'widthstr)^str)(** hex parsing *)(*val natural_of_char : char -> natural*)letnatural_of_charc:Nat_big_num.num=(letnaturalOrdc'=(Nat_big_num.of_int(Char.codec'))inletn=(naturalOrdc)inifNat_big_num.greater_equaln(naturalOrd'0')&&Nat_big_num.less_equaln(naturalOrd'9')thenNat_big_num.sub_natn(naturalOrd'0')elseifNat_big_num.greater_equaln(naturalOrd'A')&&Nat_big_num.less_equaln(naturalOrd'F')thenNat_big_num.add(Nat_big_num.sub_natn(naturalOrd'A'))((Nat_big_num.of_int10))elseifNat_big_num.greater_equaln(naturalOrd'a')&&Nat_big_num.less_equaln(naturalOrd'f')thenNat_big_num.add(Nat_big_num.sub_natn(naturalOrd'a'))((Nat_big_num.of_int10))elsefailwith("natural_of_char argument #'"^(Xstring.implode[c]^"' not in 0-9,A-F,a-f")))(*val natural_of_hex' : list char -> natural*)letrecnatural_of_hex'cs:Nat_big_num.num=((matchcswith|c::cs'->Nat_big_num.add(natural_of_charc)(Nat_big_num.mul((Nat_big_num.of_int16))(natural_of_hex'cs'))|[]->(Nat_big_num.of_int0)))(*val natural_of_hex : string -> natural*)letnatural_of_hexs:Nat_big_num.num=(letcs=(Xstring.explodes)in(matchcswith|'0'::'x'::cs'->(matchcs'with|c::_->natural_of_hex'(List.revcs')|[]->failwith("natural_of_hex argument \""^(s^"\" has no digits")))|_->failwith("natural_of_hex argument \""^(s^"\" does not begin 0x"))))letassert_unwrap_maybemaybe1:'a=((matchmaybe1with|Somev->v|None->failwith"assert_unwrap_maybe: nothing"))