text
stringlengths
12
786k
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 ...
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 guess...
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_wh...
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 , pr...
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 ' = disamb...
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 , profilin...
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 Ne...
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 )
let cut_rev_trace rev_trace = on_the_fly_cut_finalize ( List . fold_left on_the_fly_cut_step on_the_fly_cut_init rev_trace )
let remove_obs_before _parameter _handler log_info error last_eid trace = error , log_info , ( let rec aux l score output = match l with [ ] -> List . rev output , score | t :: q -> if Trace . step_is_obs t then match Trace . simulation_info_of_step t with None -> aux q score ( t :: output...
let remove_obs_before parameter handler log_info error last_info trace = lift_to_care_about_ambiguities ( transform_trace_gen ( fun parameter handler log_info error -> remove_obs_before parameter handler log_info error last_info ) ( Some " \ t - Removing already visited observable hits " ) " Trace a...
let remove_obs_before parameter ? shall_we_compute ( : _ ) ? shall_we_compute_profiling_information ( : _ ) ? print_if_zero ( : _ ) handler log_info error last_info trace = match last_info with | None -> error , log_info , trace | Some l -> let last = List . fold_left ( fun result x ...
let fill_siphon = lift_to_care_about_ambiguities ( transform_trace_gen ( monadic_lift S . PH . B . PB . CI . Po . K . fill_siphon ) ( Some " \ t - detecting siphons " ) " Trace after having detected siphons :\ n " StoryProfiling . Siphon_detection ) Require_the_abscence_of_ambigu...
let ( remove_events_after_last_obs : ( trace , trace ) unary ) = lift_to_care_about_ambiguities ( transform_trace_gen ( monadic_lift ( ( List_util . remove_suffix_after_last_occurrence Trace . step_is_obs ) ) ) ( Some " \ t - removing events occurring after the last observable " ) ...
let remove_pseudo_inverse_events = lift_to_care_about_ambiguities ( transform_trace_gen S . PH . B . PB . CI . cut ( Some " \ t - detecting pseudo inverse events " ) " Trace after having removed pseudo inverse events :\ n " StoryProfiling . Pseudo_inverse_deletion ) Do_not_care Neutral
type story_table = { story_counter : int ; story_list : D . table ; }
let count_stories story_table = D . count_stories story_table . story_list
type observable_hit = { list_of_actions : S . PH . update_order list ; list_of_events : step_id list ; runtime_info : unit Trace . Simulation_info . t option }
let get_event_list_from_observable_hit a = a . list_of_events
let get_runtime_info_from_observable_hit a = a . runtime_info
let _get_list_order a = a . list_of_actions
let extract_observable_hits_from_musical_notation a ? shall_we_compute ( : _ ) ? shall_we_compute_profiling_information ( : _ ) ? print_if_zero ( : _ ) b profiling_info c d = let error , profiling_info , l = S . PH . forced_events a b profiling_info c d in error , profiling_info , Lis...
let extract_observable_hit_from_musical_notation a ? shall_we_compute ( : _ ) ? shall_we_compute_profiling_information ( : _ ) ? print_if_zero ( : _ ) b profiling_info c string d = let error , profiling_info , l = S . PH . forced_events a b profiling_info c d in match l with | [ a , ...
let translate p h profiling_info e b list = let error , profiling_info , ( list , _ ) = S . translate p h profiling_info e b list in error , profiling_info , trace_of_pretrace list
let causal_prefix_of_an_observable_hit parameter ? shall_we_compute ( : _ ) ? shall_we_compute_profiling_information ( : _ ) ? print_if_zero ( : _ ) handler profiling_info error string blackboard ( enriched_grid : enriched_cflow_grid ) observable_id = let eid = match get_event_list_from_obse...
let export_musical_grid_to_xls a ? shall_we_compute ( : _ ) ? shall_we_compute_profiling_information ( : _ ) ? print_if_zero ( : _ ) b ( p : StoryProfiling . StoryStats . log_info ) c d e f g = S . PH . B . export_blackboard_to_xls a b p c d e f g
let print_musical_grid a ? shall_we_compute ( : _ ) ? shall_we_compute_profiling_information ( : _ ) ? print_if_zero ( : _ ) b p c d = S . PH . B . print_blackboard a b p c d
let create_story_table parameters ? shall_we_compute ( : _ ) ? shall_we_compute_profiling_information ( : _ ) ? print_if_zero ( : _ ) handler profiling_info error = let error , profiling_info , init = D . init_table parameters handler profiling_info error in error , profiling_info , { ...
let _get_trace_of_story ( _ , _ , _ , y , _ ) = trace_of_pretrace y
let _get_info_of_story ( _ , _ , _ , _ , t ) = t
let tick_opt parameter bar = match bar with | None -> bar | Some ( logger , bar ) -> Some ( logger , Tick_stories . tick_stories logger Configuration . empty ( S . PH . B . PB . CI . Po . K . H . save_progress_bar parameter ) bar )
let close_progress_bar_opt logger = Loggers . print_newline logger
let print_fails logger s n = match n with | 0 -> ( ) | 1 -> Loggers . fprintf logger " . @\ t 1 % s has failed . " @ s | _ -> Loggers . fprintf logger " . @\ t % i % ss have failed . " @ n s
let inc_fails a a ' b = if a == a ' then succ b else b
let fold_story_table_gen logger parameter ( ? shall_we_compute = we_shall ) ( ? shall_we_compute_profiling_information = we_shall ) ( handler : kappa_handler ) ( profiling_info : profiling_info ) error s ( f ( ( : trace , trace_runtime_info list , ' a , ' a ) ternary ) ) l a...
let fold_story_table_with_progress_bar parameter ? shall_we_compute ? shall_we_compute_profiling_information ? print_if_zero : _ handler profiling_info error s f l a = fold_story_table_gen ( S . PH . B . PB . CI . Po . K . H . get_logger parameter ) parameter ? shall_we_compute ? shall_we_co...
let fold_story_table_without_progress_bar parameter ? shall_we_compute ? shall_we_compute_profiling_information ? print_if_zero : _ handler profiling_info error s f l a = fold_story_table_gen Loggers . dummy_txt_logger parameter ? shall_we_compute ? shall_we_compute_profiling_information handler profiling_inf...
let get_counter story_list = story_list . story_counter
let get_stories story_list = story_list . story_list
let _inc_counter story_list = { story_list with story_counter = succ story_list . story_counter }
let build_grid parameter handler computation_info error trace bool = let error , computation_info = StoryProfiling . StoryStats . add_event ( S . PH . B . PB . CI . Po . K . H . get_kasa_parameters parameter ) error StoryProfiling . Build_grid None computation_info in let grid = S . PH ...
let store_trace ( parameter : parameter ) ? shall_we_compute : _ ? shall_we_compute_profiling_information : _ ? print_if_zero : _ handler computation_info error trace obs_info story_table = let error , computation_info = StoryProfiling . StoryStats . add_event ( S . PH . B . PB . CI . ...
let flatten_story_table parameter ? shall_we_compute : _ ? shall_we_compute_profiling_information : _ ? print_if_zero : _ handler log_info error story_table = let error , log_info , list = D . hash_list parameter handler log_info error story_table . story_list in error , log_info , { story_tabl...
let compress ? heuristic parameter ? shall_we_compute : _ ? shall_we_compute_profiling_information : _ ? print_if_zero : _ handler log_info error trace = match parameter . S . PH . B . PB . CI . Po . K . H . current_compression_mode with | None -> error , log_info , [ trace ] | S...
let strongly_compress ? heuristic parameter = compress ? heuristic ( S . PH . B . PB . CI . Po . K . H . set_compression_strong parameter )