text stringlengths 0 601k |
|---|
let check_name_of_type t = ignore ( name_of_type t ) |
let remove_names tyl = let tyl = List . map repr tyl in names := List . filter ( fun ( ty , _ ) -> not ( List . memq ty tyl ) ) ! names |
let visited_objects = ref ( [ ] : type_expr list ) |
let aliased = ref ( [ ] : type_expr list ) |
let delayed = ref ( [ ] : type_expr list ) |
let add_delayed t = if not ( List . memq t ! delayed ) then delayed := t :: ! delayed |
let is_aliased ty = List . memq ( proxy ty ) ! aliased |
let add_alias ty = let px = proxy ty in if not ( is_aliased px ) then begin aliased := px :: ! aliased ; add_named_var px end |
let aliasable ty = match ty . desc with Tvar _ | Tunivar _ | Tpoly _ -> false | Tconstr ( p , _ , _ ) -> not ( is_nth ( snd ( best_type_path p ) ) ) | _ -> true |
let namable_row row = row . row_name <> None && List . for_all ( fun ( _ , f ) -> match row_field_repr f with | Reither ( c , l , _ , _ ) -> row . row_closed && if c then l = [ ] else List . length l = 1 | _ -> true ) row . row_fields |
let rec mark_loops_rec visited ty = let ty = repr ty in let px = proxy ty in if List . memq px visited && aliasable ty then add_alias px else let visited = px :: visited in match ty . desc with | Tvar _ -> add_named_var ty | Tarrow ( _ , ty1 , ty2 , _ ) -> mark_loops_rec visited ty1 ; mark_loops_rec visited ty2 | Ttupl... |
let mark_loops ty = normalize_type Env . empty ty ; mark_loops_rec [ ] ty ; ; |
let reset_loop_marks ( ) = visited_objects := [ ] ; aliased := [ ] ; delayed := [ ] |
let reset ( ) = unique_names := Ident . empty ; reset_names ( ) ; reset_loop_marks ( ) |
let reset_and_mark_loops ty = reset ( ) ; mark_loops ty |
let reset_and_mark_loops_list tyl = reset ( ) ; List . iter mark_loops tyl |
let print_labels = ref true |
let rec tree_of_typexp sch ty = let ty = repr ty in let px = proxy ty in if List . mem_assq px ! names && not ( List . memq px ! delayed ) then let mark = is_non_gen sch ty in Otyp_var ( mark , name_of_type px ) else let pr_typ ( ) = match ty . desc with | Tvar _ -> Otyp_var ( is_non_gen sch ty , name_of_type ty ) | Ta... |
let typexp sch ppf ty = ! Xoprint . out_type ppf ( tree_of_typexp sch ty ) |
let type_expr ppf ty = typexp false ppf ty |
let type_scheme_max ( ? b_reset_names = true ) ppf ty = if b_reset_names then reset_names ( ) ; typexp true ppf ty |
let tree_of_type_scheme ty = reset_and_mark_loops ty ; tree_of_typexp true ty |
let tree_of_constraints params = List . fold_right ( fun ty list -> let ty ' = unalias ty in if proxy ty != proxy ty ' then let tr = tree_of_typexp true ty in ( tr , tree_of_typexp true ty ' ) :: list else list ) params [ ] |
let filter_params tyl = let params = List . fold_left ( fun tyl ty -> let ty = repr ty in if List . memq ty tyl then Btype . newgenty ( Tsubst ty ) :: tyl else ty :: tyl ) [ ] tyl in List . rev params |
let mark_loops_constructor_arguments = function | Cstr_tuple l -> List . iter mark_loops l | Cstr_record l -> List . iter ( fun l -> mark_loops l . ld_type ) l |
let rec tree_of_type_decl id decl = reset ( ) ; let params = filter_params decl . type_params in begin match decl . type_manifest with | Some ty -> let vars = free_variables ty in List . iter ( function { desc = Tvar ( Some " _ " ) } as ty -> if List . memq ty vars then ty . desc <- Tvar None | _ -> ( ) ) params | None... |
let tree_of_type_declaration id decl rs = Osig_type ( tree_of_type_decl id decl , tree_of_rec rs ) |
let tree_of_extension_constructor id ext es = reset ( ) ; let ty_name = Path . name ext . ext_type_path in let ty_params = filter_params ext . ext_type_params in List . iter add_alias ty_params ; List . iter mark_loops ty_params ; List . iter check_name_of_type ( List . map proxy ty_params ) ; mark_loops_constructor_ar... |
let tree_of_value_description id decl = let id = Ident . name id in let ty = tree_of_type_scheme decl . val_type in let vd = { oval_name = id ; oval_type = ty ; oval_prims = [ ] ; oval_attributes = [ ] } in let vd = match decl . val_kind with | Val_prim p -> Primitive . print p vd | _ -> vd in Osig_value vd |
let method_type ( _ , kind , ty ) = match field_kind_repr kind , repr ty with Fpresent , { desc = Tpoly ( ty , tyl ) } -> ( ty , tyl ) | _ , ty -> ( ty , [ ] ) |
let tree_of_metho sch concrete csil ( lab , kind , ty ) = if lab <> dummy_method then begin let kind = field_kind_repr kind in let priv = kind <> Fpresent in let virt = not ( Concr . mem lab concrete ) in let ( ty , tyl ) = method_type ( lab , kind , ty ) in let tty = tree_of_typexp sch ty in remove_names tyl ; Ocsg_me... |
let rec prepare_class_type params = function | Cty_constr ( _p , tyl , cty ) -> let sty = Ctype . self_type cty in if List . memq ( proxy sty ) ! visited_objects || not ( List . for_all is_Tvar params ) || List . exists ( deep_occur sty ) tyl then prepare_class_type params cty else List . iter mark_loops tyl | Cty_sign... |
let rec tree_of_class_type sch params = function | Cty_constr ( p ' , tyl , cty ) -> let sty = Ctype . self_type cty in if List . memq ( proxy sty ) ! visited_objects || not ( List . for_all is_Tvar params ) then tree_of_class_type sch params cty else Octy_constr ( tree_of_path p ' , tree_of_typlist true tyl ) | Cty_si... |
let tree_of_class_param param variance = ( match tree_of_typexp true param with Otyp_var ( _ , s ) -> s | _ -> " " ) , ? if is_Tvar ( repr param ) then ( true , true ) else variance |
let class_variance = List . map Variance . ( fun v -> mem May_pos v , mem May_neg v ) |
let tree_of_class_declaration id cl rs = let params = filter_params cl . cty_params in reset ( ) ; List . iter add_alias params ; prepare_class_type params cl . cty_type ; let sty = Ctype . self_type cl . cty_type in List . iter mark_loops params ; List . iter check_name_of_type ( List . map proxy params ) ; if is_alia... |
let tree_of_cltype_declaration id cl rs = let params = List . map repr cl . clty_params in reset ( ) ; List . iter add_alias params ; prepare_class_type params cl . clty_type ; let sty = Ctype . self_type cl . clty_type in List . iter mark_loops params ; List . iter check_name_of_type ( List . map proxy params ) ; if i... |
let wrap_env fenv ftree arg = let env = ! printing_env in set_printing_env ( fenv env ) ; let tree = ftree arg in set_printing_env env ; tree |
let filter_rem_sig item rem = match item , rem with | Sig_class _ , ctydecl :: tydecl1 :: tydecl2 :: rem -> ( [ ctydecl ; tydecl1 ; tydecl2 ] , rem ) | Sig_class_type _ , tydecl1 :: tydecl2 :: rem -> ( [ tydecl1 ; tydecl2 ] , rem ) | _ -> ( [ ] , rem ) |
let dummy = { type_params = [ ] ; type_arity = 0 ; type_kind = Type_abstract ; type_private = Public ; type_manifest = None ; type_variance = [ ] ; type_newtype_level = None ; type_loc = Location . none ; type_attributes = [ ] ; type_immediate = false ; type_unboxed = unboxed_false_default_false ; } |
let hide_rec_items = function | Sig_type ( id , _decl , rs ) :: rem when rs = Trec_first && not ! Clflags . real_paths -> let rec get_ids = function Sig_type ( id , _ , Trec_next ) :: rem -> id :: get_ids rem | _ -> [ ] in let ids = id :: get_ids rem in set_printing_env ( List . fold_right ( fun id -> Env . add_type ~ ... |
let rec tree_of_modtype ( ? ellipsis = false ) = function | Mty_ident p -> Omty_ident ( tree_of_path p ) | Mty_signature sg -> Omty_signature ( if ellipsis then [ Osig_ellipsis ] else tree_of_signature sg ) | Mty_functor ( param , ty_arg , ty_res ) -> let res = match ty_arg with None -> tree_of_modtype ~ ellipsis ty_re... |
module Exn = struct let protect f v ~ final = Spotlib . Exn . protect f v ~ finally : final end |
module Array = struct let shuffle ( ? random = Random . int ) a = let len = Array . length a - 1 in for i = 0 to len - 1 do let d = len - i in let j = random d + i in let x = Array . unsafe_get a i in let y = Array . unsafe_get a j in Array . unsafe_set a i y ; Array . unsafe_set a j x ; done end |
module Base = struct let ( !++ ) r = let v = ! r in incr r ; v end |
module Gc = struct open Gc let used_words ( ) = let c = get ( ) in set { c with minor_heap_size = 1000 ; } ; compact ( ) ; let s = stat ( ) in let res = s . live_words in set c ; res let with_big_compacts f v = let used_before = used_words ( ) in Spotlib . Spot . Exn . protect_with f v ~ finally ( : fun _ -> let used_a... |
let tnb data = try int_of_string ( List . hd ( String . split ' \ 000 ' data ) ) with _ -> 0 |
let do_test xb = let i = ref 0 in let disp op pkt = let tid , rid , ty , data = pkt in printf " % 3x % s % d ( % d ) % s " \% s " . \\ n " %! ! i op tid rid ( Xb . Op . to_string ty ) ( String . escaped data ) ; flush ( stdout ) ; in let y ( tid , ty , data ) = let spkt = ( tid , ! i , ty , data ) in disp " S : " spkt ... |
let ( ) = let xb = open_xb ( ) in finally ( fun ( ) -> do_test xb ) ( fun ( ) -> close_xb xb ) ; |
module type XStringSig = sig type xstring = UChar . t XArray . t val get : xstring -> int -> UChar . t val set : xstring -> int -> UChar . t -> unit val length : xstring -> int type index val look : xstring -> index -> UChar . t val nth : xstring -> int -> index val first : xstring -> index val last : xstring -> index ... |
module XStringAux : XStringSig = struct include XArray type xstring = UChar . t XArray . t let rec compare_aux i t1 t2 = if i >= length t1 then if i >= length t2 then 0 else ~- 1 else if i >= length t2 then 1 else match UChar . compare ( XArray . get t1 i ) i ( XArray . get t2 i ) i with 0 -> compare_aux ( i + 1 ) 1 t1... |
let init len f = XArray . init len ( UChar . chr_of_uint 0 ) 0 f |
module Buf = struct include XStringAux type buf = xstring let create bufsize = make ~ bufsize 0 ( UChar . chr_of_uint 0 ) 0 let contents x = x let add_string = add_xstring let add_buffer = add_xstring end |
module String = struct include String let of_char c = String . make 1 c let rev_map f string = let n = length string in String . init n ( fun i -> f string . [ n - i - 1 ] ) let rev_iter f string = for i = length string - 1 downto 0 do f string . [ i ] done let fold_left f accu string = let accu = ref accu in for i = 0... |
let test_boolean tested_f ( name , case , expected ) = let check ( ) = Alcotest . ( check bool ) name expected ( tested_f case ) in ( name , ` Quick , check ) |
let test_string tested_f ( name , case , expected ) = let check ( ) = Alcotest . ( check string ) name expected ( tested_f case ) in ( name , ` Quick , check ) |
let test_list tested_f ( name , case , expected ) = let check ( ) = Alcotest . ( check @@ list string ) name expected ( tested_f case ) in ( name , ` Quick , check ) |
let test_rev_map = let spec_rev = [ ( " " , " " ) ; ( " foo bar " , " rab oof " ) ] in let spec_func = [ ( " id " , Fun . id ) ; ( " uppercase_ascii " , Char . uppercase_ascii ) ] in let test ( f_name , f ) ( case , expected ) = let expected = String . map f expected in let name = Printf . sprintf { " |% s " produces "... |
let test_split = let test ? limit ( splitter , splitted , expected ) = let split , name = match limit with | None -> let name = Printf . sprintf { ' |% c ' splits " % s " } | splitter splitted in let split = XString . split ~ limit ( :- 1 ) in ( split , name ) | Some limit -> let name = Printf . sprintf { ' |% c ' spli... |
let test_split_f = let specs = [ ( XString . isspace , " foo bar " , [ " foo " ; " bar " ] ) ; ( XString . isspace , " foo bar " , [ " foo " ; " bar " ] ) ; ( XString . isspace , " foo \ n \ t \ r bar " , [ " foo " ; " bar " ] ) ; ( XString . isspace , " foo bar " , [ " foo " ; " bar " ] ) ; ( XString . isspace , " " ,... |
let test_has_substr = let spec = [ ( " " , " " , true ) ; ( " " , " foo bar " , true ) ; ( " f " , " foof " , true ) ; ( " foofo " , " foof " , false ) ; ( " foof " , " foof " , true ) ; ( " f " , " foof " , true ) ; ( " fo " , " foof " , true ) ; ( " of " , " foof " , true ) ; ( " ff " , " foof " , false ) ] in let te... |
let test_startswith = let spec = [ ( " " , " " , true ) ; ( " " , " foo bar " , true ) ; ( " foofo " , " foof " , false ) ; ( " foof " , " foof " , true ) ; ( " f " , " foof " , true ) ; ( " fo " , " foof " , true ) ; ( " of " , " foof " , false ) ; ( " ff " , " foof " , false ) ] in let test ( contained , container , ... |
let test_endswith = let spec = [ ( " " , " " , true ) ; ( " " , " foo bar " , true ) ; ( " ofoof " , " foof " , false ) ; ( " foof " , " foof " , true ) ; ( " f " , " foof " , true ) ; ( " fo " , " foof " , false ) ; ( " of " , " foof " , true ) ; ( " ff " , " foof " , false ) ] in let test ( contained , container , ex... |
let test_rtrim = let spec = [ ( " " , " " ) ; ( " \ n " , " " ) ; ( " \ n \ n " , " \ n " ) ; ( " \ n " , " \ n " ) ; ( " foo \ n " , " foo " ) ; ( " fo \ no " , " fo \ no " ) ] in let test ( case , expected ) = let name = Printf . sprintf { " |% s " gets trimmed to " % s " } | ( String . escaped case ) ( String . esca... |
let ( ) = Alcotest . run " Xstringext " [ test_rev_map ; test_split ; test_split_f ; test_has_substr ; test_startswith ; test_endswith ; test_rtrim ] |
let ( |> ) a b = b a |
let getdomainpath domid client = immediate client ( fun xs -> getdomainpath xs domid ) >>= fun dom_path -> return ( prefix ^ dom_path ) |
let readdir d client = Lwt . catch ( fun ( ) -> immediate client ( fun xs -> directory xs d ) ) ( function | Xs_protocol . Enoent _ -> return [ ] | e -> Lwt . fail e ) |
let read_opt path xs = Lwt . catch ( fun ( ) -> read xs path >>= fun x -> Lwt . return ( Some x ) ) ( function | Xs_protocol . Enoent _ -> return None | e -> Lwt . fail e ) |
let exists path xs = read_opt path xs >|= ( fun x -> x <> None ) |
module Device = struct type kind = Vif | Vbd | Tap | Pci | Vfs | Vfb | Vkbd let kind_of_string = function | " vif " -> Some Vif | " vbd " -> Some Vbd | " tap " -> Some Tap | " pci " -> Some Pci | " vfs " -> Some Vfs | " vfb " -> Some Vfb | " vkbd " -> Some Vkbd | x -> None let string_of_kind = function | Vif -> " vif "... |
module Domain = struct let make domid client = getdomainpath domid client >>= fun dom_path -> let uuid = Printf . sprintf " uuid -% d " domid in let name = " name " in let vm_path = prefix ^ " / vm " / ^ uuid in let vss_path = prefix ^ " / vss " / ^ uuid in let xsdata = [ " xsdata " , " xsdata " ] in let platformdata =... |
let vm_shutdown domid client = Domain . shutdown domid ( ) client >>= fun _ -> Domain . destroy domid client |
let vm_start domid client = let vbd devid = { Device . frontend = { Device . domid = domid ; kind = Device . Vbd ; devid = 0 } ; backend = { Device . domid = 0 ; kind = Device . Vbd ; devid = 0 } } in Domain . make domid client >>= fun ( ) -> Lwt_list . iter_s ( fun d -> Device . add d client ) [ vbd 0 ; vbd 1 ; vbd 2 ... |
let vm_cycle domid client = vm_start domid client >>= fun ( ) -> vm_shutdown domid client |
let rec between start finish = if start > finish then [ ] else start :: ( between ( start + 1 ) finish ) |
let sequential n client : unit Lwt . t = Lwt_list . iter_s ( fun domid -> vm_cycle domid client ) ( between 0 n ) |
let parallel n client = Lwt_list . iter_p ( fun domid -> vm_cycle domid client ) ( between 0 n ) |
let query m n client = Lwt_list . iter_s ( fun domid -> vm_start domid client ) ( between 0 n ) >>= fun ( ) -> let rec loop i = if i = m then Lwt . return_unit else begin Lwt_list . iter_p ( fun domid -> immediate client ( fun xs -> read xs ( Printf . sprintf " % s / local / domain /% d / name " prefix domid ) >>= fun ... |
let time f = let start = Unix . gettimeofday ( ) in f ( ) >>= fun ( ) -> return ( Unix . gettimeofday ( ) . - start ) |
let usage ( ) = let bin x = Sys . argv . ( 0 ) ^ x in let lines = [ bin " : a xenstore benchmark tool " ; " " ; " Usage " ; : bin " [ - path / var / run / xenstored / socket ] [ - n number of vms ] " ; ] in List . iter ( fun x -> Printf . fprintf stderr " % s \ n " x ) lines |
let main ( ) = let verbose = ref false in let args = Sys . argv |> Array . to_list |> List . tl in if List . mem " - h " args then begin usage ( ) ; return ( ) ; end else begin verbose := List . mem " - v " args ; let args = List . filter ( fun x -> x <> " - v " ) args in let extract args key = let result = ref None in... |
let _ = Lwt_main . run ( main ( ) ) |
let ( |> ) a b = b a |
type expr = | Val of string | Not of expr | And of expr * expr | Or of expr * expr | Eq of expr * expr |
let rec pretty_print ( ) = let open Format in function | Val x -> sprintf " " \% s " " \ x | Not x -> sprintf " Not ( [ @% a ] ) " @ pretty_print x | And ( x , y ) -> sprintf " And ( [ @% a , @ % a ] ) " @ pretty_print x pretty_print y | Or ( x , y ) -> sprintf " Or ( [ @% a , @ % a ] ) " @ pretty_print x pretty_print ... |
let rec to_conjunction = function | And ( x , y ) -> ( to_conjunction x ) @ ( to_conjunction y ) | Eq ( Val k , Val v ) -> [ k , v ] | _ -> raise Invalid_expression |
let parse_expr s = let open Genlex in let keywords = [ " ( " ; " ) " ; " not " ; " " ; = " and " ; " or " ] in let flatten s = let to_list s = let result = ref [ ] in Stream . iter ( fun x -> result := x :: ! result ) s ; List . rev ! result in let ident is = if is = [ ] then [ ] else [ Ident ( String . concat " " ( Li... |
let rec eval_expression expr xs = match expr with | Val path -> Lwt . catch ( fun ( ) -> read xs path >>= fun _k -> return true ) ( function Enoent _ -> return false | e -> Lwt . fail e ) | Not a -> eval_expression a xs >>= fun a ' -> return ( not ( a ' ) ) | And ( a , b ) -> eval_expression a xs >>= fun a ' -> eval_ex... |
let usage ( ) = let bin x = Sys . argv . ( 0 ) ^ x in let lines = [ bin " : a xenstore protocol client " ; " " ; " Usage " ; : bin " [ - path / var / run / xenstored / socket ] [ - restrict domid ] < subcommand > [ args ] " ; " " ; " Where < subcommand > can be one of " ; : " " ; bin " read < key " ; > " -- read the va... |
let main ( ) = let verbose = ref false in let args = Sys . argv |> Array . to_list |> List . tl in if List . mem " - h " args then begin usage ( ) ; return ( ) ; end else begin verbose := List . mem " - v " args ; let args = List . filter ( fun x -> x <> " - v " ) args in let extract args key = let result = ref None in... |
let _ = Lwt_main . run ( main ( ) ) |
module type IO = sig type ' a t = ' a Lwt . t val return : ' a -> ' a t val ( >>= ) : ' a t -> ( ' a -> ' b t ) -> ' b t type backend = [ ` xen | ` unix ] val backend : backend type channel val create : unit -> channel t val destroy : channel -> unit t val read : channel -> string -> int -> int -> int t val write : cha... |
module type S = sig type client val make : unit -> client Lwt . t val suspend : client -> unit Lwt . t val resume : client -> unit Lwt . t type handle val immediate : client -> ( handle -> ' a Lwt . t ) -> ' a Lwt . t val transaction : client -> ( handle -> ' a Lwt . t ) -> ' a Lwt . t val wait : client -> ( handle -> ... |
let ( |> ) a b = b a |
let ( ++ ) f g x = f ( g x ) |
module Watcher = struct type t = { mutable paths : StringSet . t ; mutable cancelling : bool ; c : unit Lwt_condition . t ; m : Lwt_mutex . t ; } let make ( ) = { paths = StringSet . empty ; cancelling = false ; c = Lwt_condition . create ( ) ; m = Lwt_mutex . create ( ) ; } let put ( x : t ) path = Lwt_mutex . with_lo... |
module Client = functor ( IO : IO with type ' a t = ' a Lwt . t ) -> struct module PS = PacketStream ( IO ) type client = { mutable transport : IO . channel ; ps : PS . stream ; rid_to_wakeup : ( int32 , Xs_protocol . t Lwt . u ) Hashtbl . t ; mutable dispatcher_thread : unit Lwt . t ; mutable dispatcher_shutting_down ... |
let finally f g = try let result = f ( ) in g ( ) ; result with e -> g ( ) ; raise e |
let with_mutex m f = Mutex . lock m ; finally f ( fun ( ) -> Mutex . unlock m ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.