text stringlengths 0 601k |
|---|
let string_to_channel use_unix oc s = if not use_unix then output_string oc s else let s = Bytes . unsafe_of_string s in unix_write ( Unix . descr_of_out_channel oc ) s 0 ( Bytes . length s ) |
let dst_for sout = if sout then ` Buffer ( Buffer . create 512 ) else ` Channel stdout |
let src_for inf sin use_unix = try let ic = if inf = " " - then stdin else open_in inf in if sin then ` String ( string_of_channel use_unix ic ) else ` Channel ic with Sys_error e -> log " % s \ n " e ; exit 1 |
let close_src src = try match src with ` Channel ic when ic <> stdin -> close_in ic | _ -> ( ) with | Sys_error e -> log " % s \ n " e ; exit 1 |
let src_for_unix inf = try if inf = " " - then Unix . stdin else Unix . ( openfile inf [ O_RDONLY ] 0 ) with | Unix . Unix_error ( e , _ , v ) -> log " % s : % s \ n " ( Unix . error_message e ) v ; exit 1 |
let close_src_unix fd = try if fd <> Unix . stdin then Unix . close fd with |
let rec encode_unix fd s e v = match Uutf . encode e v with ` Ok -> ( ) unix_write fd s 0 ( Bytes . length s - Uutf . Manual . dst_rem e ) ; Uutf . Manual . dst e s 0 ( Bytes . length s ) ; encode_unix fd s e ` Await |
let dump_decode inf d v = ( match v with ` Malformed _ -> input_malformed := true | _ -> ( ) ) ; ( pp_decode inf d ) Format . std_formatter v |
let dump_ inf encoding nln src = let rec loop inf d = match Uutf . decode d with ` Await -> assert false | v -> dump_decode inf d v ; if v <> ` End then loop inf d in loop inf ( Uutf . decoder ? nln ? encoding src ) |
let dump_unix inf encoding nln usize fd = let rec loop fd s d = match Uutf . decode d with | ` Await -> let rc = unix_read fd s 0 ( Bytes . length s ) in Uutf . Manual . src d s 0 rc ; loop fd s d | v -> dump_decode inf d v ; if v <> ` End then loop fd s d in loop fd ( Bytes . create usize ) ( Uutf . decoder ? nln ? en... |
let dump inf sin use_unix usize ie nln = if sin || not use_unix then dump_ inf ie nln ( src_for inf sin use_unix ) else dump_unix inf ie nln usize ( src_for_unix inf ) |
let guess inf = let d = Uutf . decoder ( src_for inf false false ) in ignore ( Uutf . decode d ) ; Format . printf " % s . " @ ( Uutf . encoding_to_string ( Uutf . decoder_encoding d ) ) |
let decode_ inf encoding nln src = let malformed = log_malformed inf in let rec loop d = match Uutf . decode d with ` Await -> assert false | ` Uchar _ -> loop d | ` End -> ( ) | ` Malformed _ as v -> malformed d v ; loop d in loop ( Uutf . decoder ? nln ? encoding src ) ; close_src src |
let decode_unix inf encoding nln usize fd = let malformed = log_malformed inf in let rec loop fd s d = match Uutf . decode d with | ` Uchar _ -> loop fd s d | ` End -> ( ) | ` Malformed _ as v -> malformed d v ; loop fd s d | ` Await -> let rc = unix_read fd s 0 ( Bytes . length s ) in Uutf . Manual . src d s 0 rc ; lo... |
let decode inf sin use_unix usize ie nln = if sin || not use_unix then decode_ inf ie nln ( src_for inf sin use_unix ) else decode_unix inf ie nln usize ( src_for_unix inf ) |
let u_surrogate_count = 0xDFFF - 0xD800 + 1 |
let uchar_count = ( 0x10FFFF + 1 ) - u_surrogate_count |
let r_uchar ( ) = let n = Random . int uchar_count in Uchar . of_int ( if n > 0xD7FF then n + u_surrogate_count else n ) |
let r_text encoding encode_f rcount = encode_f ( ` Uchar Uutf . u_bom ) ; for i = 1 to rcount do encode_f ( ` Uchar ( r_uchar ( ) ) ) done ; encode_f ` End |
let encode_f encoding dst = let e = Uutf . encoder encoding dst in fun v -> match Uutf . encode e v with ` Ok -> ( ) | ` Partial -> assert false |
let encode_f_unix usize encoding fd = let e , s = Uutf . encoder encoding ` Manual , Bytes . create usize in Uutf . Manual . dst e s 0 ( Bytes . length s ) ; encode_unix fd s e |
let r_encode sout use_unix usize rseed rcount oe = let rseed = match rseed with | None -> Random . self_init ( ) ; Random . int ( 1 lsl 30 - 1 ) | Some rseed -> rseed in let dst = dst_for sout in let oe = match oe with None -> ` UTF_8 | Some enc -> enc in let encode_f = if sout || not use_unix then encode_f oe dst else... |
let trip_ inf nln ie oe src dst = let malformed d v e = log_malformed inf d v ; ignore ( Uutf . encode e ( ` Uchar Uutf . u_rep ) ) in let rec loop d e = function ` Await -> assert false | ` Uchar _ as v -> ignore ( Uutf . encode e v ) ; loop d e ( Uutf . decode d ) | ` End -> ignore ( Uutf . encode e ` End ) | ` Malfo... |
let trip_unix inf usize nln ie oe fdi fdo = let malformed d v e = log_malformed inf d v ; ignore ( Uutf . encode e ( ` Uchar Uutf . u_rep ) ) in let rec loop fdi fdo ds es d e = function | ` Uchar _ as v -> encode_unix fdo es e v ; loop fdi fdo ds es d e ( Uutf . decode d ) | ` End -> encode_unix fdo es e ` End | ` Mal... |
let trip inf sin sout use_unix usize ie oe nln = let src = src_for inf sin use_unix in let dst = dst_for sout in if sin || sout || not use_unix then trip_ inf nln ie oe src dst else trip_unix inf usize nln ie oe ( src_for_unix inf ) Unix . stdout ; match dst with ` Channel _ -> ( ) | ` Buffer b -> string_to_channel use... |
let do_cmd cmd inf sin sout use_unix usize ie oe nln rseed rcount = match cmd with | ` Ascii -> dump inf sin use_unix usize ie nln | ` Guess -> guess inf | ` Decode -> decode inf sin use_unix usize ie nln | ` Encode -> r_encode sout use_unix usize rseed rcount oe | ` Trip -> trip inf sin sout use_unix usize ie oe nln |
let enc_enum = [ " UTF - 8 " , ` UTF_8 ; " UTF - 16 " , ` UTF_16 ; " UTF - 16LE " , ` UTF_16LE ; " UTF - 16BE " , ` UTF_16BE ; ] |
let decode_enc_enum = ( " ASCII " , ` US_ASCII ) :: ( " latin1 " , ` ISO_8859_1 ) :: enc_enum |
let ienc = let doc = str " Decoded ( input ) encoding , must % s . If unspecified the encoding is guessed . " ( Arg . doc_alts_enum decode_enc_enum ) in Arg . ( value & opt ( some ( enum decode_enc_enum ) ) None & info [ " d " ; " input - encoding " ] ~ doc ) |
let oenc = let doc = str " Encoded ( output ) encoding , must % s . If unspecified the output encoding is the same as the input encoding except for ASCII and latin1 where UTF - 8 is output . " ( Arg . doc_alts_enum enc_enum ) in Arg . ( value & opt ( some ( enum enc_enum ) ) None & info [ " e " ; " output - encoding " ... |
let nln = let lf = Uchar . of_int 0x000A in let nln_enum = [ " ascii " , ` ASCII lf ; " nlf " , ` NLF lf ; " readline " , ` Readline lf ] in let doc = str " New line normalization to U + 000A , must % s . ascii normalizes CR ( U + 000D ) and CRLF ( < U + 000D , U + 000A ) . > nlf normalizes like ascii plus NEL ( U + 00... |
let sin = let doc = " Input everything in a string and decode the string . " in Arg . ( value & flag & info [ " input - string " ] ~ doc ) |
let sout = let doc = " Encode everything in a string and output the string . " in Arg . ( value & flag & info [ " output - string " ] ~ doc ) |
let use_unix = let doc = " Use Unix IO . " in Arg . ( value & flag & info [ " use - unix " ] ~ doc ) |
let usize = let doc = " Unix IO buffer sizes in bytes . " in Arg . ( value & opt int unix_buffer_size & info [ " unix - size " ] ~ doc ) |
let nat = let parse s = try let v = int_of_string s in if v > 0 then ` Ok v else failwith ( str " % s must be > 0 " s ) with Failure e -> ` Error e in parse , Format . pp_print_int |
let rseed = let doc = " Random seed . " in Arg . ( value & opt ( some nat ) None & info [ " rseed " ] ~ doc ) |
let rcount = let doc = " Number of random characters to generate . " in Arg . ( value & opt nat 1_000_000 & info [ " rcount " ] ~ doc ) |
let file = let doc = " The input file . Reads from stdin if unspecified . " in Arg . ( value & pos 0 string " " - & info [ ] ~ doc ~ docv " : FILE " ) |
let cmd = let doc = " Output the input text as Unicode scalar values or malformed sequences , one per line , in the US - ASCII charset with their position ( see POSITION INFORMATION for more details ) . " in let ascii = ` Ascii , Arg . info [ " a " ; " ascii " ] ~ doc in let doc = " Only guess an UTF encoding . The res... |
let cmd = let doc = " Recode UTF { - 8 , 16 , 16LE , 16BE } and latin1 from stdin to stdout . " in let man = [ ` S " DESCRIPTION " ; ` P " ( $ tname ) inputs Unicode text from stdin and rewrites it to stdout in various ways . If no input encoding is specified , it is guessed . If no output encoding is specified , the i... |
let ( ) = match Cmd . eval_value cmd with |
let ( >> ) f g x = g ( f x ) |
let ( ) >>> f g x y = g ( f x y ) |
let flip f x y = f y x |
let double x = ( x , x ) |
let k_comb x _y = x |
let s_comb x y z = x z ( y z ) ; ; |
module ExStream = struct open Stream let rec take n s = if n > 0 then icons ( next s ) @@ slazy ( fun _ -> take ( n - 1 ) s ) else sempty let rec take_int32 n s = if n > 0l then icons ( next s ) @@ slazy ( fun _ -> take_int32 ( Int32 . sub n 1l ) s ) else sempty let rec take_while f s = slazy ( fun _ -> match peek s wi... |
let list_length_int32 l = List . length l |> Int32 . of_int |
let list_unfold cons pred start = let rec loop step acc = if pred step then acc else let ( value , step ' ) = cons step in loop step ' ( value :: acc ) in loop start [ ] |
let range ( ? start = 0 ) stop = list_unfold ( pred >> double ) ( ( ) == start ) stop |
let str_length_int32 s = Int32 . of_int @@ String . length s |
let try_finally action finally = try let result = action ( ) in finally ( ) ; result ; with x -> finally ( ) ; raise x |
let with_resource resource action post = try_finally ( fun ( ) -> action resource ) ( fun ( ) -> post resource ) |
let with_file_in filename action = with_resource ( open_in filename ) action close_in |
let with_file_out filename action = with_resource ( open_out filename ) action close_out |
type buffer = { mutable buffer : string ; mutable position : int ; mutable length : int ; initial_buffer : string } |
let buffer_change_substring buf pos str = let b = buffer_of_t buf in String . blit str 0 b . buffer pos ( String . length str ) |
type shall_we = ( parameter -> bool ) |
type step_with_side_effects = step * S . PH . B . PB . CI . Po . K . side_effect |
type trace = { compressed_trace : step_with_side_effects list option ; pretrace : step list ; with_potential_ambiguity : bool } |
type trace_runtime_info = profiling_info Trace . Simulation_info . t |
type ' a with_handlers = parameter -> ? shall_we_compute : shall_we -> ? shall_we_compute_profiling_information : shall_we -> ? print_if_zero : shall_we -> kappa_handler -> profiling_info -> error_log -> ' a |
type ' a zeroary = ( error_log * profiling_info * ' a ) with_handlers |
type ( ' a , ' b ) unary = ( ' a -> error_log * profiling_info * ' b ) with_handlers |
type ( ' a , ' b , ' c ) binary = ( ' a -> ' b -> error_log * profiling_info * ' c ) with_handlers |
type ( ' a , ' b , ' c , ' d ) ternary = ( ' a -> ' b -> ' c -> error_log * profiling_info * ' d ) with_handlers |
type ( ' a , ' b , ' c , ' d , ' e ) quaternary = ( ' a -> ' b -> ' c -> ' d -> error_log * profiling_info * ' e ) with_handlers |
type ( ' a , ' b , ' c , ' d , ' e , ' f ) quinternary = ( ' a -> ' b -> ' c -> ' d -> ' e -> error_log * profiling_info * ' f ) with_handlers |
type ( ' a , ' b , ' c , ' d , ' e , ' f , ' g ) sexternary = ( ' a -> ' b -> ' c -> ' d -> ' e -> ' f -> error_log * profiling_info * ' g ) with_handlers |
let ( we_shall : shall_we ) = ( fun _ -> true ) |
let ( we_shall_not : shall_we ) = ( fun _ -> false ) |
let get_pretrace_of_trace trace = trace . pretrace |
let size_of_pretrace trace = List . length ( get_pretrace_of_trace trace ) |
let may_initial_sites_be_ambiguous trace = trace . with_potential_ambiguity |
let set_ambiguity_level trace x = { trace with with_potential_ambiguity = x } |
let _set_pretrace trace x = { trace with pretrace = x } |
let _set_compressed_trace trace x = { trace with compressed_trace = x } |
let get_compressed_trace trace = match trace . compressed_trace with | Some x -> x | None -> List . rev_map ( fun x -> x , [ ] ) ( List . rev ( get_pretrace_of_trace trace ) ) |
let is_compressed_trace trace = trace . compressed_trace != None |
let trace_of_pretrace_with_ambiguity with_ambiguity pretrace = { pretrace = pretrace ; compressed_trace = None ; with_potential_ambiguity = with_ambiguity ; } |
let trace_of_pretrace = trace_of_pretrace_with_ambiguity true |
let build_compressed_trace x y = { compressed_trace = Some y ; pretrace = x ; with_potential_ambiguity = false } |
let _extend_trace_with_dummy_side_effects l = List . rev_map ( fun a -> a , [ ] ) ( List . rev l ) |
let print_pretrace parameter _handler = Loggers . fprintf ( S . PH . B . PB . CI . Po . K . H . get_out_channel parameter ) " [ @< v >% a ] . " @@ ( Pp . list Pp . space ( Trace . print_step ~ compact : true ? env : None ) ) |
let print_trace parameter handler trace = print_pretrace parameter handler ( get_pretrace_of_trace trace ) |
let transform_trace_gen f log_message debug_message profiling_event = ( fun parameters ( ? shall_we_compute = we_shall ) ? shall_we_compute_profiling_information ( : _ ) ( ? print_if_zero = we_shall ) kappa_handler profiling_info error trace -> if shall_we_compute parameters then let error , profiling_info = StoryProfi... |
type kind = | May_add_ambiguities | Neutral |
let handle_ambiguities kind b = match kind with | Neutral -> b | May_add_ambiguities -> true |
type ambiquities_precondition = Do_not_care | Require_the_abscence_of_ambiguity |
let must_we_solve_ambiguity _parameters x = match x with | Do_not_care -> false | Require_the_abscence_of_ambiguity -> true |
let monadic_lift f = ( fun _ _ log_info error t -> let t ' = f t in error , log_info , ( t ' , List . length t - List . length t ' ) ) |
let _dummy_profiling = ( fun _ p -> p ) |
let disambiguate = transform_trace_gen ( monadic_lift S . PH . B . PB . CI . Po . K . disambiguate ) ( Some " \ t - alpha - conversion " ) " Trace after having renames agents :\ n " StoryProfiling . Agent_ids_disambiguation |
let make_unambiguous parameters ( ? shall_we_compute = we_shall ) ( ? shall_we_compute_profiling_information = we_shall_not ) ( ? print_if_zero = we_shall_not ) kappa_handler profiling_info error trace = if may_initial_sites_be_ambiguous trace then let error , profiling_info , trace ' = disambiguate parameters ~ shall_... |
let lift_to_care_about_ambiguities f requirement effect = ( fun parameters ( ? shall_we_compute = we_shall ) ( ? shall_we_compute_profiling_information = we_shall ) ( ? print_if_zero = we_shall ) kappa_handler profiling_info error trace -> if shall_we_compute parameters then let error , profiling_info , trace = if must... |
let split_init = lift_to_care_about_ambiguities ( transform_trace_gen ( monadic_lift S . PH . B . PB . CI . Po . K . split_init ) ( Some " \ t - splitting initial events " ) " Trace after having split initial events :\ n " StoryProfiling . Decompose_initial_state ) Do_not_care Neutral |
let cut = lift_to_care_about_ambiguities ( transform_trace_gen S . PH . B . PB . CI . Po . cut ( Some " \ t - cutting concurrent events " ) " Trace after having removed concurrent events :\ n " StoryProfiling . Partial_order_reduction ) Require_the_abscence_of_ambiguity Neutral |
let on_the_fly_cut_finalize cut_state = fst ( S . PH . B . PB . CI . Po . finalize_cut cut_state ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.