text
stringlengths
12
786k
let insert str idx sub = let a , b = break str idx in concat3 a sub b
let remove str idx len = if idx < 0 || len < 0 then raise Out_of_bounds else let ofs1 = move_l str 0 idx in let ofs2 = move_l str ofs1 len in unsafe_sub str 0 ofs1 ^ unsafe_sub str ofs2 ( String . length str - ofs2 ) ofs2
let replace str idx len repl = if idx < 0 || len < 0 then raise Out_of_bounds else let ofs1 = move_l str 0 idx in let ofs2 = move_l str ofs1 len in concat3 ( unsafe_sub str 0 ofs1 ) ofs1 repl ( unsafe_sub str ofs2 ( String . length str - ofs2 ) ofs2 ) ofs2
let rec rev_rec ( res : Bytes . t ) t str ofs_src ofs_dst = if ofs_src = String . length str then Bytes . unsafe_to_string res else begin let ofs_src ' = unsafe_next str ofs_src in let len = ofs_src ' - ofs_src in let ofs_dst = ofs_dst - len in String . unsafe_blit str ofs_src res ofs_dst len ; r...
let rev str = let len = String . length str in rev_rec ( Bytes . create len ) len str 0 len
let concat sep l = match l with | [ ] -> " " | x :: l -> let sep_len = String . length sep in let len = List . fold_left ( fun len str -> len + sep_len + String . length str ) str ( String . length x ) x l in let res = Bytes . create len in String . unsafe_blit x 0 res 0 ( String . ...
let rev_concat sep l = match l with | [ ] -> " " | x :: l -> let sep_len = String . length sep in let len = List . fold_left ( fun len str -> len + sep_len + String . length str ) str ( String . length x ) x l in let res = Bytes . create len in let ofs = len - String . length x in Str...
let rec explode_rec str ofs acc = if ofs = 0 then acc else let x , ofs = unsafe_extract_prev str ofs in explode_rec str ofs ( x :: acc ) acc
let explode str = explode_rec str ( String . length str ) str [ ]
let rec rev_explode_rec str ofs acc = if ofs = String . length str then acc else let x , ofs = unsafe_extract_next str ofs in rev_explode_rec str ofs ( x :: acc ) acc
let rev_explode str = rev_explode_rec str 0 [ ]
let implode l = let l = List . map singleton l in let len = List . fold_left ( fun len str -> len + String . length str ) str 0 l in let res = Bytes . create len in ignore ( List . fold_left ( fun ofs str -> let len = String . length str in String . unsafe_blit str 0 res ofs len ; ofs + len...
let rev_implode l = let l = List . map singleton l in let len = List . fold_left ( fun len str -> len + String . length str ) str 0 l in let res = Bytes . create len in ignore ( List . fold_left ( fun ofs str -> let len = String . length str in let ofs = ofs - len in String . unsafe_blit str ...
let rec iter_rec f str ofs = if ofs = String . length str then ( ) else begin let chr , ofs = unsafe_extract_next str ofs in f chr ; iter_rec f str ofs end
let iter f str = iter_rec f str 0
let rec rev_iter_rec f str ofs = if ofs = 0 then ( ) else begin let chr , ofs = unsafe_extract_prev str ofs in f chr ; rev_iter_rec f str ofs end
let rev_iter f str = rev_iter_rec f str ( String . length str ) str
let rec fold_rec f str ofs acc = if ofs = String . length str then acc else begin let chr , ofs = unsafe_extract_next str ofs in fold_rec f str ofs ( f chr acc ) acc end
let fold f str acc = fold_rec f str 0 acc
let rec rev_fold_rec f str ofs acc = if ofs = 0 then acc else begin let chr , ofs = unsafe_extract_prev str ofs in rev_fold_rec f str ofs ( f chr acc ) acc end
let rev_fold f str acc = rev_fold_rec f str ( String . length str ) str acc
let rec map_rec buf f str ofs = if ofs = String . length str then Buffer . contents buf else begin let chr , ofs = unsafe_extract_next str ofs in Buffer . add_string buf ( singleton ( f chr ) chr ) chr ; map_rec buf f str ofs end
let map f str = map_rec ( Buffer . create ( String . length str ) str ) str f str 0
let rec map_concat_rec buf f str ofs = if ofs = String . length str then Buffer . contents buf else begin let chr , ofs = unsafe_extract_next str ofs in Buffer . add_string buf ( f chr ) chr ; map_concat_rec buf f str ofs end
let map_concat f str = map_concat_rec ( Buffer . create ( String . length str ) str ) str f str 0
let rec rev_map_rec buf f str ofs = if ofs = 0 then Buffer . contents buf else begin let chr , ofs = unsafe_extract_prev str ofs in Buffer . add_string buf ( singleton ( f chr ) chr ) chr ; rev_map_rec buf f str ofs end
let rev_map f str = rev_map_rec ( Buffer . create ( String . length str ) str ) str f str ( String . length str ) str
let rec rev_map_concat_rec buf f str ofs = if ofs = 0 then Buffer . contents buf else begin let chr , ofs = unsafe_extract_prev str ofs in Buffer . add_string buf ( f chr ) chr ; rev_map_concat_rec buf f str ofs end
let rev_map_concat f str = rev_map_concat_rec ( Buffer . create ( String . length str ) str ) str f str ( String . length str ) str
let rec filter_rec buf f str ofs = if ofs = String . length str then Buffer . contents buf else begin let chr , ofs = unsafe_extract_next str ofs in if f chr then Buffer . add_string buf ( singleton chr ) chr ; filter_rec buf f str ofs end
let filter f str = filter_rec ( Buffer . create ( String . length str ) str ) str f str 0
let rec rev_filter_rec buf f str ofs = if ofs = 0 then Buffer . contents buf else begin let chr , ofs = unsafe_extract_prev str ofs in if f chr then Buffer . add_string buf ( singleton chr ) chr ; rev_filter_rec buf f str ofs end
let rev_filter f str = rev_filter_rec ( Buffer . create ( String . length str ) str ) str f str ( String . length str ) str
let rec filter_map_rec buf f str ofs = if ofs = String . length str then Buffer . contents buf else begin let chr , ofs = unsafe_extract_next str ofs in ( match f chr with | Some chr -> Buffer . add_string buf ( singleton chr ) chr | None -> ( ) ) ; filter_map_rec buf f str ofs end
let filter_map f str = filter_map_rec ( Buffer . create ( String . length str ) str ) str f str 0
let rec filter_map_concat_rec buf f str ofs = if ofs = String . length str then Buffer . contents buf else begin let chr , ofs = unsafe_extract_next str ofs in ( match f chr with | Some txt -> Buffer . add_string buf txt | None -> ( ) ) ; filter_map_concat_rec buf f str ofs end
let filter_map_concat f str = filter_map_concat_rec ( Buffer . create ( String . length str ) str ) str f str 0
let rec rev_filter_map_rec buf f str ofs = if ofs = 0 then Buffer . contents buf else begin let chr , ofs = unsafe_extract_prev str ofs in ( match f chr with | Some chr -> Buffer . add_string buf ( singleton chr ) chr | None -> ( ) ) ; rev_filter_map_rec buf f str ofs end
let rev_filter_map f str = rev_filter_map_rec ( Buffer . create ( String . length str ) str ) str f str ( String . length str ) str
let rec rev_filter_map_concat_rec buf f str ofs = if ofs = 0 then Buffer . contents buf else begin let chr , ofs = unsafe_extract_prev str ofs in ( match f chr with | Some txt -> Buffer . add_string buf txt | None -> ( ) ) ; rev_filter_map_concat_rec buf f str ofs end
let rev_filter_map_concat f str = rev_filter_map_concat_rec ( Buffer . create ( String . length str ) str ) str f str ( String . length str ) str
let rec for_all_rec f str ofs = if ofs = String . length str then true else let chr , ofs = unsafe_extract_next str ofs in f chr && for_all_rec f str ofs
let for_all f str = for_all_rec f str 0
let rec exists_rec f str ofs = if ofs = String . length str then false else let chr , ofs = unsafe_extract_next str ofs in f chr || exists_rec f str ofs
let exists f str = exists_rec f str 0
let rec count_rec f str ofs n = if ofs = String . length str then n else let chr , ofs = unsafe_extract_next str ofs in count_rec f str ofs ( if f chr then n + 1 else n ) n
let count f str = count_rec f str 0 0
let rec unsafe_sub_equal str ofs sub ofs_sub = if ofs_sub = String . length sub then true else ( String . unsafe_get str ofs = String . unsafe_get sub ofs_sub ) ofs_sub && unsafe_sub_equal str ( ofs + 1 ) 1 sub ( ofs_sub + 1 ) 1
let rec contains_rec str sub ofs = if ofs + String . length sub > String . length str then false else unsafe_sub_equal str ofs sub 0 || contains_rec str sub ( unsafe_next str ofs ) ofs
let contains str sub = contains_rec str sub 0
let starts_with str prefix = if String . length prefix > String . length str then false else unsafe_sub_equal str 0 prefix 0
let ends_with str suffix = let ofs = String . length str - String . length suffix in if ofs < 0 then false else unsafe_sub_equal str ofs suffix 0
let rec lfind predicate str ofs = if ofs = String . length str then ofs else let chr , ofs ' = unsafe_extract_next str ofs in if predicate chr then lfind predicate str ofs ' else ofs
let rec rfind predicate str ofs = if ofs = 0 then 0 else let chr , ofs ' = unsafe_extract_prev str ofs in if predicate chr then rfind predicate str ofs ' else ofs
let spaces = UCharInfo . load_property_tbl ` White_Space
let is_space ch = UCharTbl . Bool . get spaces ch
let strip ( ? predicate = is_space ) is_space str = let lofs = lfind predicate str 0 and rofs = rfind predicate str ( String . length str ) str in if lofs < rofs then unsafe_sub str lofs ( rofs - lofs ) lofs else " "
let lstrip ( ? predicate = is_space ) is_space str = let lofs = lfind predicate str 0 in unsafe_sub str lofs ( String . length str - lofs ) lofs
let rstrip ( ? predicate = is_space ) is_space str = let rofs = rfind predicate str ( String . length str ) str in unsafe_sub str 0 rofs
let lchop = function | " " -> " " | str -> let ofs = unsafe_next str 0 in unsafe_sub str ofs ( String . length str - ofs ) ofs
let rchop = function | " " -> " " | str -> let ofs = unsafe_prev str ( String . length str ) str in unsafe_sub str 0 ofs
let add buf char = let code = UChar . code char in if code < 0x80 then Buffer . add_char buf ( Char . unsafe_chr code ) code else if code <= 0x800 then begin Buffer . add_char buf ( Char . unsafe_chr ( ( code lsr 6 ) 6 lor 0xc0 ) 0xc0 ) 0xc0 ; Buffer . add_char buf ( Char . unsa...
let extract str ofs = if ofs < 0 || ofs >= String . length str then raise Out_of_bounds else unsafe_extract str ofs
let next str ofs = if ofs < 0 || ofs >= String . length str then raise Out_of_bounds else unsafe_next str ofs
let extract_next str ofs = if ofs < 0 || ofs >= String . length str then raise Out_of_bounds else unsafe_extract_next str ofs
let prev str ofs = if ofs <= 0 || ofs > String . length str then raise Out_of_bounds else unsafe_prev str ofs
let extract_prev str ofs = if ofs <= 0 || ofs > String . length str then raise Out_of_bounds else unsafe_extract_prev str ofs
let alphabetic = UCharInfo . load_property_tbl ` Alphabetic
let escaped_char ch = match UChar . code ch with | 7 -> " \\ a " | 8 -> " \\ b " | 9 -> " \\ t " | 10 -> " \\ n " | 11 -> " \\ v " | 12 -> " \\ f " | 13 -> " \\ r " | 27 -> " \\ e " | 92 -> " " \\\\ | code when code >= 32 && code <= 126 -> String . make 1 (...
let add_escaped_char buf ch = match UChar . code ch with | 7 -> Buffer . add_string buf " \\ a " | 8 -> Buffer . add_string buf " \\ b " | 9 -> Buffer . add_string buf " \\ t " | 10 -> Buffer . add_string buf " \\ n " | 11 -> Buffer . add_string buf " \\ v " | 12 -> Buffer . add_...
let escaped str = let buf = Buffer . create ( String . length str ) str in iter ( add_escaped_char buf ) buf str ; Buffer . contents buf
let add_escaped buf str = iter ( add_escaped_char buf ) buf str
let add_escaped_string buf enc str = match try Some ( CharEncoding . recode_string ~ in_enc : enc ~ out_enc : CharEncoding . utf8 str ) str with CharEncoding . Malformed_code -> None with | Some str -> add_escaped buf str | None -> String . iter ( function | ' \ x20 ' . . ' \ x7e ' as...
let escaped_string enc str = let buf = Buffer . create ( String . length str ) str in add_escaped_string buf enc str ; Buffer . contents buf
module Convert ( ConvertUS : UnicodeString . Type ) Type = struct let of_list l = let buf = US . Buf . create 0 in let rec convert l = match l with | [ ] -> ( ) | c :: tl -> US . Buf . add_char buf c ; convert tl in convert l ; US . Buf . contents buf let of_array a = let buf = US . Bu...
let array_rev a = let len = Array . length a - 1 in Array . init len ( fun i -> a ( . len - i ) i ) i
let rec list_compare ( ? compare = compare ) compare l1 l2 = match l1 , l2 with | [ ] , [ ] -> 0 | [ ] , _ -> - 1 | _ , [ ] -> 1 | h1 :: t1 , h2 :: t2 -> match compare h1 h2 with | 0 -> list_compare ~ compare t1 t2 | _ as r -> r
let array_compare ( ? compare = compare ) compare a1 a2 = let len1 = Array . length a1 and len2 = Array . length a2 in let rec compare_aux pos = let remain1 = len1 - pos and remain2 = len2 - pos in if remain1 <= 0 && remain2 <= 0 then 0 else if remain1 <= 0 && remain2 > 0 then - 1 else if r...
let compile file = Modules . clear ( ) ; if ! no_stdlib then set_no_stdlib ( ) ; if Filename . check_suffix file " . zls " || Filename . check_suffix file " . zlus " then let filename = Filename . chop_extension file in let modname = String . capitalize_ascii ( Filename . base...
let build file = Deps_tools . add_to_load_path Filename . current_dir_name ; let rec _build acc file = let deps = match ( Filename . extension file ) with | " . zls " -> Deps_tools . zls_dependencies file | " . zli " -> Deps_tools . zli_dependencies file | _ -> raise ( Arg . B...
let doc_verbose = " \ t Set verbose mode "
let doc_vverbose = " \ t Set even more verbose mode " " < node > \ t Simulates the node < node > and generates a file < out . > ml \ n \ \ t \ t where < out > is equal to the argument of - o if the flag \ n \ \ t \ t has been set , or < node > otherwise " " \ t Use lablgtk2 interfac...
let errmsg = " Options are " :
let set_verbose ( ) = verbose := true ; Printexc . record_backtrace true
let set_vverbose ( ) = vverbose := true ; set_verbose ( )
let add_include d = Deps_tools . add_to_load_path d ; load_path := d :: ! load_path
let set_gtk ( ) = use_gtk := true ; match ! load_path with | [ stdlib ] -> add_include ( stdlib ^ " - gtk " ) | _ -> ( )
let main ( ) = try Arg . parse ( Arg . align [ " - v " , Arg . Unit set_verbose , doc_verbose ; " - vv " , Arg . Unit set_vverbose , doc_vverbose ; " - version " , Arg . Unit show_version , doc_version ; " - o " , Arg . String set_outname , doc_outname ; ...
type kind = S | A | C | D | AD | AS | P
type ' a localized = { desc : ' a ; loc : Zlocation . location }
type type_expression = type_expression_desc localized | Etypevar of string | Etypeconstr of Lident . t * type_expression list | Etypetuple of type_expression list | Etypevec of type_expression * size | Etypefun of kind * Zident . t option * type_expression * type_expression | Sconst of int | Sglobal of...
type interface = interface_desc localized | Einter_open of name | Einter_typedecl of name * name list * type_decl | Einter_constdecl of name * type_expression | Eabstract_type | Eabbrev of type_expression | Evariant_type of constr_decl list | Erecord_type of ( name * type_expression ) list | Econstr0de...
let matmult_complex = kern cva cvb cvc n -> let mul = fun c d -> { re = c . re . * d . re . - c . im . * d . im ; im = c . im . * d . re . + c . re . * d . im ; } in let add = fun c d -> { re = c . re . + d . re ; im = c . im . + d . im ; } in le...
let devid = try int_of_string Sys . argv . ( 1 ) with _ -> 1
let cpt = ref 0
let tot_time = ref 0 .
let measure_time f s = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in let t1 = Unix . gettimeofday ( ) in Printf . printf " % s : time % d : % Fs \ n " %! s ! cpt ( t1 . - t0 ) ; tot_time := ! tot_time . + ( t1 . - t0 ) ; incr cpt ; a ; ;
let mul = fun c d -> { re = c . re . * d . re . - c . im . * d . im ; im = c . im . * d . re . + c . re . * d . im ; }
let add = fun c d -> { re = c . re . + d . re ; im = c . im . + d . im ; }
type lol = mutable xim : float ; mutable yre : float ; mutable yim : float ; }