text
stringlengths
12
786k
let sec_part ~ regexp line = Str . string_match ( Str . regexp regexp ) line 0
let sec_start = sec_part ~ regexp " : " *=+
let sec_end = sec_part ~ regexp " ( :-+\\|\\ Nothing else to report in this section ) " \\
let errors = ref 0
let error ~ why ~ where ( ) = incr errors ; prerr_string " \ x1b [ 0 ; 31m " ; prerr_string where ; prerr_string " : \ x1b [ 0 ; 37 ; 41m " ; prerr_string why ; prerr_string " \ x1b [ 0m " |> prerr_newline
let total = ref 0
let comp = ref " "
let nextl = ref " "
let fnames = ref [ ]
let dir = ref " "
let res = ref ( open_in_gen [ Open_creat ] 777 " trash . out " )
let fn = ref None
let in_file = ref ! res
let old_fn = ref None
let extend = ref " "
let normalize fname = let rec block fname pos len = if pos = String . length fname || fname . [ pos ] = ' ' / then String . sub fname ( pos - len ) len else block fname ( pos + 1 ) ( len + 1 ) in let rec normalize acc fname pos = if pos = String . length fname then acc else let blk = block fname pos 0 in if blk = " " || blk = " . " then normalize acc fname ( pos + 1 ) else normalize ( acc ^ " " / ^ blk ) fname ( pos + String . length blk ) in normalize " . " fname 0
let rec empty file = try let where = input_line file in if where <> " " then ( error ~ why " : Not detected " ~ where ( ) ; incr total ) ; empty file with _ -> close_in file
let rec empty_fnames ( ? regexp = " . " ) * threshold = function | e :: l -> let extension s = let tmp = Filename . chop_extension s in String . sub s ( String . length tmp ) ( String . length s - String . length tmp ) in if ( try extension e <= extension threshold with _ -> true ) && get_element ~ regexp ~ start : 0 e < threshold then ( empty @@ open_in e ; empty_fnames ~ regexp threshold l ) else e :: l | _ -> [ ]
let is_trash diff eq = let tmp = open_in " trash . out " in if ! in_file <> tmp then ( close_in tmp ; diff ( ) ) else eq
let rec check_fn name line = let ok = match ! fn with | None -> begin match ! old_fn with | Some str when str = name -> decr total ; error ~ why " : Should not be detected " ~ where : line ( ) ; nextl := " " ; false | _ -> fn := Some name ; let name = normalize ( ! dir ^ name ) in if ( try Filename . chop_extension name >= Filename . chop_extension ( List . hd ! fnames ) with _ -> false ) then fnames := List . tl ( empty_fnames name ! fnames ) ; try empty ! in_file ; in_file := open_in name ; true with _ -> error ~ why " : File not found or cannot be opened . " ~ where : name ( ) ; fn := None ; nextl := " " ; false end | Some str when str = name -> is_trash ( fun ( ) -> true ) false | _ -> if in_channel_length ! in_file - 1 <= pos_in ! in_file then true else begin empty ! in_file ; old_fn := ! fn ; fn := None ; false end in if ok then try input_line ! in_file with End_of_file -> close_in ! in_file ; old_fn := ! fn ; fn := None ; check_fn name line else " "
let check_elt ~ f line x = compare x @@ f line
let check_aux line status = if status > 0 then ( error ~ why ( " : Not detected " ) ~ where : line ( ) ; comp := " " ; false ) else if status < 0 then ( decr total ; error ~ why ( " : Should not be detected " ) ~ where :! nextl ( ) ; nextl := " " ; false ) else true
let check_value line x = check_elt ~ f : get_info line x |> check_aux line
let check_pos line pos = check_elt ~ f : get_pos line pos |> check_aux line
let check_info line info = if ( check_elt ~ f : get_info line info ) <> 0 then ( error ~ why ( " : Expected " : ^ ( get_info line ) ) ~ where :! nextl ( ) ; nextl := " " ; comp := " " ; false ) else true
let rec section ( ? path = true ) ( ? pos = true ) ( ? value = false ) ( ? info = true ) ( ) = try if ! nextl = " " then ( nextl := input_line ! res ; section ~ path ~ pos ~ value ~ info ( ) ) else if sec_start ! nextl then ( nextl := " " ; comp := " " ; section ~ path ~ pos ~ value ~ info ( ) ) else if sec_end ! nextl then ( is_trash ( fun ( ) -> empty ! in_file ) ( ) ; print_string ! nextl ; print_string " \ n \ n \ n " ; nextl := " " ) else if ! comp <> " " && normalize ( get_path ! comp ) <> normalize ( get_path ! nextl ) then begin empty ! in_file ; comp := " " ; old_fn := ! fn ; fn := None ; section ~ path ~ pos ~ value ~ info ( ) end else begin incr total ; comp := if path && ! comp = " " then ( ( Filename . chop_extension @@ get_path ! nextl ) ^ ! extend |> check_fn ) ! nextl else ! comp ; if not path || ! comp <> " " then if not ( ( pos && not @@ check_pos ! comp @@ get_pos ! nextl ) || ( value && not @@ check_value ! comp @@ get_info ! nextl ) || ( info && not @@ check_info ! comp @@ get_info ! nextl ) ) then ( print_endline ! nextl ; nextl := " " ; comp := " " ) ; section ~ path ~ pos ~ value ~ info ( ) end with End_of_file -> is_trash ( fun ( ) -> empty ! in_file ) ( )
let rec sel_section ( ) = fn := None ; old_fn := None ; nextl := " " ; comp := " " ; try match ( input_line ! res ) with | " . > UNUSED EXPORTED VALUES " : as s -> ( try fnames := empty_fnames ~ regexp " . :\\ ml [ a - z0 - 9 ] " *$ " . mli " ! fnames with _ -> ( ) ) ; print_endline s ; print_endline ( input_line ! res ) ; extend := " . mli " ; sel_section ( section ( ) ) | " . > UNUSED METHODS " : as s -> ( try fnames := empty_fnames ~ regexp " . :\\ ml [ a - z0 - 9 ] " *$ " . mlio " ! fnames with _ -> ( ) ) ; print_endline s ; print_endline ( input_line ! res ) ; extend := " . mlio " ; sel_section ( section ( ) ) | " . > UNUSED CONSTRUCTORS / RECORD FIELDS " : as s -> ( try fnames := empty_fnames ~ regexp " . :\\ ml [ a - z0 - 9 ] " *$ " . mlit " ! fnames with _ -> ( ) ) ; print_endline s ; print_endline ( input_line ! res ) ; extend := " . mlit " ; sel_section ( section ( ) ) | " . > OPTIONAL ARGUMENTS : ALWAYS " : as s -> ( try fnames := empty_fnames ~ regexp " . :\\ ml [ a - z0 - 9 ] " *$ " . mlopta " ! fnames with _ -> ( ) ) ; print_endline s ; print_endline ( input_line ! res ) ; extend := " . mlopta " ; sel_section ( section ~ value : true ~ info : false ( ) ) | " . > OPTIONAL ARGUMENTS : NEVER " : as s -> ( try fnames := empty_fnames ~ regexp " . :\\ ml [ a - z0 - 9 ] " *$ " . mloptn " ! fnames with _ -> ( ) ) ; print_endline s ; print_endline ( input_line ! res ) ; extend := " . mloptn " ; sel_section ( section ~ value : true ~ info : false ( ) ) | " . > CODING STYLE " : as s -> ( try fnames := empty_fnames ~ regexp " . :\\ ml [ a - z0 - 9 ] " *$ " . mlstyle " ! fnames with _ -> ( ) ) ; print_endline s ; print_endline ( input_line ! res ) ; extend := " . mlstyle " ; sel_section ( section ( ) ) | s when String . length s > 36 && String . sub s 0 36 = " . >-> ALMOST UNUSED EXPORTED VALUES " : -> let n = Scanf . sscanf s " . >-> ALMOST UNUSED EXPORTED VALUES : Called % s time ( s ) " ( fun n -> n ) in begin try fnames := empty_fnames ~ regexp " . :\\ ml [ a - z0 - 9 ] " *$ ( " . mli " ^ n ) ! fnames with _ -> ( ) end ; print_endline s ; print_endline ( input_line ! res ) ; extend := " . mli " ^ n ; sel_section ( section ( ) ) | s when String . length s > 33 && String . sub s 0 28 = " . >-> ALMOST UNUSED METHODS " : -> let n = Scanf . sscanf s " . >-> ALMOST UNUSED METHODS : Called % s time ( s ) " ( fun n -> n ) in begin try fnames := empty_fnames ~ regexp " . :\\ ml [ a - z0 - 9 ] " *$ ( " . mlio " ^ n ) ! fnames with _ -> ( ) end ; print_endline s ; print_endline ( input_line ! res ) ; extend := " . mlio " ^ n ; sel_section ( section ( ) ) | s when String . length s > 55 && String . sub s 0 47 = " . >-> ALMOST UNUSED CONSTRUCTORS / RECORD FIELDS " : -> let n = Scanf . sscanf s " . >-> ALMOST UNUSED CONSTRUCTORS / RECORD FIELDS : Called % s time ( s ) " ( fun n -> n ) in begin try fnames := empty_fnames ~ regexp " . :\\ ml [ a - z0 - 9 ] " *$ ( " . mlit " ^ n ) ! fnames with _ -> ( ) end ; print_endline s ; print_endline ( input_line ! res ) ; extend := " . mlit " ^ n ; sel_section ( section ( ) ) | s when String . length s > 40 && String . sub s 0 40 = " . >-> OPTIONAL ARGUMENTS : ALMOST ALWAYS " : -> let n = Scanf . sscanf s " . >-> OPTIONAL ARGUMENTS : ALMOST ALWAYS : Except % s time ( s ) " ( fun n -> n ) in begin try fnames := empty_fnames ~ regexp " . :\\ ml [ a - z0 - 9 ] " *$ ( " . mlopta " ^ n ) ! fnames with _ -> ( ) end ; print_endline s ; print_endline ( input_line ! res ) ; extend := " . mlopta " ^ n ; sel_section ( section ( ) ) | s when String . length s > 39 && String . sub s 0 39 = " . >-> OPTIONAL ARGUMENTS : ALMOST NEVER " : -> let n = Scanf . sscanf s " . >-> OPTIONAL ARGUMENTS : ALMOST NEVER : Except % s time ( s ) " ( fun n -> n ) in begin try fnames := empty_fnames ~ regexp " . :\\ ml [ a - z0 - 9 ] " *$ ( " . mloptn " ^ n ) ! fnames with _ -> ( ) end ; print_endline s ; print_endline ( input_line ! res ) ; extend := " . mloptn " ^ n ; sel_section ( section ( ) ) | _ -> sel_section ( ) with End_of_file -> ( )
let result ( ) = print_string " Total : \ x1b [ 0 ; 34m " ; print_int ! total ; print_string " \ x1b [ 0m \ nFailed : \ x1b [ 0 ; 31m " ; print_int ! errors ; let ratio = ( . - ) 100 . @@ ( . * ) 100 . @@ ( float_of_int ! total |> ( . / ) @@ float_of_int ! errors ) in print_string @@ " \ x1b [ 0m \ nRatio : \ x1b [ 0 ; 3 " ^ ( if ratio < 50 . then " 1m " else if ratio < 80 . then " 3m " else " 2m " ) ; print_float ratio ; print_endline " %\ x1b [ 0m "
let rec get_fnames ( ? acc = [ ] ) dir = try if Sys . is_directory dir then acc @ Array . fold_left ( fun l s -> get_fnames ~ acc : l ( normalize ( dir ^ " " / ^ s ) ) ) [ ] @@ Sys . readdir dir else if dir <> " . / check . ml " && Str . string_match ( Str . regexp " . [ */ _a - zA - Z0 - 9 ] . -* ml [ a - z0 - 9 ] " ) * dir 0 then dir :: acc else acc with _ -> acc
let ( ) = dir := if ( Array . length Sys . argv ) < 2 then " . " else Sys . argv . ( 1 ) ; res := if ( Array . length Sys . argv ) < 3 then open_in " res . out " else open_in Sys . argv . ( 2 ) ; fnames := List . fast_sort ( fun x y -> let req s = get_element ~ f : Str . search_backward ~ regexp " . :\\ ml [ a - z0 - 9 ] " * ~ start ( : String . length s - 1 ) s in let c = compare ( req x ) ( req y ) in if c = 0 then compare x y else c ) @@ get_fnames ! dir ; dir := ! dir ^ " " ; / sel_section ( ) ; close_in ! res ; result ( )
type checkpoint_state = C_stopped | C_running of int64
type checkpoint = { mutable c_time : int64 ; mutable c_pid : int ; mutable c_fd : io_channel ; mutable c_valid : bool ; mutable c_report : report option ; mutable c_state : checkpoint_state ; mutable c_parent : checkpoint ; mutable c_breakpoint_version : int ; mutable c_breakpoints : ( pc * int ref ) list ; mutable c_trap_barrier : int ; mutable c_code_fragments : int list }
let rec root = { c_time = _0 ; c_pid = - 2 ; c_fd = std_io ; c_valid = false ; c_report = None ; c_state = C_stopped ; c_parent = root ; c_breakpoint_version = 0 ; c_breakpoints = [ ] ; c_trap_barrier = 0 ; c_code_fragments = [ 0 ] }
let checkpoints = ref ( [ ] : checkpoint list )
let current_checkpoint = ref root
let current_time ( ) = ! current_checkpoint . c_time
let current_report ( ) = ! current_checkpoint . c_report
let current_pc_sp ( ) = match current_report ( ) with | Some { rep_type = Event | Breakpoint ; rep_program_pointer = pc ; rep_stack_pointer = sp } -> Some ( pc , sp ) | _ -> None
let current_pc ( ) = Option . map fst ( current_pc_sp ( ) )
module Stdlib = struct external register_named_value : string -> ' a -> unit = " caml_register_named_value " let ( ) = register_named_value " Pervasives . array_bound_error " ( Invalid_argument " index out of bounds " ) external raise : exn -> ' a = " % raise " external raise_notrace : exn -> ' a = " % raise_notrace " let failwith s = raise ( Failure s ) let invalid_arg s = raise ( Invalid_argument s ) exception Exit exception Match_failure = Match_failure exception Assert_failure = Assert_failure exception Invalid_argument = Invalid_argument exception Failure = Failure exception Not_found = Not_found exception Out_of_memory = Out_of_memory exception Stack_overflow = Stack_overflow exception Sys_error = Sys_error exception End_of_file = End_of_file exception Division_by_zero = Division_by_zero exception Sys_blocked_io = Sys_blocked_io exception Undefined_recursive_module = Undefined_recursive_module external ( |> ) : ' a -> ( ' a -> ' b ) -> ' b = " % revapply " external ( @@ ) : ( ' a -> ' b ) -> ' a -> ' b = " % apply " external __LOC__ : string = " % loc_LOC " external __FILE__ : string = " % loc_FILE " external __LINE__ : int = " % loc_LINE " external __MODULE__ : string = " % loc_MODULE " external __POS__ : string * int * int * int = " % loc_POS " external __LOC_OF__ : ' a -> string * ' a = " % loc_LOC " external __LINE_OF__ : ' a -> int * ' a = " % loc_LINE " external __POS_OF__ : ' a -> ( string * int * int * int ) * ' a = " % loc_POS " external ( = ) : ' a -> ' a -> bool = " % equal " external ( <> ) : ' a -> ' a -> bool = " % notequal " external ( < ) : ' a -> ' a -> bool = " % lessthan " external ( > ) : ' a -> ' a -> bool = " % greaterthan " external ( <= ) : ' a -> ' a -> bool = " % lessequal " external ( >= ) : ' a -> ' a -> bool = " % greaterequal " external compare : ' a -> ' a -> int = " % compare " let min x y = if x <= y then x else y let max x y = if x >= y then x else y external ( == ) : ' a -> ' a -> bool = " % eq " external ( != ) : ' a -> ' a -> bool = " % noteq " external not : bool -> bool = " % boolnot " external ( & ) : bool -> bool -> bool = " % sequand " external ( && ) : bool -> bool -> bool = " % sequand " external ( or ) : bool -> bool -> bool = " % sequor " external ( || ) : bool -> bool -> bool = " % sequor " external ( ~- ) : int -> int = " % negint " external ( ~+ ) : int -> int = " % identity " external succ : int -> int = " % succint " external pred : int -> int = " % predint " external ( + ) : int -> int -> int = " % addint " external ( - ) : int -> int -> int = " % subint " external ( * ) : int -> int -> int = " % mulint " external ( / ) : int -> int -> int = " % divint " external ( mod ) : int -> int -> int = " % modint " let abs x = if x >= 0 then x else - x external ( land ) : int -> int -> int = " % andint " external ( lor ) : int -> int -> int = " % orint " external ( lxor ) : int -> int -> int = " % xorint " let lnot x = x lxor - 1 external ( lsl ) : int -> int -> int = " % lslint " external ( lsr ) : int -> int -> int = " % lsrint " external ( asr ) : int -> int -> int = " % asrint " let max_int = - 1 lsr 1 let min_int = max_int + 1 external ( . ~- ) : float -> float = " % negfloat " external ( . ~+ ) : float -> float = " % identity " external ( . + ) : float -> float -> float = " % addfloat " external ( . - ) : float -> float -> float = " % subfloat " external ( . * ) : float -> float -> float = " % mulfloat " external ( . / ) : float -> float -> float = " % divfloat " external ( ** ) : float -> float -> float = " caml_power_float " " pow " [ @@ unboxed ] [ @@ noalloc ] external exp : float -> float = " caml_exp_float " " exp " [ @@ unboxed ] [ @@ noalloc ] external expm1 : float -> float = " caml_expm1_float " " caml_expm1 " [ @@ unboxed ] [ @@ noalloc ] external acos : float -> float = " caml_acos_float " " acos " [ @@ unboxed ] [ @@ noalloc ] external asin : float -> float = " caml_asin_float " " asin " [ @@ unboxed ] [ @@ noalloc ] external atan : float -> float = " caml_atan_float " " atan " [ @@ unboxed ] [ @@ noalloc ] external atan2 : float -> float -> float = " caml_atan2_float " " atan2 " [ @@ unboxed ] [ @@ noalloc ] external hypot : float -> float -> float = " caml_hypot_float " " caml_hypot " [ @@ unboxed ] [ @@ noalloc ] external cos : float -> float = " caml_cos_float " " cos " [ @@ unboxed ] [ @@ noalloc ] external cosh : float -> float = " caml_cosh_float " " cosh " [ @@ unboxed ] [ @@ noalloc ] external log : float -> float = " caml_log_float " " log " [ @@ unboxed ] [ @@ noalloc ] external log10 : float -> float = " caml_log10_float " " log10 " [ @@ unboxed ] [ @@ noalloc ] external log1p : float -> float = " caml_log1p_float " " caml_log1p " [ @@ unboxed ] [ @@ noalloc ] external sin : float -> float = " caml_sin_float " " sin " [ @@ unboxed ] [ @@ noalloc ] external sinh : float -> float = " caml_sinh_float " " sinh " [ @@ unboxed ] [ @@ noalloc ] external sqrt : float -> float = " caml_sqrt_float " " sqrt " [ @@ unboxed ] [ @@ noalloc ] external tan : float -> float = " caml_tan_float " " tan " [ @@ unboxed ] [ @@ noalloc ] external tanh : float -> float = " caml_tanh_float " " tanh " [ @@ unboxed ] [ @@ noalloc ] external ceil : float -> float = " caml_ceil_float " " ceil " [ @@ unboxed ] [ @@ noalloc ] external floor : float -> float = " caml_floor_float " " floor " [ @@ unboxed ] [ @@ noalloc ] external abs_float : float -> float = " % absfloat " external copysign : float -> float -> float = " caml_copysign_float " " caml_copysign " [ @@ unboxed ] [ @@ noalloc ] external mod_float : float -> float -> float = " caml_fmod_float " " fmod " [ @@ unboxed ] [ @@ noalloc ] external frexp : float -> float * int = " caml_frexp_float " external ldexp : ( float [ @ unboxed ] ) -> ( int [ @ untagged ] ) -> ( float [ @ unboxed ] ) = " caml_ldexp_float " " caml_ldexp_float_unboxed " [ @@ noalloc ] external modf : float -> float * float = " caml_modf_float " external float : int -> float = " % floatofint " external float_of_int : int -> float = " % floatofint " external truncate : float -> int = " % intoffloat " external int_of_float : float -> int = " % intoffloat " external float_of_bits : int64 -> float = " caml_int64_float_of_bits " " caml_int64_float_of_bits_unboxed " [ @@ unboxed ] [ @@ noalloc ] let infinity = float_of_bits 0x7F_F0_00_00_00_00_00_00L let neg_infinity = float_of_bits 0xFF_F0_00_00_00_00_00_00L let nan = float_of_bits 0x7F_F8_00_00_00_00_00_01L let max_float = float_of_bits 0x7F_EF_FF_FF_FF_FF_FF_FFL let min_float = float_of_bits 0x00_10_00_00_00_00_00_00L let epsilon_float = float_of_bits 0x3C_B0_00_00_00_00_00_00L type fpclass = | FP_normal | FP_subnormal | FP_zero | FP_infinite | FP_nan external classify_float : ( float [ @ unboxed ] ) -> fpclass = " caml_classify_float " " caml_classify_float_unboxed " [ @@ noalloc ] external string_length : string -> int = " % string_length " external bytes_length : bytes -> int = " % bytes_length " external bytes_create : int -> bytes = " caml_create_bytes " external string_blit : string -> int -> bytes -> int -> int -> unit = " caml_blit_string " [ @@ noalloc ] external bytes_blit : bytes -> int -> bytes -> int -> int -> unit = " caml_blit_bytes " [ @@ noalloc ] external bytes_unsafe_to_string : bytes -> string = " % bytes_to_string " let ( ^ ) s1 s2 = let l1 = string_length s1 and l2 = string_length s2 in let s = bytes_create ( l1 + l2 ) in string_blit s1 0 s 0 l1 ; string_blit s2 0 s l1 l2 ; bytes_unsafe_to_string s external int_of_char : char -> int = " % identity " external unsafe_char_of_int : int -> char = " % identity " let char_of_int n = if n < 0 || n > 255 then invalid_arg " char_of_int " else unsafe_char_of_int n external ignore : ' a -> unit = " % ignore " external fst : ' a * ' b -> ' a = " % field0 " external snd : ' a * ' b -> ' b = " % field1 " type ' a ref = { mutable contents : ' a } external ref : ' a -> ' a ref = " % makemutable " external ( ! ) : ' a ref -> ' a = " % field0 " external ( := ) : ' a ref -> ' a -> unit = " % setfield0 " external incr : int ref -> unit = " % incr " external decr : int ref -> unit = " % decr " type ( ' a , ' b ) result = | Ok of ' a | Error of ' b external format_int : string -> int -> string = " caml_format_int " external format_float : string -> float -> string = " caml_format_float " let string_of_bool b = if b then " true " else " false " let bool_of_string = function | " true " -> true | " false " -> false | _ -> invalid_arg " bool_of_string " let bool_of_string_opt = function | " true " -> Some true | " false " -> Some false | _ -> None let string_of_int n = format_int " % d " n external int_of_string : string -> int = " caml_int_of_string " let int_of_string_opt s = try Some ( int_of_string s ) with Failure _ -> None external string_get : string -> int -> char = " % string_safe_get " let valid_float_lexem s = let l = string_length s in let rec loop i = if i >= l then s ^ " . " else match string_get s i with ' 0 ' . . ' 9 ' | ' ' - -> loop ( i + 1 ) | _ -> s in loop 0 let string_of_float f = valid_float_lexem ( format_float " . % 12g " f ) external float_of_string : string -> float = " caml_float_of_string " let float_of_string_opt s = try Some ( float_of_string s ) with Failure _ -> None let rec ( @ ) l1 l2 = match l1 with [ ] -> l2 | hd :: tl -> hd :: ( tl @ l2 ) type in_channel type out_channel external open_descriptor_out : int -> out_channel = " caml_ml_open_descriptor_out " external open_descriptor_in : int -> in_channel = " caml_ml_open_descriptor_in " let stdin = open_descriptor_in 0 let stdout = open_descriptor_out 1 let stderr = open_descriptor_out 2 type open_flag = | Open_rdonly | Open_wronly | Open_append | Open_creat | Open_trunc | Open_excl | Open_binary | Open_text | Open_nonblock external open_desc : string -> open_flag list -> int -> int = " caml_sys_open " external set_out_channel_name : out_channel -> string -> unit = " caml_ml_set_channel_name " let open_out_gen mode perm name = let c = open_descriptor_out ( open_desc name mode perm ) in set_out_channel_name c name ; c let open_out name = open_out_gen [ Open_wronly ; Open_creat ; Open_trunc ; Open_text ] 0o666 name let open_out_bin name = open_out_gen [ Open_wronly ; Open_creat ; Open_trunc ; Open_binary ] 0o666 name external flush : out_channel -> unit = " caml_ml_flush " external out_channels_list : unit -> out_channel list = " caml_ml_out_channels_list " let flush_all ( ) = let rec iter = function | [ ] -> ( ) | a :: l -> begin try flush a with Sys_error _ -> ( ) end ; iter l in iter ( out_channels_list ( ) ) external unsafe_output : out_channel -> bytes -> int -> int -> unit = " caml_ml_output_bytes " external unsafe_output_string : out_channel -> string -> int -> int -> unit = " caml_ml_output " external output_char : out_channel -> char -> unit = " caml_ml_output_char " let output_bytes oc s = unsafe_output oc s 0 ( bytes_length s ) let output_string oc s = unsafe_output_string oc s 0 ( string_length s ) let output oc s ofs len = if ofs < 0 || len < 0 || ofs > bytes_length s - len then invalid_arg " output " else unsafe_output oc s ofs len let output_substring oc s ofs len = if ofs < 0 || len < 0 || ofs > string_length s - len then invalid_arg " output_substring " else unsafe_output_string oc s ofs len external output_byte : out_channel -> int -> unit = " caml_ml_output_char " external output_binary_int : out_channel -> int -> unit = " caml_ml_output_int " external marshal_to_channel : out_channel -> ' a -> unit list -> unit = " caml_output_value " let output_value chan v = marshal_to_channel chan v [ ] external seek_out : out_channel -> int -> unit = " caml_ml_seek_out " external pos_out : out_channel -> int = " caml_ml_pos_out " external out_channel_length : out_channel -> int = " caml_ml_channel_size " external close_out_channel : out_channel -> unit = " caml_ml_close_channel " let close_out oc = flush oc ; close_out_channel oc let close_out_noerr oc = ( try flush oc with _ -> ( ) ) ; try close_out_channel oc with _ -> ( ) external set_binary_mode_out : out_channel -> bool -> unit = " caml_ml_set_binary_mode " external set_in_channel_name : in_channel -> string -> unit = " caml_ml_set_channel_name " let open_in_gen mode perm name = let c = open_descriptor_in ( open_desc name mode perm ) in set_in_channel_name c name ; c let open_in name = open_in_gen [ Open_rdonly ; Open_text ] 0 name let open_in_bin name = open_in_gen [ Open_rdonly ; Open_binary ] 0 name external input_char : in_channel -> char = " caml_ml_input_char " external unsafe_input : in_channel -> bytes -> int -> int -> int = " caml_ml_input " let input ic s ofs len = if ofs < 0 || len < 0 || ofs > bytes_length s - len then invalid_arg " input " else unsafe_input ic s ofs len let rec unsafe_really_input ic s ofs len = if len <= 0 then ( ) else let r = unsafe_input ic s ofs len in if r = 0 then raise End_of_file else unsafe_really_input ic s ( ofs + r ) ( len - r ) let really_input ic s ofs len = if ofs < 0 || len < 0 || ofs > bytes_length s - len then invalid_arg " really_input " else unsafe_really_input ic s ofs len let really_input_string ic len = let s = bytes_create len in really_input ic s 0 len ; bytes_unsafe_to_string s external input_scan_line : in_channel -> int = " caml_ml_input_scan_line " let input_line chan = let rec build_result buf pos = function | [ ] -> buf | hd :: tl -> let len = bytes_length hd in bytes_blit hd 0 buf ( pos - len ) len ; build_result buf ( pos - len ) tl in let rec scan accu len = let n = input_scan_line chan in if n = 0 then match accu with | [ ] -> raise End_of_file | _ -> build_result ( bytes_create len ) len accu else if n > 0 then begin let res = bytes_create ( n - 1 ) in ignore ( unsafe_input chan res 0 ( n - 1 ) ) ; ignore ( input_char chan ) ; match accu with | [ ] -> res | _ -> let len = len + n - 1 in build_result ( bytes_create len ) len ( res :: accu ) end else let beg = bytes_create ( - n ) in ignore ( unsafe_input chan beg 0 ( - n ) ) ; scan ( beg :: accu ) ( len - n ) in bytes_unsafe_to_string ( scan [ ] 0 ) external input_byte : in_channel -> int = " caml_ml_input_char " external input_binary_int : in_channel -> int = " caml_ml_input_int " external input_value : in_channel -> ' a = " caml_input_value " external seek_in : in_channel -> int -> unit = " caml_ml_seek_in " external pos_in : in_channel -> int = " caml_ml_pos_in " external in_channel_length : in_channel -> int = " caml_ml_channel_size " external close_in : in_channel -> unit = " caml_ml_close_channel " let close_in_noerr ic = try close_in ic with _ -> ( ) external set_binary_mode_in : in_channel -> bool -> unit = " caml_ml_set_binary_mode " let print_char c = output_char stdout c let print_string s = output_string stdout s let print_bytes s = output_bytes stdout s let print_int i = output_string stdout ( string_of_int i ) let print_float f = output_string stdout ( string_of_float f ) let print_endline s = output_string stdout s ; output_char stdout ' \ n ' ; flush stdout let print_newline ( ) = output_char stdout ' \ n ' ; flush stdout let prerr_char c = output_char stderr c let prerr_string s = output_string stderr s let prerr_bytes s = output_bytes stderr s let prerr_int i = output_string stderr ( string_of_int i ) let prerr_float f = output_string stderr ( string_of_float f ) let prerr_endline s = output_string stderr s ; output_char stderr ' \ n ' ; flush stderr let prerr_newline ( ) = output_char stderr ' \ n ' ; flush stderr let read_line ( ) = flush stdout ; input_line stdin let read_int ( ) = int_of_string ( read_line ( ) ) let read_int_opt ( ) = int_of_string_opt ( read_line ( ) ) let read_float ( ) = float_of_string ( read_line ( ) ) let read_float_opt ( ) = float_of_string_opt ( read_line ( ) ) module LargeFile = struct external seek_out : out_channel -> int64 -> unit = " caml_ml_seek_out_64 " external pos_out : out_channel -> int64 = " caml_ml_pos_out_64 " external out_channel_length : out_channel -> int64 = " caml_ml_channel_size_64 " external seek_in : in_channel -> int64 -> unit = " caml_ml_seek_in_64 " external pos_in : in_channel -> int64 = " caml_ml_pos_in_64 " external in_channel_length : in_channel -> int64 = " caml_ml_channel_size_64 " end type ( ' a , ' b , ' c , ' d , ' e , ' f ) format6 = ( ' a , ' b , ' c , ' d , ' e , ' f ) CamlinternalFormatBasics . format6 = | Format of ( ' a , ' b , ' c , ' d , ' e , ' f ) CamlinternalFormatBasics . fmt * string type ( ' a , ' b , ' c , ' d ) format4 = ( ' a , ' b , ' c , ' c , ' c , ' d ) format6 type ( ' a , ' b , ' c ) format = ( ' a , ' b , ' c , ' c ) format4 let string_of_format ( Format ( _fmt , str ) ) = str external format_of_string : ( ' a , ' b , ' c , ' d , ' e , ' f ) format6 -> ( ' a , ' b , ' c , ' d , ' e , ' f ) format6 = " % identity " let ( ^^ ) ( Format ( fmt1 , str1 ) ) ( Format ( fmt2 , str2 ) ) = Format ( CamlinternalFormatBasics . concat_fmt fmt1 fmt2 , str1 ^ " , " % ^ str2 ) external sys_exit : int -> ' a = " caml_sys_exit " let exit_function = ref flush_all let at_exit f = let g = ! exit_function in let f_already_ran = ref false in exit_function := fun ( ) -> if not ! f_already_ran then begin f_already_ran := true ; f ( ) end ; g ( ) let do_at_exit ( ) = ! exit_function ( ) let exit retcode = do_at_exit ( ) ; sys_exit retcode let _ = register_named_value " Pervasives . do_at_exit " do_at_exit end
let create_char_set ( ) = Bytes . make 32 ' \ 000 '
let add_in_char_set char_set c = let ind = int_of_char c in let str_ind = ind lsr 3 and mask = 1 lsl ( ind land 0b111 ) in Bytes . set char_set str_ind ( char_of_int ( int_of_char ( Bytes . get char_set str_ind ) lor mask ) )
let freeze_char_set char_set = Bytes . to_string char_set
let rev_char_set char_set = let char_set ' = create_char_set ( ) in for i = 0 to 31 do Bytes . set char_set ' i ( char_of_int ( int_of_char ( String . get char_set i ) lxor 0xFF ) ) done ; Bytes . unsafe_to_string char_set '
let is_in_char_set char_set c = let ind = int_of_char c in let str_ind = ind lsr 3 and mask = 1 lsl ( ind land 0b111 ) in int_of_char ( String . get char_set str_ind ) land mask <> 0
type ( ' a , ' b , ' c , ' d , ' e , ' f ) param_format_ebb = | Param_format_EBB : ( ' x -> ' a , ' b , ' c , ' d , ' e , ' f ) fmt -> ( ' a , ' b , ' c , ' d , ' e , ' f ) param_format_ebb
let pad_of_pad_opt pad_opt = match pad_opt with | None -> No_padding | Some width -> Lit_padding ( Right , width )
let prec_of_prec_opt prec_opt = match prec_opt with None -> No_precision | Some ndec -> Lit_precision ndec
let param_format_of_ignored_format : type a b c d e f x y . ( a , b , c , d , y , x ) ignored -> ( x , b , c , y , e , f ) fmt -> ( a , b , c , d , e , f ) param_format_ebb = fun ign fmt -> match ign with | Ignored_char -> Param_format_EBB ( Char fmt ) | Ignored_caml_char -> Param_format_EBB ( Caml_char fmt ) | Ignored_string pad_opt -> Param_format_EBB ( String ( pad_of_pad_opt pad_opt , fmt ) ) | Ignored_caml_string pad_opt -> Param_format_EBB ( Caml_string ( pad_of_pad_opt pad_opt , fmt ) ) | Ignored_int ( iconv , pad_opt ) -> Param_format_EBB ( Int ( iconv , pad_of_pad_opt pad_opt , No_precision , fmt ) ) | Ignored_int32 ( iconv , pad_opt ) -> Param_format_EBB ( Int32 ( iconv , pad_of_pad_opt pad_opt , No_precision , fmt ) ) | Ignored_nativeint ( iconv , pad_opt ) -> Param_format_EBB ( Nativeint ( iconv , pad_of_pad_opt pad_opt , No_precision , fmt ) ) | Ignored_int64 ( iconv , pad_opt ) -> Param_format_EBB ( Int64 ( iconv , pad_of_pad_opt pad_opt , No_precision , fmt ) ) | Ignored_float ( pad_opt , prec_opt ) -> Param_format_EBB ( Float ( ( Float_flag_ , Float_f ) , pad_of_pad_opt pad_opt , prec_of_prec_opt prec_opt , fmt ) ) | Ignored_bool pad_opt -> Param_format_EBB ( Bool ( pad_of_pad_opt pad_opt , fmt ) ) | Ignored_format_arg ( pad_opt , fmtty ) -> Param_format_EBB ( Format_arg ( pad_opt , fmtty , fmt ) ) | Ignored_format_subst ( pad_opt , fmtty ) -> Param_format_EBB ( Format_subst ( pad_opt , fmtty , fmt ) ) | Ignored_reader -> Param_format_EBB ( Reader fmt ) | Ignored_scan_char_set ( width_opt , char_set ) -> Param_format_EBB ( Scan_char_set ( width_opt , char_set , fmt ) ) | Ignored_scan_get_counter counter -> Param_format_EBB ( Scan_get_counter ( counter , fmt ) ) | Ignored_scan_next_char -> Param_format_EBB ( Scan_next_char fmt )
type ( ' b , ' c ) acc_formatting_gen = | Acc_open_tag of ( ' b , ' c ) acc | Acc_open_box of ( ' b , ' c ) acc | Acc_formatting_lit of ( ' b , ' c ) acc * formatting_lit | Acc_formatting_gen of ( ' b , ' c ) acc * ( ' b , ' c ) acc_formatting_gen | Acc_string_literal of ( ' b , ' c ) acc * string | Acc_char_literal of ( ' b , ' c ) acc * char | Acc_data_string of ( ' b , ' c ) acc * string | Acc_data_char of ( ' b , ' c ) acc * char | Acc_delay of ( ' b , ' c ) acc * ( ' b -> ' c ) | Acc_flush of ( ' b , ' c ) acc | Acc_invalid_arg of ( ' b , ' c ) acc * string | End_of_acc
type ( ' a , ' b ) heter_list = | Cons : ' c * ( ' a , ' b ) heter_list -> ( ' c -> ' a , ' b ) heter_list | Nil : ( ' b , ' b ) heter_list
type ( ' a , ' b , ' c , ' d , ' e , ' f ) padding_fmtty_ebb = | Padding_fmtty_EBB : ( ' x , ' y ) padding * ( ' y , ' b , ' c , ' d , ' e , ' f ) fmtty -> ( ' x , ' b , ' c , ' d , ' e , ' f ) padding_fmtty_ebb
type ( ' a , ' b , ' c , ' d , ' e , ' f ) padprec_fmtty_ebb = | Padprec_fmtty_EBB : ( ' x , ' y ) padding * ( ' y , ' z ) precision * ( ' z , ' b , ' c , ' d , ' e , ' f ) fmtty -> ( ' x , ' b , ' c , ' d , ' e , ' f ) padprec_fmtty_ebb
type ( ' a , ' b , ' c , ' e , ' f ) padding_fmt_ebb = | Padding_fmt_EBB : ( _ , ' x -> ' a ) padding * ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt -> ( ' x , ' b , ' c , ' e , ' f ) padding_fmt_ebb
type ( ' a , ' b , ' c , ' e , ' f ) precision_fmt_ebb = | Precision_fmt_EBB : ( _ , ' x -> ' a ) precision * ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt -> ( ' x , ' b , ' c , ' e , ' f ) precision_fmt_ebb
type ( ' p , ' b , ' c , ' e , ' f ) padprec_fmt_ebb = | Padprec_fmt_EBB : ( ' x , ' y ) padding * ( ' y , ' p -> ' a ) precision * ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt -> ( ' p , ' b , ' c , ' e , ' f ) padprec_fmt_ebb
type ( ' b , ' c , ' e , ' f ) fmt_ebb = | Fmt_EBB : ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt -> ( ' b , ' c , ' e , ' f ) fmt_ebb
type ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt_fmtty_ebb = | Fmt_fmtty_EBB : ( ' a , ' b , ' c , ' d , ' y , ' x ) fmt * ( ' x , ' b , ' c , ' y , ' e , ' f ) fmtty -> ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt_fmtty_ebb
type ( ' a , ' b , ' c , ' d , ' e , ' f ) fmtty_fmt_ebb = | Fmtty_fmt_EBB : ( ' a , ' b , ' c , ' d , ' y , ' x ) fmtty * ( ' x , ' b , ' c , ' y , ' e , ' f ) fmt_fmtty_ebb -> ( ' a , ' b , ' c , ' d , ' e , ' f ) fmtty_fmt_ebb
type fmtty_ebb = Fmtty_EBB : ( ' a , ' b , ' c , ' d , ' e , ' f ) fmtty -> fmtty_ebb
type padding_ebb = Padding_EBB : ( ' a , ' b ) padding -> padding_ebb
type precision_ebb = Precision_EBB : ( ' a , ' b ) precision -> precision_ebb
let default_float_precision fconv = match snd fconv with | Float_f | Float_e | Float_E | Float_g | Float_G | Float_h | Float_H -> - 6 | Float_F -> 12 = " caml_nativeint_format " = " caml_hexstring_of_float "
type buffer = { mutable ind : int ; mutable bytes : bytes }
let buffer_create init_size = { ind = 0 ; bytes = Bytes . create init_size }
let buffer_check_size buf overhead = let len = Bytes . length buf . bytes in let min_len = buf . ind + overhead in if min_len > len then ( let new_len = max ( len * 2 ) min_len in let new_str = Bytes . create new_len in Bytes . blit buf . bytes 0 new_str 0 len ; buf . bytes <- new_str )
let buffer_add_char buf c = buffer_check_size buf 1 ; Bytes . set buf . bytes buf . ind c ; buf . ind <- buf . ind + 1
let buffer_add_string buf s = let str_len = String . length s in buffer_check_size buf str_len ; String . blit s 0 buf . bytes buf . ind str_len ; buf . ind <- buf . ind + str_len
let buffer_contents buf = Bytes . sub_string buf . bytes 0 buf . ind
let char_of_iconv iconv = match iconv with | Int_d | Int_pd | Int_sd | Int_Cd -> ' d ' | Int_i | Int_pi | Int_si | Int_Ci -> ' i ' | Int_x | Int_Cx -> ' x ' | Int_X | Int_CX -> ' X ' | Int_o | Int_Co -> ' o ' | Int_u | Int_Cu -> ' u '
let char_of_fconv ( ? cF = ' F ' ) fconv = match snd fconv with | Float_f -> ' f ' | Float_e -> ' e ' | Float_E -> ' E ' | Float_g -> ' g ' | Float_G -> ' G ' | Float_F -> cF | Float_h -> ' h ' | Float_H -> ' H '
let char_of_counter counter = match counter with | Line_counter -> ' l ' | Char_counter -> ' n ' | Token_counter -> ' N '
let bprint_char_set buf char_set = let rec print_start set = let is_alone c = let before , after = Char . ( chr ( code c - 1 ) , chr ( code c + 1 ) ) in is_in_char_set set c && not ( is_in_char_set set before && is_in_char_set set after ) in if is_alone ' ] ' then buffer_add_char buf ' ] ' ; print_out set 1 ; if is_alone ' ' - then buffer_add_char buf ' ' - and print_out set i = if i < 256 then if is_in_char_set set ( char_of_int i ) then print_first set i else print_out set ( i + 1 ) and print_first set i = match char_of_int i with | ' \ 255 ' -> print_char buf 255 | ' ] ' | ' ' - -> print_out set ( i + 1 ) | _ -> print_second set ( i + 1 ) and print_second set i = if is_in_char_set set ( char_of_int i ) then match char_of_int i with | ' \ 255 ' -> print_char buf 254 ; print_char buf 255 | ( ' ] ' | ' ' ) - when not ( is_in_char_set set ( char_of_int ( i + 1 ) ) ) -> print_char buf ( i - 1 ) ; print_out set ( i + 1 ) | _ when not ( is_in_char_set set ( char_of_int ( i + 1 ) ) ) -> print_char buf ( i - 1 ) ; print_char buf i ; print_out set ( i + 2 ) | _ -> print_in set ( i - 1 ) ( i + 2 ) else ( print_char buf ( i - 1 ) ; print_out set ( i + 1 ) ) and print_in set i j = if j = 256 || not ( is_in_char_set set ( char_of_int j ) ) then ( print_char buf i ; print_char buf ( int_of_char ' ' ) ; - print_char buf ( j - 1 ) ; if j < 256 then print_out set ( j + 1 ) ) else print_in set i ( j + 1 ) and print_char buf i = match char_of_int i with | ' ' % -> buffer_add_char buf ' ' ; % buffer_add_char buf ' ' % | ' ' @ -> buffer_add_char buf ' ' ; % buffer_add_char buf ' ' @ | c -> buffer_add_char buf c in buffer_add_char buf ' [ ' ; print_start ( if is_in_char_set char_set ' \ 000 ' then ( buffer_add_char buf ' ' ; ^ rev_char_set char_set ) else char_set ) ; buffer_add_char buf ' ] '
let bprint_padty buf padty = match padty with | Left -> buffer_add_char buf ' ' - | Right -> ( ) | Zeros -> buffer_add_char buf ' 0 '
let bprint_ignored_flag buf ign_flag = if ign_flag then buffer_add_char buf ' _ '
let bprint_pad_opt buf pad_opt = match pad_opt with | None -> ( ) | Some width -> buffer_add_string buf ( Int . to_string width )
let bprint_padding : type a b . buffer -> ( a , b ) padding -> unit = fun buf pad -> match pad with | No_padding -> ( ) | Lit_padding ( padty , n ) -> bprint_padty buf padty ; buffer_add_string buf ( Int . to_string n ) | Arg_padding padty -> bprint_padty buf padty ; buffer_add_char buf ' ' *
let bprint_precision : type a b . buffer -> ( a , b ) precision -> unit = fun buf prec -> match prec with | No_precision -> ( ) | Lit_precision n -> buffer_add_char buf ' . ' ; buffer_add_string buf ( Int . to_string n ) | Arg_precision -> buffer_add_string buf " . " *
let bprint_iconv_flag buf iconv = match iconv with | Int_pd | Int_pi -> buffer_add_char buf ' ' + | Int_sd | Int_si -> buffer_add_char buf ' ' | Int_Cx | Int_CX | Int_Co | Int_Cd | Int_Ci | Int_Cu -> buffer_add_char buf ' ' # | Int_d | Int_i | Int_x | Int_X | Int_o | Int_u -> ( )
let bprint_int_fmt buf ign_flag iconv pad prec = buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; bprint_iconv_flag buf iconv ; bprint_padding buf pad ; bprint_precision buf prec ; buffer_add_char buf ( char_of_iconv iconv )
let bprint_altint_fmt buf ign_flag iconv pad prec c = buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; bprint_iconv_flag buf iconv ; bprint_padding buf pad ; bprint_precision buf prec ; buffer_add_char buf c ; buffer_add_char buf ( char_of_iconv iconv )
let bprint_fconv_flag buf fconv = match fst fconv with | Float_flag_p -> buffer_add_char buf ' ' + | Float_flag_s -> buffer_add_char buf ' ' | Float_flag_ -> ( )
let bprint_float_fmt buf ign_flag fconv pad prec = buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; bprint_fconv_flag buf fconv ; bprint_padding buf pad ; bprint_precision buf prec ; buffer_add_char buf ( char_of_fconv fconv )
let string_of_formatting_lit formatting_lit = match formatting_lit with | Close_box -> " ] " @ | Close_tag -> " } " @ | Break ( str , _ , _ ) -> str | FFlush -> " " @? | Force_newline -> " @\ n " | Flush_newline -> " . " @ | Magic_size ( str , _ ) -> str | Escaped_at -> " " @@ | Escaped_percent -> " " @% | Scan_indic c -> " " @ ^ String . make 1 c
let string_of_formatting_gen : type a b c d e f . ( a , b , c , d , e , f ) formatting_gen -> string = fun formatting_gen -> match formatting_gen with | Open_tag ( Format ( _ , str ) ) -> str | Open_box ( Format ( _ , str ) ) -> str
let bprint_char_literal buf chr = match chr with | ' ' % -> buffer_add_string buf " " %% | _ -> buffer_add_char buf chr
let bprint_string_literal buf str = for i = 0 to String . length str - 1 do bprint_char_literal buf str . [ i ] done
let rec bprint_fmtty : type a b c d e f g h i j k l . buffer -> ( a , b , c , d , e , f , g , h , i , j , k , l ) fmtty_rel -> unit = fun buf fmtty -> match fmtty with | Char_ty rest -> buffer_add_string buf " % c " ; bprint_fmtty buf rest | String_ty rest -> buffer_add_string buf " % s " ; bprint_fmtty buf rest | Int_ty rest -> buffer_add_string buf " % i " ; bprint_fmtty buf rest | Int32_ty rest -> buffer_add_string buf " % li " ; bprint_fmtty buf rest | Nativeint_ty rest -> buffer_add_string buf " % ni " ; bprint_fmtty buf rest | Int64_ty rest -> buffer_add_string buf " % Li " ; bprint_fmtty buf rest | Float_ty rest -> buffer_add_string buf " % f " ; bprint_fmtty buf rest | Bool_ty rest -> buffer_add_string buf " % B " ; bprint_fmtty buf rest | Alpha_ty rest -> buffer_add_string buf " % a " ; bprint_fmtty buf rest | Theta_ty rest -> buffer_add_string buf " % t " ; bprint_fmtty buf rest | Any_ty rest -> buffer_add_string buf " " ; %? bprint_fmtty buf rest | Reader_ty rest -> buffer_add_string buf " % r " ; bprint_fmtty buf rest | Ignored_reader_ty rest -> buffer_add_string buf " % _r " ; bprint_fmtty buf rest | Format_arg_ty ( sub_fmtty , rest ) -> buffer_add_string buf " { " ; % bprint_fmtty buf sub_fmtty ; buffer_add_string buf " } " ; % bprint_fmtty buf rest | Format_subst_ty ( sub_fmtty , _ , rest ) -> buffer_add_string buf " ( " ; % bprint_fmtty buf sub_fmtty ; buffer_add_string buf " ) " ; % bprint_fmtty buf rest | End_of_fmtty -> ( )
let rec int_of_custom_arity : type a b c . ( a , b , c ) custom_arity -> int = function | Custom_zero -> 0 | Custom_succ x -> 1 + int_of_custom_arity x
let bprint_fmt buf fmt = let rec fmtiter : type a b c d e f . ( a , b , c , d , e , f ) fmt -> bool -> unit = fun fmt ign_flag -> match fmt with | String ( pad , rest ) -> buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; bprint_padding buf pad ; buffer_add_char buf ' s ' ; fmtiter rest false | Caml_string ( pad , rest ) -> buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; bprint_padding buf pad ; buffer_add_char buf ' S ' ; fmtiter rest false | Int ( iconv , pad , prec , rest ) -> bprint_int_fmt buf ign_flag iconv pad prec ; fmtiter rest false | Int32 ( iconv , pad , prec , rest ) -> bprint_altint_fmt buf ign_flag iconv pad prec ' l ' ; fmtiter rest false | Nativeint ( iconv , pad , prec , rest ) -> bprint_altint_fmt buf ign_flag iconv pad prec ' n ' ; fmtiter rest false | Int64 ( iconv , pad , prec , rest ) -> bprint_altint_fmt buf ign_flag iconv pad prec ' L ' ; fmtiter rest false | Float ( fconv , pad , prec , rest ) -> bprint_float_fmt buf ign_flag fconv pad prec ; fmtiter rest false | Char rest -> buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; buffer_add_char buf ' c ' ; fmtiter rest false | Caml_char rest -> buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; buffer_add_char buf ' C ' ; fmtiter rest false | Bool ( pad , rest ) -> buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; bprint_padding buf pad ; buffer_add_char buf ' B ' ; fmtiter rest false | Alpha rest -> buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; buffer_add_char buf ' a ' ; fmtiter rest false | Theta rest -> buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; buffer_add_char buf ' t ' ; fmtiter rest false | Custom ( arity , _ , rest ) -> for _i = 1 to int_of_custom_arity arity do buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; buffer_add_char buf ' ' ? done ; fmtiter rest false | Reader rest -> buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; buffer_add_char buf ' r ' ; fmtiter rest false | Flush rest -> buffer_add_string buf " " ; %! fmtiter rest ign_flag | String_literal ( str , rest ) -> bprint_string_literal buf str ; fmtiter rest ign_flag | Char_literal ( chr , rest ) -> bprint_char_literal buf chr ; fmtiter rest ign_flag | Format_arg ( pad_opt , fmtty , rest ) -> buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; bprint_pad_opt buf pad_opt ; buffer_add_char buf ' { ' ; bprint_fmtty buf fmtty ; buffer_add_char buf ' ' ; % buffer_add_char buf ' } ' ; fmtiter rest false | Format_subst ( pad_opt , fmtty , rest ) -> buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; bprint_pad_opt buf pad_opt ; buffer_add_char buf ' ( ' ; bprint_fmtty buf fmtty ; buffer_add_char buf ' ' ; % buffer_add_char buf ' ) ' ; fmtiter rest false | Scan_char_set ( width_opt , char_set , rest ) -> buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; bprint_pad_opt buf width_opt ; bprint_char_set buf char_set ; fmtiter rest false | Scan_get_counter ( counter , rest ) -> buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; buffer_add_char buf ( char_of_counter counter ) ; fmtiter rest false | Scan_next_char rest -> buffer_add_char buf ' ' ; % bprint_ignored_flag buf ign_flag ; bprint_string_literal buf " 0c " ; fmtiter rest false | Ignored_param ( ign , rest ) -> let ( Param_format_EBB fmt ' ) = param_format_of_ignored_format ign rest in fmtiter fmt ' true | Formatting_lit ( fmting_lit , rest ) -> bprint_string_literal buf ( string_of_formatting_lit fmting_lit ) ; fmtiter rest ign_flag | Formatting_gen ( fmting_gen , rest ) -> bprint_string_literal buf " { " ; @ bprint_string_literal buf ( string_of_formatting_gen fmting_gen ) ; fmtiter rest ign_flag | End_of_format -> ( ) in fmtiter fmt false
let string_of_fmt fmt = let buf = buffer_create 16 in bprint_fmt buf fmt ; buffer_contents buf
type ( _ , _ ) eq = Refl : ( ' a , ' a ) eq
let rec symm : type a1 b1 c1 d1 e1 f1 a2 b2 c2 d2 e2 f2 . ( a1 , b1 , c1 , d1 , e1 , f1 , a2 , b2 , c2 , d2 , e2 , f2 ) fmtty_rel -> ( a2 , b2 , c2 , d2 , e2 , f2 , a1 , b1 , c1 , d1 , e1 , f1 ) fmtty_rel = function | Char_ty rest -> Char_ty ( symm rest ) | Int_ty rest -> Int_ty ( symm rest ) | Int32_ty rest -> Int32_ty ( symm rest ) | Int64_ty rest -> Int64_ty ( symm rest ) | Nativeint_ty rest -> Nativeint_ty ( symm rest ) | Float_ty rest -> Float_ty ( symm rest ) | Bool_ty rest -> Bool_ty ( symm rest ) | String_ty rest -> String_ty ( symm rest ) | Theta_ty rest -> Theta_ty ( symm rest ) | Alpha_ty rest -> Alpha_ty ( symm rest ) | Any_ty rest -> Any_ty ( symm rest ) | Reader_ty rest -> Reader_ty ( symm rest ) | Ignored_reader_ty rest -> Ignored_reader_ty ( symm rest ) | Format_arg_ty ( ty , rest ) -> Format_arg_ty ( ty , symm rest ) | Format_subst_ty ( ty1 , ty2 , rest ) -> Format_subst_ty ( ty2 , ty1 , symm rest ) | End_of_fmtty -> End_of_fmtty
let rec fmtty_rel_det : type a1 b c d1 e1 f1 a2 d2 e2 f2 . ( a1 , b , c , d1 , e1 , f1 , a2 , b , c , d2 , e2 , f2 ) fmtty_rel -> ( ( f1 , f2 ) eq -> ( a1 , a2 ) eq ) * ( ( a1 , a2 ) eq -> ( f1 , f2 ) eq ) * ( ( e1 , e2 ) eq -> ( d1 , d2 ) eq ) * ( ( d1 , d2 ) eq -> ( e1 , e2 ) eq ) = function | End_of_fmtty -> ( fun Refl -> Refl ) , ( fun Refl -> Refl ) , ( fun Refl -> Refl ) , fun Refl -> Refl | Char_ty rest -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ed , de ) | String_ty rest -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ed , de ) | Int_ty rest -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ed , de ) | Int32_ty rest -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ed , de ) | Int64_ty rest -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ed , de ) | Nativeint_ty rest -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ed , de ) | Float_ty rest -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ed , de ) | Bool_ty rest -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ed , de ) | Theta_ty rest -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ed , de ) | Alpha_ty rest -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ed , de ) | Any_ty rest -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ed , de ) | Reader_ty rest -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ( fun Refl -> let Refl = ed Refl in Refl ) , fun Refl -> let Refl = de Refl in Refl ) | Ignored_reader_ty rest -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ( fun Refl -> let Refl = ed Refl in Refl ) , fun Refl -> let Refl = de Refl in Refl ) | Format_arg_ty ( _ty , rest ) -> let fa , af , ed , de = fmtty_rel_det rest in ( ( fun Refl -> let Refl = fa Refl in Refl ) , ( fun Refl -> let Refl = af Refl in Refl ) , ed , de ) | Format_subst_ty ( ty1 , ty2 , rest ) -> let fa , af , ed , de = fmtty_rel_det rest in let ty = trans ( symm ty1 ) ty2 in let ag , ga , dj , jd = fmtty_rel_det ty in ( ( fun Refl -> let Refl = fa Refl in let Refl = ag Refl in Refl ) , ( fun Refl -> let Refl = ga Refl in let Refl = af Refl in Refl ) , ( fun Refl -> let Refl = ed Refl in let Refl = dj Refl in Refl ) , fun Refl -> let Refl = jd Refl in let Refl = de Refl in Refl ) | Foo _ , _ | _ , Foo _ -> assert false ) * type a1 b1 c1 d1 e1 f1 a2 b2 c2 d2 e2 f2 a3 b3 c3 d3 e3 f3 . ( a1 , b1 , c1 , d1 , e1 , f1 , a2 , b2 , c2 , d2 , e2 , f2 ) fmtty_rel -> ( a2 , b2 , c2 , d2 , e2 , f2 , a3 , b3 , c3 , d3 , e3 , f3 ) fmtty_rel -> ( a1 , b1 , c1 , d1 , e1 , f1 , a3 , b3 , c3 , d3 , e3 , f3 ) fmtty_rel = fun ty1 ty2 -> match ty1 , ty2 with | Char_ty rest1 , Char_ty rest2 -> Char_ty ( trans rest1 rest2 ) | String_ty rest1 , String_ty rest2 -> String_ty ( trans rest1 rest2 ) | Bool_ty rest1 , Bool_ty rest2 -> Bool_ty ( trans rest1 rest2 ) | Int_ty rest1 , Int_ty rest2 -> Int_ty ( trans rest1 rest2 ) | Int32_ty rest1 , Int32_ty rest2 -> Int32_ty ( trans rest1 rest2 ) | Int64_ty rest1 , Int64_ty rest2 -> Int64_ty ( trans rest1 rest2 ) | Nativeint_ty rest1 , Nativeint_ty rest2 -> Nativeint_ty ( trans rest1 rest2 ) | Float_ty rest1 , Float_ty rest2 -> Float_ty ( trans rest1 rest2 ) | Alpha_ty rest1 , Alpha_ty rest2 -> Alpha_ty ( trans rest1 rest2 ) | Alpha_ty _ , _ -> assert false | _ , Alpha_ty _ -> assert false | Theta_ty rest1 , Theta_ty rest2 -> Theta_ty ( trans rest1 rest2 ) | Theta_ty _ , _ -> assert false | _ , Theta_ty _ -> assert false | Any_ty rest1 , Any_ty rest2 -> Any_ty ( trans rest1 rest2 ) | Any_ty _ , _ -> assert false | _ , Any_ty _ -> assert false | Reader_ty rest1 , Reader_ty rest2 -> Reader_ty ( trans rest1 rest2 ) | Reader_ty _ , _ -> assert false | _ , Reader_ty _ -> assert false | Ignored_reader_ty rest1 , Ignored_reader_ty rest2 -> Ignored_reader_ty ( trans rest1 rest2 ) | Ignored_reader_ty _ , _ -> assert false | _ , Ignored_reader_ty _ -> assert false | Format_arg_ty ( ty1 , rest1 ) , Format_arg_ty ( ty2 , rest2 ) -> Format_arg_ty ( trans ty1 ty2 , trans rest1 rest2 ) | Format_arg_ty _ , _ -> assert false | _ , Format_arg_ty _ -> assert false | Format_subst_ty ( ty11 , ty12 , rest1 ) , Format_subst_ty ( ty21 , ty22 , rest2 ) -> let ty = trans ( symm ty12 ) ty21 in let _ , f2 , _ , f4 = fmtty_rel_det ty in let Refl = f2 Refl in let Refl = f4 Refl in Format_subst_ty ( ty11 , ty22 , trans rest1 rest2 ) | Format_subst_ty _ , _ -> assert false | _ , Format_subst_ty _ -> assert false | End_of_fmtty , End_of_fmtty -> End_of_fmtty | End_of_fmtty , _ -> assert false | _ , End_of_fmtty -> assert false
let rec fmtty_of_formatting_gen : type a b c d e f . ( a , b , c , d , e , f ) formatting_gen -> ( a , b , c , d , e , f ) fmtty = fun formatting_gen -> match formatting_gen with | Open_tag ( Format ( fmt , _ ) ) -> fmtty_of_fmt fmt | Open_box ( Format ( fmt , _ ) ) -> fmtty_of_fmt fmt type a b c d e f . ( a , b , c , d , e , f ) fmt -> ( a , b , c , d , e , f ) fmtty = fun fmtty -> match fmtty with | String ( pad , rest ) -> fmtty_of_padding_fmtty pad ( String_ty ( fmtty_of_fmt rest ) ) | Caml_string ( pad , rest ) -> fmtty_of_padding_fmtty pad ( String_ty ( fmtty_of_fmt rest ) ) | Int ( _ , pad , prec , rest ) -> let ty_rest = fmtty_of_fmt rest in let prec_ty = fmtty_of_precision_fmtty prec ( Int_ty ty_rest ) in fmtty_of_padding_fmtty pad prec_ty | Int32 ( _ , pad , prec , rest ) -> let ty_rest = fmtty_of_fmt rest in let prec_ty = fmtty_of_precision_fmtty prec ( Int32_ty ty_rest ) in fmtty_of_padding_fmtty pad prec_ty | Nativeint ( _ , pad , prec , rest ) -> let ty_rest = fmtty_of_fmt rest in let prec_ty = fmtty_of_precision_fmtty prec ( Nativeint_ty ty_rest ) in fmtty_of_padding_fmtty pad prec_ty | Int64 ( _ , pad , prec , rest ) -> let ty_rest = fmtty_of_fmt rest in let prec_ty = fmtty_of_precision_fmtty prec ( Int64_ty ty_rest ) in fmtty_of_padding_fmtty pad prec_ty | Float ( _ , pad , prec , rest ) -> let ty_rest = fmtty_of_fmt rest in let prec_ty = fmtty_of_precision_fmtty prec ( Float_ty ty_rest ) in fmtty_of_padding_fmtty pad prec_ty | Char rest -> Char_ty ( fmtty_of_fmt rest ) | Caml_char rest -> Char_ty ( fmtty_of_fmt rest ) | Bool ( pad , rest ) -> fmtty_of_padding_fmtty pad ( Bool_ty ( fmtty_of_fmt rest ) ) | Alpha rest -> Alpha_ty ( fmtty_of_fmt rest ) | Theta rest -> Theta_ty ( fmtty_of_fmt rest ) | Custom ( arity , _ , rest ) -> fmtty_of_custom arity ( fmtty_of_fmt rest ) | Reader rest -> Reader_ty ( fmtty_of_fmt rest ) | Format_arg ( _ , ty , rest ) -> Format_arg_ty ( ty , fmtty_of_fmt rest ) | Format_subst ( _ , ty , rest ) -> Format_subst_ty ( ty , ty , fmtty_of_fmt rest ) | Flush rest -> fmtty_of_fmt rest | String_literal ( _ , rest ) -> fmtty_of_fmt rest | Char_literal ( _ , rest ) -> fmtty_of_fmt rest | Scan_char_set ( _ , _ , rest ) -> String_ty ( fmtty_of_fmt rest ) | Scan_get_counter ( _ , rest ) -> Int_ty ( fmtty_of_fmt rest ) | Scan_next_char rest -> Char_ty ( fmtty_of_fmt rest ) | Ignored_param ( ign , rest ) -> fmtty_of_ignored_format ign rest | Formatting_lit ( _ , rest ) -> fmtty_of_fmt rest | Formatting_gen ( fmting_gen , rest ) -> concat_fmtty ( fmtty_of_formatting_gen fmting_gen ) ( fmtty_of_fmt rest ) | End_of_format -> End_of_fmtty type x y a b c d e f . ( a , x , y ) custom_arity -> ( a , b , c , d , e , f ) fmtty -> ( y , b , c , d , e , f ) fmtty = fun arity fmtty -> match arity with | Custom_zero -> fmtty | Custom_succ arity -> Any_ty ( fmtty_of_custom arity fmtty ) type x y a b c d e f . ( a , b , c , d , y , x ) ignored -> ( x , b , c , y , e , f ) fmt -> ( a , b , c , d , e , f ) fmtty = fun ign fmt -> match ign with | Ignored_char -> fmtty_of_fmt fmt | Ignored_caml_char -> fmtty_of_fmt fmt | Ignored_string _ -> fmtty_of_fmt fmt | Ignored_caml_string _ -> fmtty_of_fmt fmt | Ignored_int ( _ , _ ) -> fmtty_of_fmt fmt | Ignored_int32 ( _ , _ ) -> fmtty_of_fmt fmt | Ignored_nativeint ( _ , _ ) -> fmtty_of_fmt fmt | Ignored_int64 ( _ , _ ) -> fmtty_of_fmt fmt | Ignored_float ( _ , _ ) -> fmtty_of_fmt fmt | Ignored_bool _ -> fmtty_of_fmt fmt | Ignored_format_arg _ -> fmtty_of_fmt fmt | Ignored_format_subst ( _ , fmtty ) -> concat_fmtty fmtty ( fmtty_of_fmt fmt ) | Ignored_reader -> Ignored_reader_ty ( fmtty_of_fmt fmt ) | Ignored_scan_char_set _ -> fmtty_of_fmt fmt | Ignored_scan_get_counter _ -> fmtty_of_fmt fmt | Ignored_scan_next_char -> fmtty_of_fmt fmt type x a b c d e f . ( x , a ) padding -> ( a , b , c , d , e , f ) fmtty -> ( x , b , c , d , e , f ) fmtty = fun pad fmtty -> match pad with | No_padding -> fmtty | Lit_padding _ -> fmtty | Arg_padding _ -> Int_ty fmtty type x a b c d e f . ( x , a ) precision -> ( a , b , c , d , e , f ) fmtty -> ( x , b , c , d , e , f ) fmtty = fun prec fmtty -> match prec with | No_precision -> fmtty | Lit_precision _ -> fmtty | Arg_precision -> Int_ty fmtty
let type_padding : type a b c d e f x y . ( x , y ) padding -> ( a , b , c , d , e , f ) fmtty -> ( a , b , c , d , e , f ) padding_fmtty_ebb = fun pad fmtty -> match pad , fmtty with | No_padding , _ -> Padding_fmtty_EBB ( No_padding , fmtty ) | Lit_padding ( padty , w ) , _ -> Padding_fmtty_EBB ( Lit_padding ( padty , w ) , fmtty ) | Arg_padding padty , Int_ty rest -> Padding_fmtty_EBB ( Arg_padding padty , rest ) | _ -> raise Type_mismatch
let type_padprec : type a b c d e f x y z . ( x , y ) padding -> ( y , z ) precision -> ( a , b , c , d , e , f ) fmtty -> ( a , b , c , d , e , f ) padprec_fmtty_ebb = fun pad prec fmtty -> match prec , type_padding pad fmtty with | No_precision , Padding_fmtty_EBB ( pad , rest ) -> Padprec_fmtty_EBB ( pad , No_precision , rest ) | Lit_precision p , Padding_fmtty_EBB ( pad , rest ) -> Padprec_fmtty_EBB ( pad , Lit_precision p , rest ) | Arg_precision , Padding_fmtty_EBB ( pad , Int_ty rest ) -> Padprec_fmtty_EBB ( pad , Arg_precision , rest ) | _ , Padding_fmtty_EBB ( _ , _ ) -> raise Type_mismatch
let rec type_format : type a1 b1 c1 d1 e1 f1 a2 b2 c2 d2 e2 f2 . ( a1 , b1 , c1 , d1 , e1 , f1 ) fmt -> ( a2 , b2 , c2 , d2 , e2 , f2 ) fmtty -> ( a2 , b2 , c2 , d2 , e2 , f2 ) fmt = fun fmt fmtty -> match type_format_gen fmt fmtty with | Fmt_fmtty_EBB ( fmt ' , End_of_fmtty ) -> fmt ' | _ -> raise Type_mismatch type a1 b1 c1 d1 e1 f1 a2 b2 c2 d2 e2 f2 . ( a1 , b1 , c1 , d1 , e1 , f1 ) fmt -> ( a2 , b2 , c2 , d2 , e2 , f2 ) fmtty -> ( a2 , b2 , c2 , d2 , e2 , f2 ) fmt_fmtty_ebb = fun fmt fmtty -> match fmt , fmtty with | Char fmt_rest , Char_ty fmtty_rest -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Char fmt ' , fmtty ' ) | Caml_char fmt_rest , Char_ty fmtty_rest -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Caml_char fmt ' , fmtty ' ) | String ( pad , fmt_rest ) , _ -> ( match type_padding pad fmtty with | Padding_fmtty_EBB ( pad , String_ty fmtty_rest ) -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( String ( pad , fmt ' ) , fmtty ' ) | Padding_fmtty_EBB ( _ , _ ) -> raise Type_mismatch ) | Caml_string ( pad , fmt_rest ) , _ -> ( match type_padding pad fmtty with | Padding_fmtty_EBB ( pad , String_ty fmtty_rest ) -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Caml_string ( pad , fmt ' ) , fmtty ' ) | Padding_fmtty_EBB ( _ , _ ) -> raise Type_mismatch ) | Int ( iconv , pad , prec , fmt_rest ) , _ -> ( match type_padprec pad prec fmtty with | Padprec_fmtty_EBB ( pad , prec , Int_ty fmtty_rest ) -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Int ( iconv , pad , prec , fmt ' ) , fmtty ' ) | Padprec_fmtty_EBB ( _ , _ , _ ) -> raise Type_mismatch ) | Int32 ( iconv , pad , prec , fmt_rest ) , _ -> ( match type_padprec pad prec fmtty with | Padprec_fmtty_EBB ( pad , prec , Int32_ty fmtty_rest ) -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Int32 ( iconv , pad , prec , fmt ' ) , fmtty ' ) | Padprec_fmtty_EBB ( _ , _ , _ ) -> raise Type_mismatch ) | Nativeint ( iconv , pad , prec , fmt_rest ) , _ -> ( match type_padprec pad prec fmtty with | Padprec_fmtty_EBB ( pad , prec , Nativeint_ty fmtty_rest ) -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Nativeint ( iconv , pad , prec , fmt ' ) , fmtty ' ) | Padprec_fmtty_EBB ( _ , _ , _ ) -> raise Type_mismatch ) | Int64 ( iconv , pad , prec , fmt_rest ) , _ -> ( match type_padprec pad prec fmtty with | Padprec_fmtty_EBB ( pad , prec , Int64_ty fmtty_rest ) -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Int64 ( iconv , pad , prec , fmt ' ) , fmtty ' ) | Padprec_fmtty_EBB ( _ , _ , _ ) -> raise Type_mismatch ) | Float ( fconv , pad , prec , fmt_rest ) , _ -> ( match type_padprec pad prec fmtty with | Padprec_fmtty_EBB ( pad , prec , Float_ty fmtty_rest ) -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Float ( fconv , pad , prec , fmt ' ) , fmtty ' ) | Padprec_fmtty_EBB ( _ , _ , _ ) -> raise Type_mismatch ) | Bool ( pad , fmt_rest ) , _ -> ( match type_padding pad fmtty with | Padding_fmtty_EBB ( pad , Bool_ty fmtty_rest ) -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Bool ( pad , fmt ' ) , fmtty ' ) | Padding_fmtty_EBB ( _ , _ ) -> raise Type_mismatch ) | Flush fmt_rest , fmtty_rest -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Flush fmt ' , fmtty ' ) | String_literal ( str , fmt_rest ) , fmtty_rest -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( String_literal ( str , fmt ' ) , fmtty ' ) | Char_literal ( chr , fmt_rest ) , fmtty_rest -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Char_literal ( chr , fmt ' ) , fmtty ' ) | ( Format_arg ( pad_opt , sub_fmtty , fmt_rest ) , Format_arg_ty ( sub_fmtty ' , fmtty_rest ) ) -> if Fmtty_EBB sub_fmtty <> Fmtty_EBB sub_fmtty ' then raise Type_mismatch ; let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Format_arg ( pad_opt , sub_fmtty ' , fmt ' ) , fmtty ' ) | ( Format_subst ( pad_opt , sub_fmtty , fmt_rest ) , Format_subst_ty ( sub_fmtty1 , _sub_fmtty2 , fmtty_rest ) ) -> if Fmtty_EBB ( erase_rel sub_fmtty ) <> Fmtty_EBB ( erase_rel sub_fmtty1 ) then raise Type_mismatch ; let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest ( erase_rel fmtty_rest ) in Fmt_fmtty_EBB ( Format_subst ( pad_opt , sub_fmtty1 , fmt ' ) , fmtty ' ) | Alpha fmt_rest , Alpha_ty fmtty_rest -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Alpha fmt ' , fmtty ' ) | Theta fmt_rest , Theta_ty fmtty_rest -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Theta fmt ' , fmtty ' ) | Formatting_lit ( formatting_lit , fmt_rest ) , fmtty_rest -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Formatting_lit ( formatting_lit , fmt ' ) , fmtty ' ) | Formatting_gen ( formatting_gen , fmt_rest ) , fmtty_rest -> type_formatting_gen formatting_gen fmt_rest fmtty_rest | Reader fmt_rest , Reader_ty fmtty_rest -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Reader fmt ' , fmtty ' ) | Scan_char_set ( width_opt , char_set , fmt_rest ) , String_ty fmtty_rest -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Scan_char_set ( width_opt , char_set , fmt ' ) , fmtty ' ) | Scan_get_counter ( counter , fmt_rest ) , Int_ty fmtty_rest -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt_rest fmtty_rest in Fmt_fmtty_EBB ( Scan_get_counter ( counter , fmt ' ) , fmtty ' ) | Ignored_param ( ign , rest ) , fmtty_rest -> type_ignored_param ign rest fmtty_rest | End_of_format , fmtty_rest -> Fmt_fmtty_EBB ( End_of_format , fmtty_rest ) | _ -> raise Type_mismatch type a1 a3 b1 b3 c1 c3 d1 d3 e1 e2 e3 f1 f2 f3 . ( a1 , b1 , c1 , d1 , e1 , f1 ) formatting_gen -> ( f1 , b1 , c1 , e1 , e2 , f2 ) fmt -> ( a3 , b3 , c3 , d3 , e3 , f3 ) fmtty -> ( a3 , b3 , c3 , d3 , e3 , f3 ) fmt_fmtty_ebb = fun formatting_gen fmt0 fmtty0 -> match formatting_gen with | Open_tag ( Format ( fmt1 , str ) ) -> let ( Fmt_fmtty_EBB ( fmt2 , fmtty2 ) ) = type_format_gen fmt1 fmtty0 in let ( Fmt_fmtty_EBB ( fmt3 , fmtty3 ) ) = type_format_gen fmt0 fmtty2 in Fmt_fmtty_EBB ( Formatting_gen ( Open_tag ( Format ( fmt2 , str ) ) , fmt3 ) , fmtty3 ) | Open_box ( Format ( fmt1 , str ) ) -> let ( Fmt_fmtty_EBB ( fmt2 , fmtty2 ) ) = type_format_gen fmt1 fmtty0 in let ( Fmt_fmtty_EBB ( fmt3 , fmtty3 ) ) = type_format_gen fmt0 fmtty2 in Fmt_fmtty_EBB ( Formatting_gen ( Open_box ( Format ( fmt2 , str ) ) , fmt3 ) , fmtty3 ) type p q x y z t u v a b c d e f . ( x , y , z , t , q , p ) ignored -> ( p , y , z , q , u , v ) fmt -> ( a , b , c , d , e , f ) fmtty -> ( a , b , c , d , e , f ) fmt_fmtty_ebb = fun ign fmt fmtty -> match ign with | Ignored_char as ign ' -> type_ignored_param_one ign ' fmt fmtty | Ignored_caml_char as ign ' -> type_ignored_param_one ign ' fmt fmtty | Ignored_string _ as ign ' -> type_ignored_param_one ign ' fmt fmtty | Ignored_caml_string _ as ign ' -> type_ignored_param_one ign ' fmt fmtty | Ignored_int _ as ign ' -> type_ignored_param_one ign ' fmt fmtty | Ignored_int32 _ as ign ' -> type_ignored_param_one ign ' fmt fmtty | Ignored_nativeint _ as ign ' -> type_ignored_param_one ign ' fmt fmtty | Ignored_int64 _ as ign ' -> type_ignored_param_one ign ' fmt fmtty | Ignored_float _ as ign ' -> type_ignored_param_one ign ' fmt fmtty | Ignored_bool _ as ign ' -> type_ignored_param_one ign ' fmt fmtty | Ignored_scan_char_set _ as ign ' -> type_ignored_param_one ign ' fmt fmtty | Ignored_scan_get_counter _ as ign ' -> type_ignored_param_one ign ' fmt fmtty | Ignored_scan_next_char as ign ' -> type_ignored_param_one ign ' fmt fmtty | Ignored_format_arg ( pad_opt , sub_fmtty ) -> type_ignored_param_one ( Ignored_format_arg ( pad_opt , sub_fmtty ) ) fmt fmtty | Ignored_format_subst ( pad_opt , sub_fmtty ) -> let ( Fmtty_fmt_EBB ( sub_fmtty ' , Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) ) = type_ignored_format_substitution sub_fmtty fmt fmtty in Fmt_fmtty_EBB ( Ignored_param ( Ignored_format_subst ( pad_opt , sub_fmtty ' ) , fmt ' ) , fmtty ' ) | Ignored_reader -> ( match fmtty with | Ignored_reader_ty fmtty_rest -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt fmtty_rest in Fmt_fmtty_EBB ( Ignored_param ( Ignored_reader , fmt ' ) , fmtty ' ) | _ -> raise Type_mismatch ) type a1 a2 b1 b2 c1 c2 d1 d2 e1 e2 f1 f2 . ( a2 , b2 , c2 , d2 , d2 , a2 ) ignored -> ( a1 , b1 , c1 , d1 , e1 , f1 ) fmt -> ( a2 , b2 , c2 , d2 , e2 , f2 ) fmtty -> ( a2 , b2 , c2 , d2 , e2 , f2 ) fmt_fmtty_ebb = fun ign fmt fmtty -> let ( Fmt_fmtty_EBB ( fmt ' , fmtty ' ) ) = type_format_gen fmt fmtty in Fmt_fmtty_EBB ( Ignored_param ( ign , fmt ' ) , fmtty ' ) type w x y z p s t u a b c d e f . ( w , x , y , z , s , p ) fmtty -> ( p , x , y , s , t , u ) fmt -> ( a , b , c , d , e , f ) fmtty -> ( a , b , c , d , e , f ) fmtty_fmt_ebb = fun sub_fmtty fmt fmtty -> match sub_fmtty , fmtty with | Char_ty sub_fmtty_rest , Char_ty fmtty_rest -> let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution sub_fmtty_rest fmt fmtty_rest in Fmtty_fmt_EBB ( Char_ty sub_fmtty_rest ' , fmt ' ) | String_ty sub_fmtty_rest , String_ty fmtty_rest -> let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution sub_fmtty_rest fmt fmtty_rest in Fmtty_fmt_EBB ( String_ty sub_fmtty_rest ' , fmt ' ) | Int_ty sub_fmtty_rest , Int_ty fmtty_rest -> let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution sub_fmtty_rest fmt fmtty_rest in Fmtty_fmt_EBB ( Int_ty sub_fmtty_rest ' , fmt ' ) | Int32_ty sub_fmtty_rest , Int32_ty fmtty_rest -> let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution sub_fmtty_rest fmt fmtty_rest in Fmtty_fmt_EBB ( Int32_ty sub_fmtty_rest ' , fmt ' ) | Nativeint_ty sub_fmtty_rest , Nativeint_ty fmtty_rest -> let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution sub_fmtty_rest fmt fmtty_rest in Fmtty_fmt_EBB ( Nativeint_ty sub_fmtty_rest ' , fmt ' ) | Int64_ty sub_fmtty_rest , Int64_ty fmtty_rest -> let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution sub_fmtty_rest fmt fmtty_rest in Fmtty_fmt_EBB ( Int64_ty sub_fmtty_rest ' , fmt ' ) | Float_ty sub_fmtty_rest , Float_ty fmtty_rest -> let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution sub_fmtty_rest fmt fmtty_rest in Fmtty_fmt_EBB ( Float_ty sub_fmtty_rest ' , fmt ' ) | Bool_ty sub_fmtty_rest , Bool_ty fmtty_rest -> let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution sub_fmtty_rest fmt fmtty_rest in Fmtty_fmt_EBB ( Bool_ty sub_fmtty_rest ' , fmt ' ) | Alpha_ty sub_fmtty_rest , Alpha_ty fmtty_rest -> let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution sub_fmtty_rest fmt fmtty_rest in Fmtty_fmt_EBB ( Alpha_ty sub_fmtty_rest ' , fmt ' ) | Theta_ty sub_fmtty_rest , Theta_ty fmtty_rest -> let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution sub_fmtty_rest fmt fmtty_rest in Fmtty_fmt_EBB ( Theta_ty sub_fmtty_rest ' , fmt ' ) | Reader_ty sub_fmtty_rest , Reader_ty fmtty_rest -> let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution sub_fmtty_rest fmt fmtty_rest in Fmtty_fmt_EBB ( Reader_ty sub_fmtty_rest ' , fmt ' ) | Ignored_reader_ty sub_fmtty_rest , Ignored_reader_ty fmtty_rest -> let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution sub_fmtty_rest fmt fmtty_rest in Fmtty_fmt_EBB ( Ignored_reader_ty sub_fmtty_rest ' , fmt ' ) | ( Format_arg_ty ( sub2_fmtty , sub_fmtty_rest ) , Format_arg_ty ( sub2_fmtty ' , fmtty_rest ) ) -> if Fmtty_EBB sub2_fmtty <> Fmtty_EBB sub2_fmtty ' then raise Type_mismatch ; let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution sub_fmtty_rest fmt fmtty_rest in Fmtty_fmt_EBB ( Format_arg_ty ( sub2_fmtty ' , sub_fmtty_rest ' ) , fmt ' ) | ( Format_subst_ty ( sub1_fmtty , sub2_fmtty , sub_fmtty_rest ) , Format_subst_ty ( sub1_fmtty ' , sub2_fmtty ' , fmtty_rest ) ) -> if Fmtty_EBB ( erase_rel sub1_fmtty ) <> Fmtty_EBB ( erase_rel sub1_fmtty ' ) then raise Type_mismatch ; if Fmtty_EBB ( erase_rel sub2_fmtty ) <> Fmtty_EBB ( erase_rel sub2_fmtty ' ) then raise Type_mismatch ; let sub_fmtty ' = trans ( symm sub1_fmtty ' ) sub2_fmtty ' in let _ , f2 , _ , f4 = fmtty_rel_det sub_fmtty ' in let Refl = f2 Refl in let Refl = f4 Refl in let ( Fmtty_fmt_EBB ( sub_fmtty_rest ' , fmt ' ) ) = type_ignored_format_substitution ( erase_rel sub_fmtty_rest ) fmt fmtty_rest in Fmtty_fmt_EBB ( Format_subst_ty ( sub1_fmtty ' , sub2_fmtty ' , symm sub_fmtty_rest ' ) , fmt ' ) | End_of_fmtty , fmtty -> Fmtty_fmt_EBB ( End_of_fmtty , type_format_gen fmt fmtty ) | _ -> raise Type_mismatch
let recast : type a1 b1 c1 d1 e1 f1 a2 b2 c2 d2 e2 f2 . ( a1 , b1 , c1 , d1 , e1 , f1 ) fmt -> ( a1 , b1 , c1 , d1 , e1 , f1 , a2 , b2 , c2 , d2 , e2 , f2 ) fmtty_rel -> ( a2 , b2 , c2 , d2 , e2 , f2 ) fmt = fun fmt fmtty -> type_format fmt ( erase_rel ( symm fmtty ) )
let fix_padding padty width str = let len = String . length str in let width , padty = ( abs width , if width < 0 then Left else padty ) in if width <= len then str else let res = Bytes . make width ( if padty = Zeros then ' 0 ' else ' ' ) in begin match padty with | Left -> String . blit str 0 res 0 len | Right -> String . blit str 0 res ( width - len ) len | Zeros when len > 0 && ( str . [ 0 ] = ' ' + || str . [ 0 ] = ' ' - || str . [ 0 ] = ' ' ) -> Bytes . set res 0 str . [ 0 ] ; String . blit str 1 res ( width - len + 1 ) ( len - 1 ) | Zeros when len > 1 && str . [ 0 ] = ' 0 ' && ( str . [ 1 ] = ' x ' || str . [ 1 ] = ' X ' ) -> Bytes . set res 1 str . [ 1 ] ; String . blit str 2 res ( width - len + 2 ) ( len - 2 ) | Zeros -> String . blit str 0 res ( width - len ) len end ; Bytes . unsafe_to_string res