text
stringlengths
0
601k
let trans n = trans_aux G . empty ( true , n ) ; ;
let p n = ( ( true , n ) , [ ( true , 0 ) ] , fun ( b , _ ) -> b ) ; ;
let ex n = let t = trans n in ( A . strategyA t ( p n ) , t ) ; ;
let ex1 = ex n1 ; ;
let ex2 = ex n2 ; ;
let couple_of_strat g s = let f v l = try let v ' = S . next s v in ( v , v ' ) :: l with Invalid_argument _ -> l in G . fold_vertex f g [ ] ; ;
let string_of_couple ( ( _ , i1 ) , ( _ , i2 ) ) = " ( " ^ ( string_of_int i1 ) ^ " , " ^ ( string_of_int i2 ) ^ " ) " ; ;
let rec string_of_couple_list l = match l with [ ] -> " " | e :: l ' -> ( string_of_couple e ) ^ ( string_of_couple_list l ' ) ; ; print_newline ( ) ; ; print_newline ( ) ; ; print_newline ( ) ; ;
type ' a t = ' a cell option Sempty | Scons of ' a * ' a data | Sapp of ' a data * ' a data | Slazy of ' a data Lazy . t | Sgen of ' a gen | Sbuffio : buffio -> char data { ic : in_channel ; buff : bytes ; mutable len : int ; mutable ind : int }
let count = function | None -> 0 | Some { count } -> count
let data = function | None -> Sempty | Some { data } -> data
let fill_buff b = b . len <- input b . ic b . buff 0 ( Bytes . length b . buff ) ; b . ind <- 0
let rec get_data : type v . int -> v data -> v data = fun count d -> match d with Sempty | Scons ( _ , _ ) -> d | Sapp ( d1 , d2 ) -> begin match get_data count d1 with Scons ( a , d11 ) -> Scons ( a , Sapp ( d11 , d2 ) ) | Sempty -> get_data count d2 | _ -> assert false end | Sgen { curr = Some None } -> Sempty | Sgen...
let rec peek_data : type v . v cell -> v option = fun s -> match s . data with Sempty -> None | Scons ( a , _ ) -> Some a | Sapp ( _ , _ ) -> begin match get_data s . count s . data with Scons ( a , _ ) as d -> s . data <- d ; Some a | Sempty -> None | _ -> assert false end | Slazy f -> s . data <- ( Lazy . force f ) ;...
let peek = function | None -> None | Some s -> peek_data s
let rec junk_data : type v . v cell -> unit = fun s -> match s . data with Scons ( _ , d ) -> s . count <- ( succ s . count ) ; s . data <- d | Sgen ( { curr = Some _ } as g ) -> s . count <- ( succ s . count ) ; g . curr <- None | Sbuffio b -> if b . ind >= b . len then fill_buff b ; if b . len == 0 then s . data <- S...
let junk = function | None -> ( ) | Some data -> junk_data data
let rec nget_data n s = if n <= 0 then [ ] , s . data , 0 else match peek_data s with Some a -> junk_data s ; let ( al , d , k ) = nget_data ( pred n ) s in a :: al , Scons ( a , d ) , succ k | None -> [ ] , s . data , 0
let npeek_data n s = let ( al , d , len ) = nget_data n s in s . count <- ( s . count - len ) ; s . data <- d ; al
let npeek n = function | None -> [ ] | Some d -> npeek_data n d
let next s = match peek s with Some a -> junk s ; a | None -> raise Failure
let empty s = match peek s with Some _ -> raise Failure | None -> ( )
let iter f strm = let rec do_rec ( ) = match peek strm with Some a -> junk strm ; ignore ( f a ) ; do_rec ( ) | None -> ( ) in do_rec ( )
let from f = Some { count = 0 ; data = Sgen { curr = None ; func = f } }
let of_list l = Some { count = 0 ; data = List . fold_right ( fun x l -> Scons ( x , l ) ) l Sempty }
let of_string s = let count = ref 0 in from ( fun _ -> let c = ! count in if c < String . length s then ( incr count ; Some s . [ c ] ) else None )
let of_bytes s = let count = ref 0 in from ( fun _ -> let c = ! count in if c < Bytes . length s then ( incr count ; Some ( Bytes . get s c ) ) else None )
let of_channel ic = Some { count = 0 ; data = Sbuffio { ic = ic ; buff = Bytes . create 4096 ; len = 0 ; ind = 0 } }
let iapp i s = Some { count = 0 ; data = Sapp ( data i , data s ) }
let icons i s = Some { count = 0 ; data = Scons ( i , data s ) }
let ising i = Some { count = 0 ; data = Scons ( i , Sempty ) }
let lapp f s = Some { count = 0 ; data = Slazy ( lazy ( Sapp ( data ( f ( ) ) , data s ) ) ) }
let lcons f s = Some { count = 0 ; data = Slazy ( lazy ( Scons ( f ( ) , data s ) ) ) }
let lsing f = Some { count = 0 ; data = Slazy ( lazy ( Scons ( f ( ) , Sempty ) ) ) }
let slazy f = Some { count = 0 ; data = Slazy ( lazy ( data ( f ( ) ) ) ) }
let rec dump : type v . ( v -> unit ) -> v t -> unit = fun f s -> print_string " { count = " ; print_int ( count s ) ; print_string " ; data = " ; dump_data f ( data s ) ; print_string " } " ; print_newline ( ) function Sempty -> print_string " Sempty " | Scons ( a , d ) -> print_string " Scons ( " ; f a ; print_string...
type ' a t = { count : int ; data : ' a data ; last : ' a option } | Sempty | Scons of ' a * ' a data | Sapp of ' a data * ' a t | Slazy of ' a t Lazy . t | Sgen of ' a gen | Sbuffio of buffio { ic : in_channel ; buff : string ; mutable len : int ; mutable ind : int } ; ;
let set_last ( s : ' a t ) ( v ' : a option ) = Obj . set_field ( Obj . repr s ) 2 ( Obj . repr v ) ; ;
let set_data ( s : ' a t ) ( d : ' a data ) = Obj . set_field ( Obj . repr s ) 1 ( Obj . repr d ) ; ;
let fill_buff b = ( b . len <- input b . ic b . buff 0 ( String . length b . buff ) ; b . ind <- 0 ) ; ;
let rec get_data s d = match d with | Sempty | Scons ( _ , _ ) -> d | Sapp ( d1 , s2 ) -> begin match get_data s d1 with | Scons ( a , d11 ) -> Scons ( a , Sapp ( d11 , s2 ) ) | Sempty -> ( set_count s s2 . count ; get_data s s2 . data ) | _ -> assert false end | Sgen { curr = Some None ; _ } -> Sempty | Sgen ( { curr ...
let rec peek s = match s . data with Sempty -> None | Scons ( a , _ ) -> Some a | Sapp ( _ , _ ) -> begin match get_data s s . data with | Scons ( a , _ ) as d -> set_data s d ; Some a | Sempty -> None | _ -> assert false end | Slazy f -> let s2 = Lazy . force f in set_count s s2 . count ; set_data s s2 . data ; peek s...
let rec junk s = match s . data with Scons ( a , d ) -> set_count s ( succ s . count ) ; set_data s d ; set_last s ( Some a ) ; | Sgen ( { curr = Some a ; _ } as g ) -> set_count s ( succ s . count ) ; g . curr <- None ; set_last s a ; | Sbuffio b -> if b . ind >= b . len then fill_buff b ; if b . len == 0 then ( ) els...
let rec fake_junk s = match s . data with Scons ( _a , d ) -> set_count s ( succ s . count ) ; set_data s d ; | Sgen ( { curr = Some _a ; _ } as g ) -> set_count s ( succ s . count ) ; g . curr <- None ; | Sbuffio b -> if b . ind >= b . len then fill_buff b ; if b . len == 0 then ( ) else begin set_count s ( succ s . c...
let rec nget n s = if n <= 0 then [ ] , s . data , 0 else match peek s with Some a -> fake_junk s ; let ( al , d , k ) = nget ( pred n ) s in a :: al , Scons ( a , d ) , succ k | None -> [ ] , s . data , 0 ; ;
let npeek n s = let ( al , d , len ) = nget n s in set_count s ( s . count - len ) ; set_data s d ; al ; ;
let next s = match peek s with Some a -> junk s ; a | None -> raise NotConsumed ; ;
let empty s = match peek s with Some _ -> raise NotConsumed | None -> ( ) ; ;
let iter f strm = let rec do_rec ( ) = match peek strm with Some a -> junk strm ; ignore ( f a ) ; do_rec ( ) | None -> ( ) in do_rec ( ) ; ;
let from f = { count = 0 ; data = Sgen { curr = None ; func = f } ; last = None } ; ;
let of_list l = { count = 0 ; data = List . fold_right ( fun x l -> Scons ( x , l ) ) l Sempty ; last = None } ; ;
let of_array l = { count = 0 ; data = Array . fold_right ( fun x l -> Scons ( x , l ) ) l Sempty ; last = None } ; ;
let of_string s = from ( fun c -> if c < String . length s then Some s . [ c ] else None ) ; ;
let of_channel ic = { count = 0 ; data = Sbuffio { ic = ic ; buff = String . create 4096 ; len = 0 ; ind = 0 } ; last = None } ; ;
let ising i = { count = 0 ; data = Scons ( i , Sempty ) ; last = None } ; ;
let icons i s = { count = s . count - 1 ; data = Scons ( i , s . data ) ; last = None } ; ;
let iapp i s = { count = i . count ; data = Sapp ( i . data , s ) ; last = None } ; ;
let sempty = { count = 0 ; data = Sempty ; last = None } ; ;
let slazy f = { count = 0 ; data = Slazy ( lazy ( f ( ) ) ) ; last = None } ; ;
let lsing f = { count = 0 ; data = Slazy ( lazy ( ising ( f ( ) ) ) ) ; last = None } ; ;
let lcons f s = { count = 0 ; data = Slazy ( lazy ( icons ( f ( ) ) s ) ) ; last = None } ; ;
let lapp f s = { count = 0 ; data = Slazy ( lazy ( iapp ( f ( ) ) s ) ) ; last = None } ; ;
let rec dump f s = print_string " { count = " ; print_int s . count ; print_string " ; data = " ; dump_data f s . data ; print_string " } " ; print_newline ( ) function Sempty -> print_string " Sempty " | Scons ( a , d ) -> print_string " Scons ( " ; f a ; print_string " , " ; dump_data f d ; print_string " ) " | Sapp ...
let get_last v = v . last ; ;
let njunk n strm = for _i = 1 to n do junk strm done
let tail s = match peek s with | Some _ -> ( junk s ; s ) | _ -> sempty
let rev strm = let rec aux s = match peek s with | Some x -> ( junk s ; ( let xs = s in lapp ( fun _ -> aux xs ) ( ising x ) ) ) | _ -> sempty in aux strm
let rec map f s = match peek s with | Some x -> ( junk s ; ( let xs = s in lcons ( fun _ -> f x ) ( slazy ( fun _ -> map f xs ) ) ) ) | _ -> sempty
let peek_nth strm n = let rec loop i = function | x :: xs -> if i = 0 then Some x else loop ( i - 1 ) xs | [ ] -> None in if n < 0 then invalid_arg " Streamf . peek_nth " else loop n ( npeek ( n + 1 ) strm )
let dup strm = from ( peek_nth strm )
let rec filter f s = match peek s with | Some x -> ( junk s ; ( let xs = s in if f x then icons x ( slazy ( fun _ -> filter f xs ) ) else slazy ( fun _ -> filter f xs ) ) ) | _ -> sempty
let rec listrec acc = parser [ [ : ` t ; strm ] : -> listrec [ t :: acc ] strm ] ;
let rec paux v1 = parser [ [ : op = sep ; v2 = f ; rv = paux ( op v1 v2 ) ] : -> rv ] [ : v = f ; rv = paux v ] : -> rv ] ; [ : ` Kwd " " + ] : -> ( fun x y -> x + y ) ] ; [ : ` Kwd " " * ] : -> ( fun x y -> x * y ) ] ; [ : rv = pleft expr2 additives ] : -> rv ] [ : rv = pleft expr3 multiplicatives ] : -> rv ] [ : ` In...
let ( === ) = Int32 . equal
let state_fold f initial = let state = ref initial in ( fun throw e k -> f ! state throw e ( fun ( c , new_state ) -> state := new_state ; k c ) ) |> make
let string s = state_fold ( fun i _ e k -> if i >= String . length s then e ( ) else k ( s . [ i ] , i + 1 ) ) 0
let buffer b = state_fold ( fun i _ e k -> if i >= Buffer . length b then e ( ) else k ( Buffer . nth b i , i + 1 ) ) 0
type result = Count of int | Exn of exn
let channel c = let ended = ref false in let buffer_length = 4096 in let buffer = Bytes . create buffer_length in let position = ref 0 in let buffered = ref 0 in ( fun throw e k -> let position ' = ! position in if position ' < ! buffered then begin position := position ' + 1 ; k ( Bytes . get buffer position ' ) end e...
let file f = let c = open_in f in let s = channel c in let s ' = ( fun throw e k -> next s ( fun exn -> close_in_noerr c ; throw exn ) ( fun ( ) -> close_in_noerr c ; e ( ) ) k ) |> make in s ' , fun ( ) -> close_in_noerr c
let to_buffer s throw k = let buffer = Buffer . create 4096 in iter ( fun b _ k -> Buffer . add_char buffer b ; k ( ) ) s throw ( fun ( ) -> k buffer )
let to_string s throw k = to_buffer s throw ( fun buffer -> k ( Buffer . contents buffer ) )
let to_channel c s throw k = let write b throw k = let exn = try output_char c b ; None with exn -> Some exn in match exn with | None -> k ( ) | Some exn -> throw exn in iter write s throw k
let to_file f s throw k = let c = open_out f in to_channel c s ( fun exn -> close_out_noerr c ; throw exn ) ( fun ( ) -> close_out_noerr c ; k ( ) )
let parse ( token : unit -> Genlex . token ) token = let look_ahead = Queue . create ( ) in let token ( ) = if Queue . is_empty look_ahead then try token ( ) with _ -> Kwd " " == else Queue . pop look_ahead in let push e = Queue . push e look_ahead in let rec parse_atom ( ) = match token ( ) with | Int n -> n | Kwd ( "...
let lexer = Genlex . make_lexer [ ( " " ; " " ; * " " ; / " " ; + " " ; - ) ] " " ; ;
let token chars = let strm = ( lexer chars ) chars in fun ( ) -> Stream . next strm ; ;
let l_parse ( token : unit -> Genlex . token ) token = let look_ahead = Queue . create ( ) in let token ( ) = if Queue . is_empty look_ahead then try token ( ) with _ -> Kwd " " == else Queue . pop look_ahead in let push e = Queue . push e look_ahead in let rec parse_e ( ) = parse_t_aux ( parse_t ( ) ) and parse_t_aux ...
let suites : Mt . pair_suites ref = ref [ ]
let test_id = ref 0
let eq loc x y = incr test_id ; suites := ( loc " ^ id " ^ ( string_of_int ! test_id ) test_id , ( fun _ -> Mt . Eq ( Eqx , y ) y ) y ) y :: ! suites
let ( ) = let ( a , b ) b = ( parse ( token ( Stream . of_string " 1 + 2 + ( 3 - 2 ) 2 * 3 * 3 - 2 a ) ) ) " in eq __LOC__ ( a , b ) b ( 10 , [ Ident " a ] ) " ; eq __LOC__ ( 2 , [ Genlex . Kwd ] ) " " == ( parse ( token ( Stream . of_string " 3 - 2 - 1 ) ) ) " ; eq __LOC__ ( 0 , [ Genlex . Kwd ] ) " " == ( l_parse ( t...
let ( ) = Mt . from_pair_suites __FILE__ ! suites
type dst_info = INET of string * int | UNIX of string
type t = { dst_info : dst_info ; conn_timeout : int ; mutable socket : U . file_descr option ; mutable last_conn_err_time : int option ; mutable conn_err_count : int ; dummy_one_byte : string ; }
let create dst_info conn_timeout = { dst_info = dst_info ; conn_timeout = conn_timeout ; socket = None ; last_conn_err_time = None ; conn_err_count = 0 ; dummy_one_byte = String . create 1 }
let print_unix_error label e fn param = Printf . eprintf " % s : [ % s ] [ % s ] [ % s ] \ n " label ( U . error_message e ) fn param
let connect t = let s = U . socket ( match t . dst_info with INET _ -> U . PF_INET | UNIX _ -> U . PF_UNIX ) U . SOCK_STREAM 0 in let conn_success ( ) = t . last_conn_err_time <- None ; t . conn_err_count <- 0 ; t . socket <- Some s in let conn_failed ( ) = t . last_conn_err_time <- Some ( int_of_float ( U . time ( ) )...
let connect_if_needed t = match t . socket with | Some _ -> ( ) | None -> ( match t . last_conn_err_time with | Some tm -> ( let now = int_of_float ( U . time ( ) ) in let interval = int_of_float ( 2 . 0 ** ( float_of_int t . conn_err_count ) ) in let max_conn_retain_interval = 60 in let interval = if interval < max_co...
let close t = match t . socket with | Some s -> ( try U . close s with U . Unix_error ( e , fn , p ) -> print_unix_error " close error " e fn p ) ; t . socket <- None | None -> ( )