text stringlengths 12 786k |
|---|
module IO = struct type ' a t = ' a Deferred . t let ( ) >>= = Deferred . ( ) >>= let return = Deferred . return type ic = ( unit -> unit Deferred . t ) * Reader . t type oc = ( unit -> unit Deferred . t ) * Writer . t type conn = unit let read_line ( _ , ic ) = Re... |
let exn_to_string = function | Api_errors . Server_error ( code , params ) -> Printf . sprintf " % s % s " code ( String . concat ~ sep " : " params ) | e -> Printf . sprintf " Caught unexpected exception : % s " ( Exn . to_string e ) |
let do_it uri string = let uri = Uri . of_string uri in let connection = M . make uri in let ( ) >>= = Deferred . ( ) >>= in Monitor . protect ( fun ( ) -> M . rpc connection string >>= function | Ok x -> return x | Error e -> eprintf " Caught : % s \ n " %! ( exn_to_string... |
let make ( ? timeout = 30 . ) uri call = let req = Xmlrpc . string_of_call call in do_it uri req >>| Xmlrpc . response_of_string |
let make_json ( ? timeout = 30 . ) uri call = let req = Jsonrpc . string_of_call call in do_it uri req >>| Jsonrpc . response_of_string |
module Client = Client . ClientF ( struct include Deferred let bind a f = bind a ~ f end ) |
module Lwt_unix_IO = struct type ' a t = ' a Lwt . t let ( ) >>= = Lwt . bind let return = Lwt . return let ( ) >> m n = m >>= fun _ -> n type ic = ( unit -> unit Lwt . t ) * Lwt_io . input_channel type oc = ( unit -> unit Lwt . t ) * Lwt_io . output_channel type conn ... |
let exn_to_string = function | Api_errors . Server_error ( code , params ) -> Printf . sprintf " % s % s " code ( String . concat " " params ) | e -> Printexc . to_string e |
let do_it uri string = let uri = Uri . of_string uri in let connection = M . make uri in Lwt . finalize ( fun ( ) -> M . rpc connection string >>= fun result -> match result with | Ok x -> return x | Error e -> Printf . fprintf stderr " Caught : % s \ n " %! ( exn_to_string e ) ; ... |
let make ( ? timeout = 30 . ) uri call = let string = Xmlrpc . string_of_call call in do_it uri string >>= fun result -> Lwt . return ( Xmlrpc . response_of_string result ) |
let make_json ( ? timeout = 30 . ) uri call = let string = Jsonrpc . string_of_call call in do_it uri string >>= fun result -> Lwt . return ( Jsonrpc . response_of_string result ) |
type cf = [ ` Average | ` Min | ` Max ] |
let string_of_cf = function | ` Average -> " AVERAGE " | ` Min -> " MIN " | ` Max -> " MAX " |
let cf_of_string = function | " AVERAGE " -> ` Ok ` Average | " MIN " -> ` Ok ` Min | " MAX " -> ` Ok ` Max | x -> ` Error ( ` Msg ( Printf . sprintf " Unknown consolidation function : % s " x ) ) |
module Legend = struct type cls = [ ` VM | ` Host | ` Other of string ] type t = string * cf * cls * Uuidm . t let colon = Re . Str . regexp_string " " : let of_string x = match Re . Str . split_delim colon x with | cf :: cls :: uuid :: name :: [ ] -> begin match cf_of_strin... |
type interval = [ | ` Seconds | ` Minute | ` Hour | ` Day | ` Other of int ] |
let seconds_of_interval = function | ` Seconds -> 5 | ` Minute -> 60 | ` Hour -> 60 * 60 | ` Day -> 24 * 60 * 60 | ` Other x -> x |
let rec archive_length_of_interval = function | ` Seconds -> 10 * 60 | ` Minute -> 2 * 60 * 60 | ` Hour -> 7 * 24 * 60 * 60 | ` Day -> 365 * 7 * 24 * 60 * 60 | ` Other x -> if x <= ( seconds_of_interval ` Seconds ) then ( archive_length_of_interval ` Seconds ) e... |
module Updates = struct let uri ~ host ~ authentication ~ start ( ? include_host = false ) ? interval ? cf ( ) = let ssl , scheme = match Uri . scheme host with | Some " https " -> true , " https " | Some " http " -> false , " http " | x -> failwith ( Printf . sprintf... |
let ( |> ) a b = b a |
let id x = x |
module Fake_IO = struct type ' a t = T of ' a let return x = T x let ( ) >>= t f = match t with | T x -> f x let ( ) >> m n = m >>= fun _ -> n let rec iter f = function | [ ] -> return ( ) | x :: xs -> f x >>= fun ( ) -> ( iter f xs ) type ic = string Queue . t type oc... |
let test_login_fail _ = let module M = Xen_api . Make ( Fake_IO ) in let open Fake_IO in let rpc req = let xml = Xmlrpc . string_of_call req in M . rpc ( M . make ( Uri . of_string " http :// 127 . 0 . 0 . 1 " ) ) / xml >>= function | Ok _ -> failwith " should have faile... |
let test_login_success _ = let session_id = " OpaqueRef : 9e9cf047 - 76d7 - 9f3a - 62ca - cb7bacf5a4e1 " in let result = Printf . sprintf " < methodResponse >< params >< param >< value >< struct >< member >< name > Status </ name >< value > Success </ value ></ member >< member >< na... |
let _ = let verbose = ref false in Arg . parse [ " - verbose " , Arg . Unit ( fun _ -> verbose := true ) , " Run in verbose mode " ; ] ( fun x -> Printf . fprintf stderr " Ignoring argument : % s " x ) " Test xen - api protocol code " ; let suite = " xen - api " ... |
type xexp = | Num of int | Var of string | Fn of string * xexp | App of xexp * xexp | If of xexp * xexp * xexp | Equal of xexp * xexp | Raise of xexp | Handle of xexp * int * xexp |
type value = | N of int | B of bool | C of closure |
type result = | Val of value | Exn of int |
let emptyEnv = ( fun x -> raise ( RunError ( " unbound id : " ^ x ) ) ) |
let bind e x v = ( fun y -> if y = x then v else e y ) |
let getInt = function | N n -> n | _ -> raise ( TypeError " not an int " ) |
let getBool = function | B b -> b | _ -> raise ( TypeError " not a bool " ) |
let getClosure = function | C c -> c | _ -> raise ( TypeError " not a function " ) |
let rec eval env exp = match exp with | Num n -> Val ( N n ) | Var x -> Val ( env x ) | Fn ( x , e ) -> Val ( C ( x , e , env ) ) | App ( e1 , e2 ) -> ( match eval env e1 with | Val v1 -> let ( x , e_body , env ' ) = getClosure v1 in ( match eval env e2 with | ... |
let run : xexp -> result = fun exp -> eval emptyEnv exp |
let indent i = let rec iter = function | 0 -> ( ) | n -> ps " " ; iter ( n - 1 ) in nl ( ) ; iter i |
let rec pp i exp = match exp with | Num n -> print_int n | Var s -> ps s | Fn ( x , e ) -> ps ( " fn " ^ x ^ " => " ) ; pp i e | App ( e , e ' ) -> ps " ( " ; pp i e ; ps " ) ( " ; pp i e ' ; ps " ) " | If ( e1 , e2 , e3 ) -> indent ( i ... |
let print = pp 0 |
let rec is_sugarless = function | Num _ | Var _ -> true | Fn ( _ , e ) -> is_sugarless e | App ( e1 , e2 ) | Equal ( e1 , e2 ) -> is_sugarless e1 && is_sugarless e2 | If ( e1 , e2 , e3 ) -> is_sugarless e1 && is_sugarless e2 && is_sugarless e3 | Raise _ | Handle _ -> fals... |
type t = { po_content : po_content ; translated : SetString . t } |
let translations = ref { po_content = empty_po ; translated = SetString . empty } |
let default_textdomain = ref None |
let current_file = ref " " |
let add_translation loc singular plural_opt domain = let t = ! translations in let filepos = let start = loc . Location . loc_start in let fname = match start . Lexing . pos_fname with " " -> ! current_file | fname -> fname in ( fname , start . Lexing . pos_lnum ) in let translated = Se... |
let output_translations ? output_file t = let fd = match output_file with Some f -> open_out f | None -> stdout in set_binary_mode_out fd true ; Marshal . to_channel fd t . po_content [ ] |
let rec is_like lid = function | [ ] -> false | func :: functions -> ( match lid with | ( Lident f | Ldot ( _ , f ) ) when f = func -> true | _ -> is_like lid functions ) |
let visit_expr ( iterator : Ast_iterator . iterator ) expr = let loc = expr . pexp_loc in match expr . pexp_desc with | Pexp_apply ( { pexp_desc = Pexp_ident { Asttypes . txt = lid ; _ } ; _ } , ( Asttypes . Nolabel , { pexp_desc = Pexp_constant ( Pconst_string ( singula... |
let ast_iterator = { Ast_iterator . default_iterator with expr = visit_expr } |
let go fn = current_file := fn ; try let lexbuf = Lexing . from_channel ( open_in fn ) in let structure = Parse . implementation lexbuf in ast_iterator . Ast_iterator . structure ast_iterator structure with exn -> failwith ( fn ^ " : " ^ Printexc . to_string exn ) |
let ( ) = Arg . parse [ ] go " " ; output_translations ! translations |
let hash x = seeded_hash_param 10 100 0 x |
let hash_param n1 n2 x = seeded_hash_param n1 n2 0 x |
let seeded_hash seed x = seeded_hash_param 10 100 seed x |
type ' a t = { mutable size : int ; mutable data : ' a list array ; mutable seed : int ; initial_size : int ; } |
let randomized_default = let params = try Sys . getenv " OCAMLRUNPARAM " with Not_found -> try Sys . getenv " CAMLRUNPARAM " with Not_found -> " " in String . contains params ' R ' |
let randomized = ref randomized_default |
let randomize ( ) = randomized := true |
let prng = lazy ( Random . State . make_self_init ( ) ) |
let rec power_2_above x n = if x >= n then x else if x * 2 > Sys . max_array_length then x else power_2_above ( x * 2 ) n |
let create ( ? random = ! randomized ) initial_size = let s = power_2_above 16 initial_size in let seed = if random then Random . State . bits ( Lazy . force prng ) else 0 in { initial_size = s ; size = 0 ; seed = seed ; data = Array . make s [ ] } |
let clear h = h . size <- 0 ; let len = Array . length h . data in for i = 0 to len - 1 do h . data . ( i ) <- [ ] done |
let reset h = let len = Array . length h . data in if Obj . size ( Obj . repr h ) < 4 || len = h . initial_size then clear h else begin h . size <- 0 ; h . data <- Array . make h . initial_size [ ] end |
let copy h = { h with data = Array . copy h . data } |
let length h = h . size |
let resize indexfun h = let odata = h . data in let osize = Array . length odata in let nsize = osize * 2 in if nsize < Sys . max_array_length then begin let ndata = Array . make nsize [ ] in h . data <- ndata ; let rec insert_bucket = function [ ] -> ( ) | key :: rest -> insert_bu... |
let key_index h key = if Obj . size ( Obj . repr h ) >= 3 then ( seeded_hash_param 10 100 h . seed key ) land ( Array . length h . data - 1 ) else ( old_hash_param 10 100 key ) mod ( Array . length h . data ) |
let add h key = let i = key_index h key in let bucket = key :: h . data . ( i ) in h . data . ( i ) <- bucket ; h . size <- h . size + 1 ; if h . size > Array . length h . data lsl 1 then resize key_index h |
let remove h key = let rec remove_bucket = function | [ ] -> [ ] | k :: next -> if compare k key = 0 then begin h . size <- h . size - 1 ; next end else k :: remove_bucket next in let i = key_index h key in h . data . ( i ) <- remove_bucket h . data . ( i ) |
let rec find_rec key = function | [ ] -> raise Not_found | k :: rest -> if compare key k = 0 then k else find_rec key rest |
let find h key = match h . data . ( key_index h key ) with | [ ] -> raise Not_found | k1 :: rest1 -> if compare key k1 = 0 then k1 else match rest1 with | [ ] -> raise Not_found | k2 :: rest2 -> if compare key k2 = 0 then k2 else match rest2 with | [ ] -> raise Not_found | k3 :: r... |
let find_all h key = let rec find_in_bucket = function | [ ] -> [ ] | k :: rest -> if compare k key = 0 then k :: find_in_bucket rest else find_in_bucket rest in find_in_bucket h . data . ( key_index h key ) |
let replace h key = let rec replace_bucket = function | [ ] -> raise Not_found | k :: next -> if compare k key = 0 then k :: next else k :: replace_bucket next in let i = key_index h key in let l = h . data . ( i ) in try h . data . ( i ) <- replace_bucket l with Not_found -> h . da... |
let mem h key = let rec mem_in_bucket = function | [ ] -> false | k :: rest -> compare k key = 0 || mem_in_bucket rest in mem_in_bucket h . data . ( key_index h key ) |
let iter f h = let rec do_bucket = function | [ ] -> ( ) | k :: rest -> f k ; do_bucket rest in let d = h . data in for i = 0 to Array . length d - 1 do do_bucket d . ( i ) done |
let fold f h init = let rec do_bucket b accu = match b with [ ] -> accu | k :: rest -> do_bucket rest ( f k accu ) in let d = h . data in let accu = ref init in for i = 0 to Array . length d - 1 do accu := do_bucket d . ( i ) ! accu done ; ! accu |
let find_or_add tbl v = try find tbl v with | Not_found -> add tbl v ; v |
type statistics = { num_bindings : int ; num_buckets : int ; max_bucket_length : int ; bucket_histogram : int array } |
let rec bucket_length accu = function | [ ] -> accu | _ :: rest -> bucket_length ( accu + 1 ) rest |
let stats h = let mbl = Array . fold_left ( fun m b -> max m ( bucket_length 0 b ) ) 0 h . data in let histo = Array . make ( mbl + 1 ) 0 in Array . iter ( fun b -> let l = bucket_length 0 b in histo . ( l ) <- histo . ( l ) + 1 ) h . data ; { num_bindings = h .... |
module type HashedType = sig type t val equal : t -> t -> bool val hash : t -> int end |
module type SeededHashedType = sig type t val equal : t -> t -> bool val hash : int -> t -> int end |
module type S = sig type key type t val create : int -> t val clear : t -> unit val reset : t -> unit val copy : t -> t val add : t -> key -> unit val remove : t -> key -> unit val find : t -> key -> key val find_all : t -> key -> key list val replace : t -> key -> unit val mem : t -> key -> ... |
module type SeededS = sig type key type t val create : ? random : bool -> int -> t val clear : t -> unit val reset : t -> unit val copy : t -> t val add : t -> key -> unit val remove : t -> key -> unit val find : t -> key -> key val find_all : t -> key -> key list val replace : t -> key -> un... |
module MakeSeeded ( H : SeededHashedType ) : ( SeededS with type key = H . t ) = struct type key = H . t type hashtbl = key t type t = hashtbl let create = create let clear = clear let reset = reset let copy = copy let key_index h key = ( H . hash h . seed key ) land ( Array . length... |
module Make ( H : HashedType ) : ( S with type key = H . t ) = struct include MakeSeeded ( struct type t = H . t let equal = H . equal let hash ( _seed : int ) x = H . hash x end ) let create sz = create ~ random : false sz end |
int -> int -> int -> ' a -> int = " caml_hash " " noalloc " int -> int -> ' a -> int = " caml_hash_univ_param " " noalloc " |
let hash x = seeded_hash_param 10 100 0 x |
let hash_param n1 n2 x = seeded_hash_param n1 n2 0 x |
let seeded_hash seed x = seeded_hash_param 10 100 seed x |
type ( ' a , ' b ) t = { mutable size : int ; mutable data : ( ' a , ' b ) bucketlist array ; mutable seed : int ; initial_size : int ; } Empty | Cons of ' a * ' b * ( ' a , ' b ) bucketlist |
let randomized_default = let params = try Sys . getenv " OCAMLRUNPARAM " with Not_found -> try Sys . getenv " CAMLRUNPARAM " with Not_found -> " " in String . contains params ' R ' |
let randomized = ref randomized_default |
let randomize ( ) = randomized := true |
let prng = lazy ( Random . State . make_self_init ( ) ) |
let rec power_2_above x n = if x >= n then x else if x * 2 > Sys . max_array_length then x else power_2_above ( x * 2 ) n |
let create ( ? random = ! randomized ) initial_size = let s = power_2_above 16 initial_size in let seed = if random then Random . State . bits ( Lazy . force prng ) else 0 in { initial_size = s ; size = 0 ; seed = seed ; data = Array . make s Empty } |
let clear h = h . size <- 0 ; let len = Array . length h . data in for i = 0 to len - 1 do h . data . ( i ) <- Empty done |
let reset h = let len = Array . length h . data in if Obj . size ( Obj . repr h ) < 4 || len = h . initial_size then clear h else begin h . size <- 0 ; h . data <- Array . make h . initial_size Empty end |
let copy h = { h with data = Array . copy h . data } |
let length h = h . size |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.