text
stringlengths
0
601k
module Warehouse = Map . Make ( Int )
module S = Preface . Store . Over ( Int )
let stock = Warehouse . of_seq ( List . to_seq [ ( 0 , " OCaml " ) ; ( 1 , " Fsharp " ) ; ( 2 , " Haskell " ) ; ( 3 , " Scala " ) ] ) ; ;
let warehouse = S . store ( fun i -> Warehouse . find_opt i stock ) 0
let warehouse_pos ( ) = let open Alcotest in let computed = S . pos warehouse and expected = 0 in check int " Should be equal " expected computed ; ;
let warehouse_extract ( ) = let open Alcotest in let expected = Some " OCaml " and computed = S . extract warehouse in check ( option string ) " Should be equal " expected computed ; ;
let warehouse_peek ( ) = let open Alcotest in let expected = Some " Haskell " and computed = S . peek 2 warehouse in check ( option string ) " Should be equal " expected computed ; ;
let warehouse_peeks ( ) = let open Alcotest in let expected = Some " Fsharp " and computed = S . peeks succ warehouse in check ( option string ) " Should be equal " expected computed ; ;
let warehouse_seek ( ) = let open Alcotest in let expected = Some " Haskell " and computed = S . seek 2 warehouse |> S . extract in check ( option string ) " Should be equal " expected computed ; ;
let warehouse_seeks ( ) = let open Alcotest in let expected = Some " Fsharp " and computed = S . seeks succ warehouse |> S . extract in check ( option string ) " Should be equal " expected computed ; ;
let warehouse_experiment ( ) = let open Alcotest in let module F = S . Experiment ( Preface . List . Functor ) in let expected = [ Some " OCaml " ; Some " Fsharp " ; Some " Haskell " ; Some " Scala " ; None ] in let computed = F . run ( fun x -> [ x ; x + 1 ; x + 2 ; x + 3 ; x + 4 ] ) warehouse in check ( list ( option...
let cases = let open Alcotest in [ ( " Store " , [ test_case " Test for pos " ` Quick pos_test ; test_case " Test for seek " ` Quick seek_test ; test_case " Test for seeks " ` Quick seeks_test ; test_case " Test for warehouse pos " ` Quick warehouse_pos ; test_case " Test for warehouse extract " ` Quick warehouse_extra...
type block_descriptor = Block_hash . t * int32
let block_descriptor_encoding = let open Data_encoding in tup2 Block_hash . encoding int32
let pp_block_descriptor fmt ( hash , level ) = Format . fprintf fmt " % a ( level : % ld ) " Block_hash . pp hash level
type chain_config = { history_mode : History_mode . t ; genesis : Genesis . t ; expiration : Time . Protocol . t option ; }
let chain_config_encoding = let open Data_encoding in conv ( fun { history_mode ; genesis ; expiration } -> ( history_mode , genesis , expiration ) ) ( fun ( history_mode , genesis , expiration ) -> { history_mode ; genesis ; expiration } ) ( obj3 ( req " history_mode " History_mode . encoding ) ( req " genesis " Genes...
type invalid_block = { level : int32 ; errors : Error_monad . error list }
let invalid_block_encoding = let open Data_encoding in conv ( fun { level ; errors } -> ( level , errors ) ) ( fun ( level , errors ) -> { level ; errors } ) ( obj2 ( req " level " int32 ) ( req " errors " ( list Error_monad . error_encoding ) ) )
module Block_lru_cache = Ringo_lwt . Functors . Make_opt ( ( val Ringo . ( map_maker ~ replacement : LRU ~ overflow : Strong ~ accounting : Precise ) ) ( Block_hash ) )
module Protocol_levels = struct include Map . Make ( struct type t = int let compare = Compare . Int . compare end ) type commit_info = { author : string ; message : string ; test_chain_status : Test_chain_status . t ; predecessor_block_metadata_hash : Block_metadata_hash . t option ; predecessor_ops_metadata_hash : Op...
type step_kind = | Dummy | Beginning | Collect_traces | Causal_compression | Weak_compression | Strong_compression | Iteration of int | Story of int | Partial_order_reduction | Siphon_detection | Decompose_initial_state | Agent_ids_disambiguation | Pseudo_inverse_deletion | Remove_events_after_last_observable | Compres...
let string_of_step_kind x = match x with | Dummy | Beginning -> " " | Build_configuration -> " Build configuration " | Collect_traces -> " Collect traces " | Causal_compression -> " Causal compression " | Weak_compression -> " Weak compression " | Strong_compression -> " Strong compression " | Iteration int -> Printf ....
let print_step_kind parameters x = Loggers . print_cell ( Remanent_parameters . get_profiler parameters ) ( string_of_step_kind x )
module type StoryStats = sig type log_info val inc_removed_events : log_info -> log_info val inc_selected_events : log_info -> log_info val log_info_to_json : log_info -> Yojson . Basic . t val log_info_of_json : Yojson . Basic . t -> log_info val inc_cut_events : log_info -> log_info val inc_k_cut_events : int -> log_...
module StoryStats = ( struct type stack_head = { current_branch : int ; selected_events : int ; remaining_events : int ; removed_events : int ; stack_size : int ; } type step = { tag : step_kind ; size_before : int option ; size_after : int option ; time_start : float ; duration : float option ; depth : int } let k_fir...
type current_compression_mode = Weak | Strong | Causal
type new_story = { id : int ; graph : Graph_loggers_sig . graph ; }
type story = | New of new_story | Same_as of int
type ' a one_compression = { log_info : ' a Trace . Simulation_info . t list ; story_mode : current_compression_mode ; story : story }
let string_of_json = function | ` String s -> s | x -> raise ( Yojson . Basic . Util . Type_error ( " Not a correct string " , x ) )
let int_of_json = function | ` Int s -> s | x -> raise ( Yojson . Basic . Util . Type_error ( " Not a correct int " , x ) )
let new_story_to_json new_story = ` Assoc [ " id " , ` Int new_story . id ; " graph " , Graph_json . to_json new_story . graph ; ]
let new_story_of_json = function | ` Assoc l as x when List . length l = 2 -> begin try { id = int_of_json ( List . assoc " id " l ) ; graph = Graph_json . of_json ( List . assoc " graph " l ) } with Not_found -> raise ( Yojson . Basic . Util . Type_error ( " Not a correct new story " , x ) ) end | x -> raise ( Yojson ...
let story_to_json story = match story with | New new_story -> ` Assoc [ " new " , new_story_to_json new_story ] | Same_as int -> ` Assoc [ " same_as " , ` Int int ]
let story_of_json = function | ` Assoc [ " new " , new_story ] -> New ( new_story_of_json new_story ) | ` Assoc [ " same_as " , ` Int int ] -> Same_as int | x -> raise ( Yojson . Basic . Util . Type_error ( " Not a correct story " , x ) )
let to_json log_info_to_json one_compression = ` Assoc [ " log_info " , ` List ( List . rev_map ( Trace . Simulation_info . to_json log_info_to_json ) ( List . rev one_compression . log_info ) ) ; " story_mode " , story_mode_to_json one_compression . story_mode ; " story " , story_to_json one_compression . story ]
let of_json log_info_of_json = function | ` Assoc l as x when List . length l = 3 -> begin try { log_info = begin match List . assoc " log_info " l with | ` List l -> List . rev_map ( Trace . Simulation_info . of_json log_info_of_json ) ( List . rev l ) | _y -> raise ( Yojson . Basic . Util . Type_error ( " Not a corre...
type phase = | Start | Inprogress | Success | Faillure
let start = " starting computation "
let inprogress = " computation in progress "
let success = " computation completed successfully "
let faillure = " computation ( partially ) failed "
let phase_to_json = function | Start -> ` String start | Inprogress -> ` String inprogress | Success -> ` String success | Faillure -> ` String faillure
let phase_of_json = function | ` String s when s = start -> Start | ` String s when s = inprogress -> Inprogress | ` String s when s = success -> Success | ` String s when s = faillure -> Faillure | x -> raise ( Yojson . Basic . Util . Type_error ( " Not a correct phase " , x ) )
type progress_bar = { bool : string ; current : int ; total : int }
let progress_bar_to_json progress_bar = ` Assoc [ " progress_bar " , ` Assoc [ " bool " , ` String progress_bar . bool ; " current " , ` Int progress_bar . current ; " total " , ` Int progress_bar . total ] ]
let progress_bar_of_json = function | ` Assoc l as x when List . length l = 1 -> begin match List . assoc " progress_bar " l with | ` Assoc l when List . length l = 3 -> begin try { bool = string_of_json ( List . assoc " bool " l ) ; current = int_of_json ( List . assoc " current " l ) ; total = int_of_json ( List . as...
type ' a message = | Phase of phase * string | Progress of progress_bar | Story of ' a one_compression
let message_to_json = function | Phase ( p , m ) -> ` List [ ` String " PHASE " ; phase_to_json p ; ` String m ] | Progress p -> ` List [ ` String " PROGRESS " ; progress_bar_to_json p ] | Story s -> ` List [ ` String " STORY " ; to_json ( fun _ -> ` Null ) s ]
let message_of_json = function | ` List [ ` String " PHASE " ; p ; ` String m ] -> Phase ( phase_of_json p , m ) | ` List [ ` String " PROGRESS " ; p ] -> Progress ( progress_bar_of_json p ) | ` List [ ` String " STORY " ; s ] -> Story ( of_json ( fun _ -> ( ) ) s ) | x -> raise ( Yojson . Basic . Util . Type_error ( "...
let string_before s n = String . sub s 0 n
let string_after s n = String . sub s n ( String . length s - n )
let first_chars s n = String . sub s 0 n
let last_chars s n = String . sub s ( String . length s - n ) n
module Charset = struct type t = bytes let full = Bytes . make 32 ' \ 255 ' let make_empty ( ) = Bytes . make 32 ' \ 000 ' let add s c = let i = Char . code c in Bytes . set s ( i lsr 3 ) ( Char . chr ( Char . code ( Bytes . get s ( i lsr 3 ) ) lor ( 1 lsl ( i land 7 ) ) ) ) let add_range s c1 c2 = for i = Char . code ...
type re_syntax = Char of char | String of string | CharClass of Charset . t * bool | Seq of re_syntax list | Alt of re_syntax * re_syntax | Star of re_syntax | Plus of re_syntax | Option of re_syntax | Group of int * re_syntax | Refgroup of int | Bol | Eol | Wordboundary
type regexp = { prog : int array ; cpool : string array ; normtable : string ; numgroups : int ; numregisters : int ; startchars : int }
let instr opc arg = opc lor ( arg lsl 8 )
let displ dest from = dest - from - 1
let rec is_nullable = function Char _ -> false | String s -> s = " " | CharClass _ -> false | Seq rl -> List . for_all is_nullable rl | Alt ( r1 , r2 ) -> is_nullable r1 || is_nullable r2 | Star _ -> true | Plus r -> is_nullable r | Option _ -> true | Group ( _ , r ) -> is_nullable r | Refgroup _ -> true | Bol -> true ...
let rec first = function Char c -> Charset . singleton c | String s -> if s = " " then Charset . full else Charset . singleton s . [ 0 ] | CharClass ( cl , cmpl ) -> if cmpl then Charset . complement cl else cl | Seq rl -> first_seq rl | Alt ( r1 , r2 ) -> Charset . union ( first r1 ) ( first r2 ) | Star _ -> Charset ....
let charclass_of_regexp fold_case re = let ( cl1 , compl ) = match re with | Char c -> ( Charset . singleton c , false ) | CharClass ( cl , compl ) -> ( cl , compl ) | _ -> assert false in let cl2 = if fold_case then Charset . fold_case cl1 else cl1 in Bytes . to_string ( if compl then Charset . complement cl2 else cl2...
let fold_case_table = ( let t = Bytes . create 256 in for i = 0 to 255 do Bytes . set t i ( Char . lowercase ( Char . chr i ) ) done ; Bytes . to_string t ) [ @ ocaml . warning " - 3 " ]
module StringMap = Map . Make ( struct type t = string let compare ( x : t ) y = compare x y end )
let compile fold_case re = let prog = ref ( Array . make 32 0 ) and progpos = ref 0 and cpool = ref StringMap . empty and cpoolpos = ref 0 and numgroups = ref 1 and numregs = ref 0 in let emit_instr opc arg = if ! progpos >= Array . length ! prog then begin let newlen = ref ( Array . length ! prog ) in while ! progpos ...
module SeqBuffer = struct type t = { sb_chars : Buffer . t ; mutable sb_next : re_syntax list } let create ( ) = { sb_chars = Buffer . create 16 ; sb_next = [ ] } let flush buf = let s = Buffer . contents buf . sb_chars in Buffer . clear buf . sb_chars ; match String . length s with 0 -> ( ) | 1 -> buf . sb_next <- Cha...
let dotclass = Charset . complement ( Charset . singleton ' \ n ' )
let parse s = let len = String . length s in let group_counter = ref 1 in let rec regexp0 i = let ( r , j ) = regexp1 i in regexp0cont r j and regexp0cont r1 i = if i + 2 <= len && s . [ i ] = ' ' \\ && s . [ i + 1 ] = ' ' | then let ( r2 , j ) = regexp1 ( i + 2 ) in regexp0cont ( Alt ( r1 , r2 ) ) j else ( r1 , i ) an...
let regexp e = compile false ( parse e )
let regexp_case_fold e = compile true ( parse e )
let quote s = let len = String . length s in let buf = Bytes . create ( 2 * len ) in let pos = ref 0 in for i = 0 to len - 1 do match s . [ i ] with ' [ ' | ' ] ' | ' ' * | ' . ' | ' ' \\ | ' ' ? | ' ' + | ' ' ^ | ' ' $ as c -> Bytes . set buf ! pos ' ' ; \\ Bytes . set buf ( ! pos + 1 ) c ; pos := ! pos + 2 | c -> Byt...
let regexp_string s = compile false ( String s )
let regexp_string_case_fold s = compile true ( String s ) = " re_string_match " = " re_partial_match " = " re_search_forward " = " re_search_backward "
let last_search_result = ref [ ] ||
let string_match re s pos = let res = re_string_match re s pos in last_search_result := res ; Array . length res > 0
let string_partial_match re s pos = let res = re_partial_match re s pos in last_search_result := res ; Array . length res > 0
let search_forward re s pos = let res = re_search_forward re s pos in last_search_result := res ; if Array . length res = 0 then raise Not_found else res . ( 0 )
let search_backward re s pos = let res = re_search_backward re s pos in last_search_result := res ; if Array . length res = 0 then raise Not_found else res . ( 0 )
let group_beginning n = let n2 = n + n in if n < 0 || n2 >= Array . length ! last_search_result then invalid_arg " Str . group_beginning " else let pos = ! last_search_result . ( n2 ) in if pos = - 1 then raise Not_found else pos
let group_end n = let n2 = n + n in if n < 0 || n2 >= Array . length ! last_search_result then invalid_arg " Str . group_end " else let pos = ! last_search_result . ( n2 + 1 ) in if pos = - 1 then raise Not_found else pos
let matched_group n txt = let n2 = n + n in if n < 0 || n2 >= Array . length ! last_search_result then invalid_arg " Str . matched_group " else let b = ! last_search_result . ( n2 ) and e = ! last_search_result . ( n2 + 1 ) in if b = - 1 then raise Not_found else String . sub txt b ( e - b )
let match_beginning ( ) = group_beginning 0 = " re_replacement_text "
let replace_matched repl matched = re_replacement_text repl ! last_search_result matched
let substitute_first expr repl_fun text = try let pos = search_forward expr text 0 in String . concat " " [ string_before text pos ; repl_fun text ; string_after text ( match_end ( ) ) ] with Not_found -> text
let opt_search_forward re s pos = try Some ( search_forward re s pos ) with Not_found -> None
let global_substitute expr repl_fun text = let rec replace accu start last_was_empty = let startpos = if last_was_empty then start + 1 else start in if startpos > String . length text then string_after text start :: accu else match opt_search_forward expr text startpos with | None -> string_after text start :: accu | S...
let global_replace expr repl text = global_substitute expr ( replace_matched repl ) text substitute_first expr ( replace_matched repl ) text
let opt_search_forward_progress expr text start = match opt_search_forward expr text start with | None -> None | Some pos -> if match_end ( ) > start then Some pos else if start < String . length text then opt_search_forward expr text ( start + 1 ) else None
let bounded_split expr text num = let start = if string_match expr text 0 then match_end ( ) else 0 in let rec split accu start n = if start >= String . length text then accu else if n = 1 then string_after text start :: accu else match opt_search_forward_progress expr text start with | None -> string_after text start ...
let split expr text = bounded_split expr text 0
let bounded_split_delim expr text num = let rec split accu start n = if start > String . length text then accu else if n = 1 then string_after text start :: accu else match opt_search_forward_progress expr text start with | None -> string_after text start :: accu | Some pos -> split ( String . sub text start ( pos - st...
let split_delim expr text = bounded_split_delim expr text 0
type split_result = Text of string | Delim of string
let bounded_full_split expr text num = let rec split accu start n = if start >= String . length text then accu else if n = 1 then Text ( string_after text start ) :: accu else match opt_search_forward_progress expr text start with | None -> Text ( string_after text start ) :: accu | Some pos -> let s = matched_string t...
let full_split expr text = bounded_full_split expr text 0
module V = struct type t = bool * int let compare = compare let hash = Hashtbl . hash let equal = ( ) = end
module P = struct type vertex = V . t type t = vertex * ( vertex list ) * ( vertex -> bool ) let get_initial ( i , _ , _ ) = i let is_final ( _ , f , _ ) v = List . mem v f let turn ( _ , _ , f ) v = f v end
module S = struct type vertex = V . t type t = vertex -> vertex let empty = fun _ -> raise ( Invalid_argument " Strategy definition " ) let next f v = f v let add s v v ' = fun e -> if V . equal e v then v ' else next s e end
let rec trans_aux g ( j , n ) = if n = 0 then g else if n = 1 then let g = G . add_edge g ( j , n ) ( not j , n - 1 ) in else if n = 2 then else