text stringlengths 0 601k |
|---|
let fpath = B0_ocaml . libname " fpath " |
let fpath_top = B0_ocaml . libname " fpath . top " |
let fmt = B0_ocaml . libname " fmt " |
let fmt_top = B0_ocaml . libname " fmt . tty " |
let fmt_tty = B0_ocaml . libname " fmt . tty " |
let logs = B0_ocaml . libname " logs " |
let logs_fmt = B0_ocaml . libname " logs . fmt " |
let logs_top = B0_ocaml . libname " logs . top " |
let mtime = B0_ocaml . libname " mtime " |
let mtime_clock_os = B0_ocaml . libname " mtime . clock . os " |
let bos = B0_ocaml . libname " bos " |
let bos_setup = B0_ocaml . libname " bos . setup " |
let bos_top = B0_ocaml . libname " bos . top " |
let bos_lib = let srcs = Fpath . [ ` Dir ( v " src " ) ; ` X ( v " src / bos_setup . ml " ) ; ` X ( v " src / bos_setup . mli " ) ; ` X ( v " src / bos_top . ml " ) ; ` X ( v " src / bos_top_init . ml " ) ] in let requires = [ astring ; fpath ; fmt ; unix ; logs ] in B0_ocaml . lib bos ~ doc " : The bos library " ~ src... |
let bos_setup_lib = let srcs = Fpath . [ ` File ( v " src / bos_setup . ml " ) ; ` File ( v " src / bos_setup . mli " ) ] in let requires = [ rresult ; fmt_tty ; logs_fmt ; astring ; fpath ; logs ; fmt ; bos ] in B0_ocaml . lib bos_setup ~ doc " : The bos . setup library " ~ srcs ~ requires |
let bos_top_lib = let srcs = Fpath . [ ` File ( v " src / bos_top . ml " ) ] in let requires = [ rresult_top ; astring_top ; fpath_top ; fmt_top ; logs_top ; compiler_libs_toplevel ] in B0_ocaml . lib bos_top ~ doc " : The bos . top library " ~ srcs ~ requires |
let test = let srcs = Fpath . [ ` File ( v " test / testing . mli " ) ; ` File ( v " test / testing . ml " ) ; ` File ( v " test / test . ml " ) ; ` File ( v " test / test_cmd . ml " ) ; ` File ( v " test / test_os_cmd . ml " ) ; ` File ( v " test / test_pat . ml " ) ; ] in let meta = B0_meta . ( empty |> tag test ) in... |
let test_arg = let srcs = Fpath . [ ` File ( v " test / test_arg . ml " ) ] in let meta = B0_meta . ( empty |> tag test ) in let requires = [ astring ; fmt ; fpath ; logs_fmt ; bos ] in B0_ocaml . exe " test - arg " ~ doc " : Test argument parsing " ~ srcs ~ meta ~ requires |
let test_arg_pos = let srcs = Fpath . [ ` File ( v " test / test_arg_pos . ml " ) ] in let meta = B0_meta . ( empty |> tag test ) in let requires = [ fmt ; logs_fmt ; bos ] in B0_ocaml . exe " test - arg - pos " ~ doc " : Test argument parsing " ~ srcs ~ meta ~ requires |
let watch = let srcs = Fpath . [ ` File ( v " test / watch . ml " ) ] in let meta = B0_meta . ( empty |> tag test ) in let requires = [ logs_fmt ; fmt_tty ; mtime ; mtime_clock_os ; rresult ; fpath ; bos ; bos_setup ] in B0_ocaml . exe " watch " ~ doc " : Watch files for changes . " ~ srcs ~ meta ~ requires |
let default = let meta = let open B0_meta in empty |> add authors [ " The bos programmers " ] |> add maintainers [ " Daniel Bünzli < daniel . buenzl i @ erratique . ch " ] > |> add homepage " https :// erratique . ch / software / bos " |> add online_doc " https :// erratique . ch / software / bos / doc " |> add license... |
module Provenance = struct type t = { module_path : Path . t ; location : Debuginfo . t ; original_ident : Ident . t ; } let print ppf { module_path ; location ; original_ident ; } = let printf fmt = Format . fprintf ppf fmt in printf " [ @< hov 1 ( " ; > printf " [ @< hov 1 ( > module_path @ % a ) ] @@ " Path . print ... |
module With_provenance = struct type t = | Without_provenance of backend_var | With_provenance of { var : backend_var ; provenance : Provenance . t ; } let create ? provenance var = match provenance with | None -> Without_provenance var | Some provenance -> With_provenance { var ; provenance ; } let var t = match t wit... |
let test_Error msg = let rec f msg n = if n = 0 then raise ( Error msg ) else 1 + f msg ( n - 1 ) in let exception_raised_internally ( ) = try Hashtbl . find ( Hashtbl . create 3 ) 0 with Not_found -> false in try f msg 5 with Error " a " -> print_string " a " ; print_newline ( ) ; 0 | Error " b " as exn -> print_strin... |
let test_Not_found ( ) = let rec aux n = if n = 0 then raise Not_found else 1 + aux ( n - 1 ) in try aux 5 with exn -> print_string " test_Not_found " ; print_newline ( ) ; ( try Hashtbl . find ( Hashtbl . create 3 ) 0 with Not_found -> raise exn ) |
let test_lazy = let rec aux n = if n = 0 then raise Not_found else 1 + aux ( n - 1 ) in let exception_raised_internally ( ) = try Hashtbl . find ( Hashtbl . create 3 ) 0 with Not_found -> ( ) in let l = lazy ( aux 5 ) in fun ( ) -> exception_raised_internally ( ) ; Lazy . force l |
let run g 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 test_Error [ | " a " ] ; | run test_Error [ | " b " ] ; | run test_Error [ | " c " ] ; | run test_Error [ | " d " ] ; | run test_Error [ | " e " ] ; | run test_Error [ | " f " ] ; | run test_Error [ | ] ; | run test_Not_found [ | ( ) ] ; | run test_lazy [ | ( ) ] ; | run test_lazy [ | ( ) ] ; | ( ) |
let rec f msg n = if n = 0 then raise ( Error msg ) else 1 + f msg ( n - 1 ) |
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 " c " ; print_newline ( ) ; raise ( Error " c " ) | exception ... |
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 . make cache_size 0 ; next_verify_ix = 424... |
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 [ @ inline never ] realloc_bbuf bbuf pos ( x : int ... |
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 = Array . map convert raw_slots in le... |
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 | None -> ( ) | Some line -> print_endline line ) |
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_mod in let set = flo... |
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 . exists w then configure_cursor w ! cursor end a... |
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 " ~ background : ( ` Color " yellow " ) ~ aspect... |
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 newSz_1 in newArr . ( ind ) <- ( n :: newArr . ... |
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 :: ( ! htab ) . ( ind ) ) |
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 ) , high ) in insert ( getId low ) ( getId high ) v... |
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 ( and2 r1 r2 ) | LESS -> mkNode ( and2 l1 n2 ) v1 ( and2 r... |
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 r1 r2 ) | LESS -> mkNode ( xor l1 n2 ) v1 ( xor r1 n2 ... |
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 i ) ( g ( i + 1 ) j ) ) in h 0 ( n - 1 ) |
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 succeeded := ! succeeded && test_hwb bdd ( rand... |
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 Std in let i = thread_idx_x + block_dim_x * b... |
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 ) 1 in for i = 0 to n - 1 do let c = ( let j = Ran... |
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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.