text
stringlengths
12
786k
let g msg = match f msg 5 with | _ -> assert false | exception ( Error " a " ) -> print_string " a " ; print_newline ( ) ; 0 | exception ( Error " b " as exn ) -> print_string " b " ; print_newline ( ) ; raise exn | exception ( Error " c " ) -> print_string " ...
let run args = try ignore ( g args . ( 0 ) ) ; print_string " No exception \ n " with exn -> Printf . printf " Uncaught exception % s \ n " ( Printexc . to_string exn ) ; Printexc . print_backtrace stdout
let _ = run [ | " a " ] ; | run [ | " b " ] ; | run [ | " c " ] ; | run [ | " d " ] ; | run [ | " e " ] ; | run [ | " f " ] ; | run [ | " g " ] ; | run [ | " h " ] ; | run [ | ] |
let cache_size = 1 lsl 14
module Writer = struct open Buf . Write type t = { cache : int array ; cache_date : int array ; cache_next : cache_bucket array ; mutable next_verify_ix : int ; } let create ( ) = { cache = Array . make cache_size 0 ; cache_date = Array . make cache_size 0 ; cache_next = Array . ...
module Reader = struct open Buf . Read type t = { cache_loc : int array ; cache_pred : int array ; mutable last_backtrace : int array ; } let create ( ) = { cache_loc = Array . make cache_size 0 ; cache_pred = Array . make cache_size 0 ; last_backtrace = [ | ] | } let [ @...
let get_backtrace ( ) = let raw_backtrace = Printexc . get_raw_backtrace ( ) in let raw_slots = Array . init ( Printexc . raw_backtrace_length raw_backtrace ) ( Printexc . get_raw_backtrace_slot raw_backtrace ) in let convert = Printexc . convert_raw_backtrace_slot in let backtrace = Arra...
let rec f msg n = if n = 0 then raise ( Error msg ) else 1 + f msg ( n - 1 )
let g msg = try f msg 5 with Error " a " -> print_string " a " ; print_newline ( ) ; 0 | Error " b " as exn -> print_string " b " ; print_newline ( ) ; raise exn | Error " c " -> raise ( Error " c " )
let run args = try ignore ( g args . ( 0 ) ) ; print_string " No exception \ n " with exn -> Printf . printf " Uncaught exception % s \ n " ( Printexc . to_string exn ) ; get_backtrace ( ) |> Array . iteri ( fun i slot -> match Printexc . Slot . format i slot with | No...
let _ = run [ | " a " ] ; | run [ | " b " ] ; | run [ | " c " ] ; | run [ | " d " ] ; | run [ | ] |
let mutate_file r buf filesize rseed mratio = let mratio = get_ratio rseed mratio in let bits = filesize * 8 in let bits_to_mod = ( float_of_int bits ) . * mratio |> int_of_float in let bits_to_mod = if bits_to_mod = 0 then 1 else bits_to_mod in let bits_to_mod = get_random_partition r bits bits_to_m...
let generate conf knobs rseed = let myfile , mapsize , filesize = prepare_fuzztarget conf true in let buf = Fastlib . map_file myfile mapsize in let r = init_rseed rseed in let ( ) = mutate_file r buf filesize rseed conf . mratio in let ( ) = Fastlib . unmap_file buf in myfile , rseed
let flag = ref true
let debug = ref false
let topw = ref default_toplevel
let configure_cursor w cursor = Protocol . tkCommand [ | TkToken ( name w ) ; TkToken " configure " ; TkToken " - cursor " ; TkToken cursor ] |
let put ~ on : w ~ ms : millisec mesg = let t = ref None in let cursor = ref " " in let reset ( ) = begin match ! t with Some t -> Timer . remove t | _ -> ( ) end ; if Winfo . exists ! topw && Wm . state ! topw <> " withdrawn " then begin Wm . withdraw ! topw ; if Winfo . ...
let init ( ) = let t = Hashtbl . create 101 in Protocol . add_destroy_hook ( fun w -> Hashtbl . remove t w ) ; topw := Toplevel . create default_toplevel ; Wm . overrideredirect_set ! topw true ; Wm . withdraw ! topw ; popupw := Message . create ! topw ~ name : " balloon " ...
type bdd = One | Zero | Node of bdd * int * int * bdd
let rec eval bdd vars = match bdd with Zero -> false | One -> true | Node ( l , v , _ , h ) -> if vars . ( v ) then eval h vars else eval l vars
let getId bdd = match bdd with Node ( _ , _ , id , _ ) -> id | Zero -> 0 | One -> 1
let initSize_1 = 8 * 1024 - 1
let nodeC = ref 1
let sz_1 = ref initSize_1
let htab = ref ( Array . create ( ! sz_1 + 1 ) [ ] )
let n_items = ref 0
let hashVal x y v = x lsl 1 + y + v lsl 2
let resize newSize = let arr = ! htab in let newSz_1 = newSize - 1 in let newArr = Array . create newSize [ ] in let rec copyBucket bucket = match bucket with [ ] -> ( ) | n :: ns -> match n with | Node ( l , v , _ , h ) -> let ind = hashVal ( getId l ) ( getId h ) v land...
let rec insert idl idh v ind bucket newNode = if ! n_items <= ! sz_1 then ( ( ! htab ) . ( ind ) <- ( newNode :: bucket ) ; incr n_items ) else ( resize ( ! sz_1 + ! sz_1 + 2 ) ; let ind = hashVal idl idh v land ( ! sz_1 ) in ( ! htab ) . ( ind ) <- newNode :: ...
let resetUnique ( ) = ( sz_1 := initSize_1 ; htab := Array . create ( ! sz_1 + 1 ) [ ] ; n_items := 0 ; nodeC := 1 )
let mkNode low v high = let idl = getId low in let idh = getId high in if idl = idh then low else let ind = hashVal idl idh v land ( ! sz_1 ) in let bucket = ( ! htab ) . ( ind ) in let rec lookup b = match b with [ ] -> let n = Node ( low , v , ( incr nodeC ; ! nodeC ) , hig...
type ordering = LESS | EQUAL | GREATER
let cmpVar ( x : int ) ( y : int ) = if x < y then LESS else if x > y then GREATER else EQUAL
let mkVar x = mkNode zero x one
let andslot1 = Array . create cacheSize 0
let andslot2 = Array . create cacheSize 0
let andslot3 = Array . create cacheSize zero
let xorslot1 = Array . create cacheSize 0
let xorslot2 = Array . create cacheSize 0
let xorslot3 = Array . create cacheSize zero
let notslot1 = Array . create cacheSize 0
let notslot2 = Array . create cacheSize one
let hash x y = ( ( x lsl 1 ) + y ) mod cacheSize
let rec not n = Zero -> One in if id = notslot1 . ( h ) then notslot2 . ( h ) else let f = mkNode ( not l ) v ( not r ) in notslot1 . ( h ) <- id ; notslot2 . ( h ) <- f ; f
let rec and2 n1 n2 = Node ( l1 , v1 , i1 , r1 ) -> ( match n2 with Node ( l2 , v2 , i2 , r2 ) -> let h = hash i1 i2 in if i1 = andslot1 . ( h ) && i2 = andslot2 . ( h ) then andslot3 . ( h ) else let f = match cmpVar v1 v2 with EQUAL -> mkNode ( and2 l1 l2 ) v1 ( a...
let rec xor n1 n2 = Node ( l1 , v1 , i1 , r1 ) -> ( match n2 with Node ( l2 , v2 , i2 , r2 ) -> let h = hash i1 i2 in if i1 = andslot1 . ( h ) && i2 = andslot2 . ( h ) then andslot3 . ( h ) else let f = match cmpVar v1 v2 with EQUAL -> mkNode ( xor l1 l2 ) v1 ( xor...
let hwb n = let rec h i j = if i = j then mkVar i else xor ( and2 ( not ( mkVar j ) ) ( h i ( j - 1 ) ) ) ( and2 ( mkVar j ) ( g i ( j - 1 ) ) ) and g i j = if i = j then mkVar i else xor ( and2 ( not ( mkVar i ) ) ( h ( i + 1 ) j ) ) ( and2 ( mkVar...
let seed = ref 0
let random ( ) = seed := ! seed * 25173 + 17431 ; ! seed land 1 > 0
let random_vars n = let vars = Array . create n false in for i = 0 to n - 1 do vars . ( i ) <- random ( ) done ; vars
let test_hwb bdd vars = let ntrue = ref 0 in for i = 0 to Array . length vars - 1 do if vars . ( i ) then incr ntrue done ; eval bdd vars = ( if ! ntrue > 0 then vars . ( ! ntrue - 1 ) else false )
let main ( ) = let n = if Array . length Sys . argv >= 2 then int_of_string Sys . argv . ( 1 ) else 22 in let ntests = if Array . length Sys . argv >= 3 then int_of_string Sys . argv . ( 2 ) else 100 in let bdd = hwb n in let succeeded = ref true in for i = 1 to ntests do succ...
Ace of color | King of color | Queen of color | Jack of color | Other of colval ; ;
let compute = kern cards trump values n -> let value = fun a trump -> match a with | Ace c -> 11 | King c -> 4 | Queen c -> 3 | Jack c -> if c = trump then 20 else 2 | Other cv -> if cv . v = 10 then 10 else if ( cv . c = trump ) && ( cv . v = 9 ) then 14 else 0 in let open St...
let cpt = ref 0
let tot_time = ref 0 .
let measure_time f s = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in let t1 = Unix . gettimeofday ( ) in Printf . printf " % s : time % d : % Fs \ n " %! s ! cpt ( t1 . - t0 ) ; tot_time := ! tot_time . + ( t1 . - t0 ) ; incr cpt ; a ; ;
let _ = Random . self_init ( ) ; let devs = Spoc . Devices . init ( ) in let dev = devs . ( 2 ) in let cards = Vector . create ( Vector . Custom customCard ) n in let values = Vector . create Vector . int32 n in let trump = Vector . create ( Vector . Custom customColor ) ...
let int64_of_bool_obj_magic b = Caml . Obj . magic b |> Int64 . of_int
let int64_of_bool_branching b = if b then 1L else 0L
let test_values = [ | 1L ; 4L ; 8L ] |
let result = Bigstring . init 8 ~ f ( : fun _ -> ' \ 000 ' )
let test f = for i = 0 to Array . length test_values - 1 do for j = 0 to Array . length test_values - 1 do f test_values . ( i ) test_values . ( j ) done done ; ;
let equal_obj_magic a b = Int64 . equal a b |> int64_of_bool_obj_magic |> Bigstring . set_int64_t_le result ~ pos : 0 ; ;
let equal_branching a b = Int64 . equal a b |> int64_of_bool_branching |> Bigstring . set_int64_t_le result ~ pos : 0 ; ;
let equal_bit_fiddling a b = lnot ( Int64 . compare a b ) land 1 |> Int64 . of_int |> Bigstring . set_int64_t_le result ~ pos : 0 ; ;
let lt_obj_magic a b = Int64 . ( < ) a b |> int64_of_bool_obj_magic |> Bigstring . set_int64_t_le result ~ pos : 0 ; ;
let lt_branching a b = Int64 . ( < ) a b |> int64_of_bool_branching |> Bigstring . set_int64_t_le result ~ pos : 0 ; ;
let lt_bit_fiddling a b = ( Int64 . compare a b lsr 1 ) land 1 |> Int64 . of_int |> Bigstring . set_int64_t_le result ~ pos : 0 ; ;
let cpt = ref 0
let tot_time = ref 0 .
let measure_time f s = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in let t1 = Unix . gettimeofday ( ) in Printf . printf " % s time % d : % Fs \ n " %! s ! cpt ( ( t1 . - t0 ) . / 10 . ) ; tot_time := ! tot_time . + ( t1 . - t0 ) ; incr cpt ; a ...
let devices = measure_time ( Spoc . Devices . init ) " init " ktype node = { mutable starting : int32 ; mutable no_of_edges : int32 ; }
let max_threads_per_block = ref 512l
let bfs_kern1 = kern g_graph_nodes g_graph_edges g_graph_mask g_updating_graph_mask g_graph_visited g_cost no_of_nodes -> let open Std in let tid = ( block_idx_x * @ max_threads_per_block ) + thread_idx_x in if ( tid < no_of_nodes && ( 1 = g_graph_mask . [ < tid ] ) > ) then ( g_graph_ma...
let bfs_kern2 = kern g_graph_mask g_updating_graph_mask g_graph_visited g_over no_of_nodes -> let open Std in let tid = ( block_idx_x * @ max_threads_per_block ) + thread_idx_x in if ( tid < no_of_nodes && ( g_updating_graph_mask . [ < tid ] > = 1 ) ) then ( g_graph_mask . [ < tid ]...
let usage ( ) = Printf . eprintf " Usage : % s < input_file > [ ? device_id ] \ n " %! ( Sys . argv . ( 0 ) )
let bfs_graph ( ) = if ( Array . length Sys . argv ) != 2 && ( Array . length Sys . argv ) != 3 then ( usage ( ) ; exit 0 ; ) ; let dev = if ( Array . length Sys . argv ) = 3 then devices . ( int_of_string Sys . argv . ( 2 ) ) else devices . ( 0 ) ...
let _ = bfs_graph ( )
[ | aaa ; aab ; aac ; aad ; aae ; aaf ; aag ; aah ; aai ; aaj ; aak ; aal ; aam ; aan ; aao ; aap ; aaq ; aar ; aas ; aat ; aau ; aav ; aaw ; aax ; aay ; aaz ; aba ; abb ; abc ; abd ; abe ; abf ; abg ; abh ; abi ; abj ; abk ; abl ; abm ; a...
[ | aaaa ; aaab ; aaac ; aaad ; aaae ; aaaf ; aaag ; aaah ; aaai ; aaaj ; aaak ; aaal ; aaam ; aaan ; aaao ; aaap ; aaaq ; aaar ; aaas ; aaat ; aaau ; aaav ; aaaw ; aaax ; aaay ; aaaz ; aaba ; aabb ; aabc ; aabd ; aabe ; aabf ; aabg ; aabh ; aabi ; ...
[ | aaaaa ; aaaab ; aaaac ; aaaad ; aaaae ; aaaaf ; aaaag ; aaaah ; aaaai ; aaaaj ; aaaak ; aaaal ; aaaam ; aaaan ; aaaao ; aaaap ; aaaaq ; aaaar ; aaaas ; aaaat ; aaaau ; aaaav ; aaaaw ; aaaax ; aaaay ; aaaaz ; aaaba ; aaabb ; aaabc ; aaabd ; aaabe ; aaa...
type ( ' a , ' b ) kind = Float32 : ( float , float32_elt ) kind | Float64 : ( float , float64_elt ) kind | Int8_signed : ( int , int8_signed_elt ) kind | Int8_unsigned : ( int , int8_unsigned_elt ) kind | Int16_signed : ( int , int16_signed_elt ) kind | Int16_unsigned...
type ' a layout = C_layout : c_layout layout | Fortran_layout : fortran_layout layout
let kind_size_in_bytes : type a b . ( a , b ) kind -> int = function | Float32 -> 4 | Float64 -> 8 | Int8_signed -> 1 | Int8_unsigned -> 1 | Int16_signed -> 2 | Int16_unsigned -> 2 | Int32 -> 4 | Int64 -> 8 | Int -> Sys . word_size / 8 | Nativeint -> Sys . word_size / 8 |...
module Genarray = struct type ( ' ! a , ' ! b , ' ! c ) t external create : ( ' a , ' b ) kind -> ' c layout -> int array -> ( ' a , ' b , ' c ) t = " caml_ba_create " external get : ( ' a , ' b , ' c ) t -> int array -> ' a = " caml_ba_get_gene...
module Array0 = struct type ( ' ! a , ' ! b , ' ! c ) t = ( ' a , ' b , ' c ) Genarray . t let create kind layout = Genarray . create kind layout [ ] || let get arr = Genarray . get arr [ ] || let set arr = Genarray . set arr [ ] || external kind : ( ' a ,...
module Array1 = struct type ( ' ! a , ' ! b , ' ! c ) t = ( ' a , ' b , ' c ) Genarray . t let create kind layout dim = Genarray . create kind layout [ | dim ] | external get : ( ' a , ' b , ' c ) t -> int -> ' a = " % caml_ba_ref_1 " external set : ...
module Array2 = struct type ( ' ! a , ' ! b , ' ! c ) t = ( ' a , ' b , ' c ) Genarray . t let create kind layout dim1 dim2 = Genarray . create kind layout [ | dim1 ; dim2 ] | external get : ( ' a , ' b , ' c ) t -> int -> int -> ' a = " % caml_ba_re...
module Array3 = struct type ( ' ! a , ' ! b , ' ! c ) t = ( ' a , ' b , ' c ) Genarray . t let create kind layout dim1 dim2 dim3 = Genarray . create kind layout [ | dim1 ; dim2 ; dim3 ] | external get : ( ' a , ' b , ' c ) t -> int -> int -> int -> ' ...
let array0_of_genarray a = if Genarray . num_dims a = 0 then a else invalid_arg " Bigarray . array0_of_genarray "
let array1_of_genarray a = if Genarray . num_dims a = 1 then a else invalid_arg " Bigarray . array1_of_genarray "
let array2_of_genarray a = if Genarray . num_dims a = 2 then a else invalid_arg " Bigarray . array2_of_genarray "
let array3_of_genarray a = if Genarray . num_dims a = 3 then a else invalid_arg " Bigarray . array3_of_genarray " ( ' a , ' b , ' c ) Genarray . t -> int array -> ( ' a , ' b , ' c ) Genarray . t = " caml_ba_reshape "
let reshape_0 a = reshape a [ ] ||
let reshape_1 a dim1 = reshape a [ | dim1 ] |
let reshape_2 a dim1 dim2 = reshape a [ | dim1 ; dim2 ] |
let reshape_3 a dim1 dim2 dim3 = reshape a [ | dim1 ; dim2 ; dim3 ] |
let _ = let _ = Genarray . get in let _ = Array1 . get in let _ = Array2 . get in let _ = Array3 . get in ( )