text
stringlengths
12
786k
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 Empty in h . data <- ndata ; let rec insert_bucket = function Empty -> ( ) | Cons ( key , data , rest...
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 info = let i = key_index h key in let bucket = Cons ( key , info , a_get h . data i ) in a_set 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 | Empty -> Empty | Cons ( k , i , next ) -> if compare k key = 0 then begin h . size <- h . size - 1 ; next end else Cons ( k , i , remove_bucket next ) in let i = key_index h key in a_set h . data i @@ remove_bucket @@ a_get h . ...
let rec find_rec key = function | Empty -> raise Not_found | Cons ( k , d , rest ) -> if compare key k = 0 then d else find_rec key rest
let find h key = match a_get h . data @@ key_index h key with | Empty -> raise Not_found | Cons ( k1 , d1 , rest1 ) -> if compare key k1 = 0 then d1 else match rest1 with | Empty -> raise Not_found | Cons ( k2 , d2 , rest2 ) -> if compare key k2 = 0 then d2 else match rest2 with | Empty...
let find_all h key = let rec find_in_bucket = function | Empty -> [ ] | Cons ( k , d , rest ) -> if compare k key = 0 then d :: find_in_bucket rest else find_in_bucket rest in find_in_bucket @@ a_get h . data @@ key_index h key
let replace h key info = let rec replace_bucket = function | Empty -> raise Not_found | Cons ( k , i , next ) -> if compare k key = 0 then Cons ( key , info , next ) else Cons ( k , i , replace_bucket next ) in let i = key_index h key in let l = a_get h . data i in try a_set h . da...
let mem h key = let rec mem_in_bucket = function | Empty -> false | Cons ( k , _d , rest ) -> compare k key = 0 || mem_in_bucket rest in mem_in_bucket @@ a_get h . data @@ key_index h key
let iter f h = let rec do_bucket = function | Empty -> ( ) | Cons ( k , d , rest ) -> f k d ; do_bucket rest in let d = h . data in for i = 0 to Array . length d - 1 do do_bucket @@ a_get d i done
let fold f h init = let rec do_bucket b accu = match b with Empty -> accu | Cons ( k , d , rest ) -> do_bucket rest ( f k d accu ) in let d = h . data in let accu = ref init in for i = 0 to Array . length d - 1 do accu := do_bucket ( a_get d i ) ! accu done ; ! accu
type statistics = { num_bindings : int ; num_buckets : int ; max_bucket_length : int ; bucket_histogram : int array }
let rec bucket_length accu = function | Empty -> accu | Cons ( _ , _ , 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 a_set histo l @@ a_get histo l + 1 ) h . data ; { num_bindings = h . size ; ...
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 ' a t val create : int -> ' a t val clear : ' a t -> unit val reset : ' a t -> unit val copy : ' a t -> ' a t val add : ' a t -> key -> ' a -> unit val remove : ' a t -> key -> unit val find : ' a t -> key -> ' a val find_all : ' a t -> key ...
module type SeededS = sig type key type ' a t val create : ? random : bool -> int -> ' a t val clear : ' a t -> unit val reset : ' a t -> unit val copy : ' a t -> ' a t val add : ' a t -> key -> ' a -> unit val remove : ' a t -> key -> unit val find : ' a t -> key -> ' a val ...
module MakeSeeded ( H : SeededHashedType ) : ( SeededS with type key = H . t ) = struct type key = H . t type ' a hashtbl = ( key , ' a ) t type ' a t = ' a hashtbl let create = create let clear = clear let reset = reset let copy = copy let key_index h key = ( H . hash h . se...
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
module type S = sig open Signal . Types val lut : int64 -> signal -> signal val muxcy : signal -> signal -> signal -> signal val inv : signal -> signal val xorcy : signal -> signal -> signal val muxf5 : signal -> signal -> signal -> signal val muxf6 : signal -> signal -> signal -> signal val muxf...
module LutEqn = struct type t = | Gnd | Vdd | Input of int64 | And of t * t | Or of t * t | Xor of t * t | Not of t let i0 = Input ( 0L ) let i1 = Input ( 1L ) let i2 = Input ( 2L ) let i3 = Input ( 3L ) let i4 = Input ( 4L ) let i5 = Input ( 5L ) let gnd = Gnd let vdd ...
module HardCaml_api = struct open Signal . Types open Signal . Comb open Signal . Seq let lut v sel = let n = 1 lsl ( width sel ) in let rec build i = if i = n then [ ] else let d = if Int64 . logand v ( Int64 . shift_left 1L i ) <> 0L then vdd else gnd in d :: build ( i + 1 ) in ...
module Unisim = struct open Utils open Signal . Types open Signal . Comb open Signal . Instantiation module B = Bits . Comb . IntbitsList let inv a = ( inst " INV " [ ] [ " I " , a ] [ " O " , 1 ] ) # o " O " let lut v sel = let w = width sel in let w ' = string_o...
module type T = sig open Signal . Types val x_lut : LutEqn . t -> signal -> signal val x_map : LutEqn . t -> signal list -> signal val x_and : signal -> signal -> signal val x_or : signal -> signal -> signal val x_xor : signal -> signal -> signal val x_not : signal -> signal val x_reduce_carry ...
module type LutSize = sig val max_lut : int end
module Lut4 = struct let max_lut = 4 end
module Lut6 = struct let max_lut = 6 end
module XMake ( X : S ) ( L : LutSize ) = struct open Utils open Signal . Types module S = Signal . Comb open S open LutEqn open L let x_lut f s = let i = eval ( width s ) f in X . lut i s let x_map f l = let w = List . hd l |> width in let lut n = x_lut f ( List . map ( fun s -> sel...
module XComb ( Synth : T ) = struct open Signal . Types include Signal . Base let ( ) &: = Synth . x_and let ( ) |: = Synth . x_or let ( ) ^: = Synth . x_xor let ( ) ~: = Synth . x_not let ( ) +: = Synth . x_add let ( ) -: = Synth . x_sub let ( ) ==: = Syn...
module XSynthesizeComb ( X : S ) ( L : LutSize ) = Transform . MakeCombTransform ( XComb ( XMake ( X ) ( L ) ) )
module XSynthesize ( X : S ) ( L : LutSize ) = open Signal . Types open Signal . Comb open Utils module C = Comb . Make ( XComb ( XMake ( X ) ( L ) ) ) open C module T = Transform . MakeCombTransform ( C ) let transform find signal = match signal with | Signal_reg ( id , r...
let debug fmt = Logging . debug " xenstored " fmt
let info fmt = Logging . info " xenstored " fmt
let error fmt = Logging . error " xenstored " fmt
module type DB_S = Irmin . S with type key = Irmin . Contents . String . Path . t and type value = string
let make ( ? prefer_merge = true ) config db_m = let module DB = ( val db_m : DB_S ) in DB . Repo . create config >>= fun repo -> DB . master Irmin_unix . task repo >>= fun db -> let module DB_View = Irmin . View ( DB ) in let module V = struct type t = { v : DB_View . t ; } l...
type bare_jid = string * string [ @@ deriving sexp ] sexp
type full_jid = bare_jid * string [ @@ deriving sexp ] sexp
type t = [ | ` Full of full_jid | ` Bare of bare_jid
let t_to_bare = function | ` Full ( b , _ ) _ -> b | ` Bare b -> b
let resource = function | ` Full ( _ , r ) r -> Some r | ` Bare _ -> None
let bare_jid_to_string ( u , d ) d = u ^ " " @ ^ d
let full_jid_to_string ( b , r ) r = bare_jid_to_string b ^ " " / ^ r
let jid_to_string = function | ` Full full -> full_jid_to_string full | ` Bare bare -> bare_jid_to_string bare
let string_to_jid_helper s = let s = Utils . validate_utf8 s in match Astring . String . cut ~ sep " " :@ s with | None -> None | Some ( _ , rest ) rest when rest = " " -> None | Some ( user , rest ) rest -> match Astring . String . cut ~ sep " " :/ rest with | None -> Some ( user , ...
let string_to_bare_jid s = match string_to_jid_helper s with | Some ( u , d , _ ) _ -> Some ( u , d ) d | None -> None
let string_to_full_jid s = match string_to_jid_helper s with | Some ( u , d , Some r ) r -> Some ( ( u , d ) d , r ) r | _ -> None
let string_to_jid s = match string_to_jid_helper s with | Some ( u , d , Some r ) r -> Some ( ` Full ( ( u , d ) d , r ) r ) r | Some ( u , d , None ) None -> Some ( ` Bare ( u , d ) d ) d | None -> None
let bare_jid_equal ( u , d ) d ( u ' , d ' ) d ' = u = u ' && d = d '
let compare_bare_jid ( u , d ) d ( u ' , d ' ) d ' = match compare u u ' with | 0 -> compare d d ' | x -> x
let hex_chars start s = let hex_char = function | ' a ' . . ' f ' | ' A ' . . ' F ' | ' 0 ' . . ' 9 ' -> true | _ -> false in let rec go idx s = if idx < String . length s then if hex_char ( String . get s idx ) idx then go ( succ idx ) idx s else false else true in go start s
let is_uuid s = let open String in length s = 36 && hex_chars 0 ( sub s 0 8 ) 8 && get s 8 = ' - ' && hex_chars 0 ( sub s 9 4 ) 4 && get s 13 = ' - ' && hex_chars 0 ( sub s 14 4 ) 4 && get s 18 = ' - ' && hex_chars 0 ( sub s 19 4 ) 4 && get s 23 = ' -...
let resource_similar a b = let alen = String . length a and blen = String . length b in if abs ( alen - blen ) blen > 4 then false else if is_uuid a && is_uuid b then true else let stop = min alen blen in let rec equal idx = if idx < stop then if String . get a idx = String . get b idx then equal ( ...
let jid_matches jid jid ' = match jid , jid ' with | ` Bare bare , ` Bare bare ' -> bare_jid_equal bare bare ' | ` Bare bare , ` Full ( bare ' , _ ) _ -> bare_jid_equal bare bare ' | ` Full ( bare , resource ) resource , ` Full ( bare ' , resource ' ) resour...
let xmpp_jid_to_jid jid = let { JID . lnode ; JID . ldomain ; JID . lresource ; _ } = jid in let lnode = Utils . validate_utf8 lnode and ldomain = Utils . validate_utf8 ldomain and lresource = Utils . validate_utf8 lresource in let bare = ( lnode , ldomain ) ldomain in if lresource = " " ...
let jid_to_xmpp_jid jid = JID . of_string ( jid_to_string jid ) jid
type t = { pos : string * Xmlm . pos ; name : Xmlm . name ; mutable attrs : Xmlm . attribute list ; mutable children : tree list ; }
let pp f node = let file , ( line , col ) = node . pos in Fmt . pf f " <% a > at % s :% d :% d " Xmlm . pp_name node . name file line col
let check_empty node = node . attrs |> List . iter ( function | ( ( " " , name ) , _ ) -> Fmt . failwith " Unexpected attribute % S in % a " name pp node | _ -> ( ) ) ; node . children |> List . iter ( function | E ( { name = ( " " , _ ) ; _ } a...
let take_elements name node f = let name = ( " " , name ) in let rec aux = function | [ ] -> [ ] , [ ] | E e :: xs when e . name = name -> let es , xs = aux xs in ( e :: es ) , xs | n :: xs -> let es , xs = aux xs in es , ( n :: xs ) in let chosen , rest = au...
let take_sole_opt name node f = match take_elements name node f with | [ ] -> None | [ x ] -> Some x | _ -> Fmt . failwith " Multiple % S children in % a " ! name pp node
let take_sole name node f = match take_sole_opt name node f with | Some x -> x | None -> Fmt . failwith " No % S child in % a " ! name pp node
let take_data node = let rec aux = function | [ ] -> [ ] , [ ] | D d :: xs -> let ds , xs = aux xs in ( d :: ds ) , xs | n :: xs -> let ds , xs = aux xs in ds , ( n :: xs ) in let chosen , rest = aux node . children in node . children <- rest ; match chosen with | ...
let take_attr_opt name n = let ( let ) + x f = Option . map f x in let rec extract = function | [ ] -> None | ( ( " " , k ) , v ) :: xs when k = name -> Some ( v , xs ) | x :: xs -> let + r , xs = extract xs in r , ( x :: xs ) in let + r , xs = extract n . a...
let take_attr name node = match take_attr_opt name node with | Some x -> x | None -> Fmt . failwith " Missing attribute % S on % a " name pp node
let parse ~ name ch f = let input = Xmlm . make_input ( ` Channel ch ) in let rec aux ~ level = let pos = name , Xmlm . pos input in match Xmlm . input input with | ` El_start ( name , attrs ) -> let children = aux ~ level ( : succ level ) in let rest = if level = 0 then [ ] ...
type readyState = | UNSENT | OPENED | HEADERS_RECEIVED | LOADING | DONE
type _ response = | ArrayBuffer : Typed_array . arrayBuffer t Opt . t response | Blob : # File . blob t Opt . t response | Document : Dom . element Dom . document t Opt . t response | JSON : ' a Opt . t response | Text : js_string t response | Default : string response object ( ' se...
module Event = struct type typ = xmlHttpRequest File . progressEvent t Dom . Event . typ let readystatechange = Dom . Event . make " readystatechange " let loadstart = Dom . Event . make " loadstart " let progress = Dom . Event . make " progress " let abort = Dom . Event . make "...
module type String = sig type t val empty : t val length : t -> int val append : t -> t -> t val lowercase : t -> t val iter : ( int -> unit ) -> t -> unit val of_string : std_string -> t val to_utf_8 : ( ' a -> std_string -> ' a ) -> ' a -> t -> ' a val compare : t -> t -> int e...
module type Buffer = sig type string type t exception Full val create : int -> t val add_uchar : t -> int -> unit val clear : t -> unit val contents : t -> string val length : t -> int end
module type S = sig type string type encoding = [ | ` UTF_8 | ` UTF_16 | ` UTF_16BE | ` UTF_16LE | ` ISO_8859_1 | ` US_ASCII ] type dtd = string option type name = string * string type attribute = name * string type tag = name * attribute list type signal = [ ` Dtd of dtd | ` El_s...
let utf8_len = [ | 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ...
let uchar_utf8 i = let b0 = i ( ) in begin match utf8_len . ( b0 ) with | 0 -> raise Malformed | 1 -> b0 | 2 -> let b1 = i ( ) in if b1 lsr 6 != 0b10 then raise Malformed else ( ( b0 land 0x1F ) lsl 6 ) lor ( b1 land 0x3F ) | 3 -> let b1 = i ( ) in let b2 = i ( ) ...
let int16_be i = let b0 = i ( ) in let b1 = i ( ) in ( b0 lsl 8 ) lor b1
let int16_le i = let b0 = i ( ) in let b1 = i ( ) in ( b1 lsl 8 ) lor b0
let uchar_utf16 int16 i = let c0 = int16 i in if c0 < 0xD800 || c0 > 0xDFFF then c0 else if c0 > 0xDBFF then raise Malformed else let c1 = int16 i in ( ( ( c0 land 0x3FF ) lsl 10 ) lor ( c1 land 0x3FF ) ) + 0x10000
let uchar_utf16be = uchar_utf16 int16_be
let uchar_utf16le = uchar_utf16 int16_le
let uchar_byte i = i ( )
let uchar_iso_8859_1 i = i ( )
let uchar_ascii i = let b = i ( ) in if b > 127 then raise Malformed else b
module Make ( String : String ) ( Buffer : Buffer with type string = String . t ) = struct type string = String . t let str = String . of_string let str_eq s s ' = ( compare s s ' ) = 0 let str_empty s = ( compare s String . empty ) = 0 let cat = String . append let str_of_cha...
module String = struct type t = string let empty = " " let length = String . length let append = ( ^ ) let lowercase = String . lowercase_ascii let iter f s = let len = Std_string . length s in let pos = ref ~- 1 in let i ( ) = incr pos ; if ! pos = len then raise Exit else Char . c...
module Buffer = struct type string = String . t type t = Buffer . t exception Full let create = Buffer . create let add_uchar b u = try let buf c = Buffer . add_char b ( Char . chr c ) in if u <= 0x007F then ( buf u ) else if u <= 0x07FF then ( buf ( 0xC0 lor ( u lsr 6 ) ) ; bu...
let rec pp_list ( ? pp_sep = Format . pp_print_cut ) pp_v ppf = function pp_v ppf v ; if vs <> [ ] then ( pp_sep ppf ( ) ; pp_list ~ pp_sep pp_v ppf vs )
let pp_name ppf ( p , l ) = if p <> " " then pp ppf " % s :% s " p l else pp ppf " % s " l
let pp_attribute ppf ( n , v ) = pp ppf " [ @< 1 ( >% a , , @% S ) ] " @ pp_name n v
let pp_tag ppf ( name , atts ) = let pp_sep ppf ( ) = pp ppf " ; @ " in pp ppf " [ @< 1 ( >% a , , [ @@< 1 [ >% a ] ] ) ] " @@ pp_name name ( pp_list ~ pp_sep pp_attribute ) atts
let pp_dtd ppf = function
let pp_signal ppf = function
let encode = let translate = function | ' > ' -> Some " & gt ; " | ' < ' -> Some " & lt ; " | ' & ' -> Some " & amp ; " | ' " ' -> Some " & quot ; " | c when ( c >= ' \ x20 ' && c <= ' \ xff ' ) xff ' || c = ' \ x09 ' || c = ' \ x0a ' || c =...
let rec add_value ( ? strict = false ) false f = function | Null -> f " < value >< nil /></ value " > | Int i -> f " < value " ; > if strict then f " < i8 " ; > f ( Int64 . to_string i ) i ; if strict then f " </ i8 " ; > f " </ value " > | Int32 i -> f " < value >< i4 " ; > f ( In...
let to_string ( ? strict = false ) false x = let buf = Buffer . create 128 in add_value ~ strict ( Buffer . add_string buf ) buf x ; Buffer . contents buf
let to_a ( ? strict = false ) false ~ empty ~ append x = let buf = empty ( ) in add_value ~ strict ( fun s -> append buf s ) s x ; buf
let string_of_call ( ? strict = false ) false call = let module B = Buffer in let buf = B . create 1024 in let add = B . add_string buf in add " <? xml version " =\ 1 . 0 " " ; \?> add " < methodCall >< methodName " ; > add ( encode call . name ) name ; add " </ methodName >< params " ;...
let add_response ( ? strict = false ) false add response = let v = if response . success then Dict [ " Status " , String " Success " ; " Value " , response . contents ] else Dict [ " Status " , String " Failure " ; " ErrorDescription " , response . contents ] in add " <? xml ...
let string_of_response ( ? strict = false ) false response = let module B = Buffer in let buf = B . create 256 in let add = B . add_string buf in add_response ~ strict add response ; B . contents buf
let a_of_response ( ? strict = false ) false ~ empty ~ append response = let buf = empty ( ) in let add s = append buf s in add_response ~ strict add response ; buf