text stringlengths 0 601k |
|---|
let rec firsts = function | [ ] -> assert false | [ p ] -> [ ] , p | p :: l -> let head , tail = firsts l in p :: head , tail |
module State = struct type ' a t = | Empty | Cons of ' a * ' a t | Par of ' a t * ' a t let singleton x = Cons ( x , Empty ) let cons x s = Cons ( x , s ) let seq s1 s2 = match s1 , s2 with | ( Empty , s ) | ( s , Empty ) -> s | _ -> Seq ( s1 , s2 ) let par s1 s2 = match s1 , s2 with | ( Empty , s ) | ( s , Empty ) -> ... |
let internal_error message printer input = Format . eprintf " [ @ Internal error ( % s ) . @ % a . ] " @@ message printer input ; raise Error |
module Context = struct type t external create : unit -> t = " caml_zmq_new " external terminate : t -> unit = " caml_zmq_term " type int_option = | ZMQ_IO_THREADS | ZMQ_MAX_SOCKETS | ZMQ_IPV6 external set_int_option : t -> int_option -> int -> unit = " caml_zmq_ctx_set_int_option " external get_int_option : t -> int_o... |
module Msg = struct open Bigarray type t type bigstring = ( char , int8_unsigned_elt , c_layout ) c_layout Array1 . t external native_init_data : bigstring -> int -> int -> t = " caml_zmq_msg_init_data " let init_data ( ? offset = 0 ) 0 ? length buf = let length = let max_possible = Array1 . dim buf - offset in match l... |
module Socket = struct open Stdint type + ' a t type ' a kind = int let pair = 0 let pub = 1 let sub = 2 let req = 3 let rep = 4 let dealer = 5 let router = 6 let pull = 7 let push = 8 let xpub = 9 let xsub = 10 let stream = 11 external create : Context . t -> ' a kind -> ' a t = " caml_zmq_socket " external close : ' ... |
module Proxy = struct external zmq_proxy2 : ' a Socket . t -> ' b Socket . t -> unit = " caml_zmq_proxy2 " external zmq_proxy3 : ' a Socket . t -> ' b Socket . t -> ' c Socket . t -> unit = " caml_zmq_proxy3 " let create ? capture frontend backend = match capture with | Some capture -> zmq_proxy3 frontend backend captu... |
module Poll = struct type t type poll_event = In | Out | In_out type ' a poll_mask = ( ' a Socket . t * poll_event ) poll_event let mask_in_out t = ( t :> [ ` Pair ` | Pub ` | Sub ` | Req ` | Rep ` | Dealer ` | Router ` | Pull ` | Push ` | Xsub ` | Xpub ` | Stream ] Stream Socket . t ) , In_out let mask_in t = ( t :> [... |
module Monitor = struct type t = string type address = string type error_no = int type error_text = string type event = | Connected of address * Unix . file_descr | Connect_delayed of address | Connect_retried of address * int | Listening of address * Unix . file_descr | Bind_failed of address * error_no * error_text |... |
module Z85 = struct external encode : string -> string = " caml_z85_encode " external decode : string -> string = " caml_z85_decode " end |
module Curve = struct external keypair : unit -> string * string = " caml_curve_keypair " end |
let zmq_raise e str func_name = let exn = match e with | I_ENOTSUP -> Unix ( . Unix_error ( EOPNOTSUPP , func_name , ) ) " " | I_EPROTONOSUPPORT -> Unix ( . Unix_error ( EPROTONOSUPPORT , func_name , ) ) " " | I_ENOBUFS -> Unix ( . Unix_error ( ENOBUFS , func_name , ) ) " " | I_ENETDOWN -> Unix ( . Unix_error ( ENETDOW... |
let ( ) = Callback . register " Zmq . zmq_raise " zmq_raise |
let debug fmt = Printf . ksprintf ( fun s -> print_endline s ; flush stdout ) stdout fmt |
let sleep t = ignore ( ignoreUnix . select [ ] [ ] [ ] ( ( float t ) t . / 1000 . 0 ) 0 ) 0 |
let dump_events l = let f = function | None -> " None " | Some In -> " In " | Some Out -> " Out " | Some In_out -> " In / Out " in let l = Array . to_list ( Array . map f l ) l in [ " " | ^ ( String . concat " ; " l ) l ^ ] " " | |
let test_ctx_options ( ) = let ctx = Context . create ( ) in let test_set_get_int msg setter getter ctx v = let default = getter ctx in setter ctx v ; assert_equal ~ msg ~ printer : string_of_int v ( getter ctx ) ctx ; setter ctx default ; assert_equal ~ msg default ( getter ctx ) ctx ; ( ) in let test_set_get_bool msg... |
let test_socket_options ( ) = let ctx = Context . create ( ) in let socket = create ctx push in let test_set_get_int msg setter getter socket v = let default = getter socket in setter socket v ; assert_equal ~ msg ~ printer : string_of_int v ( getter socket ) socket ; setter socket default ; assert_equal ~ msg default ... |
let test_monitor ( ) = let endpoint = " ipc :// monitor_socket " in let expect_handshake = match Zmq . version ( ) with | ( 4 , n , _ ) _ when n < 3 -> false | ( 3 , _ , _ ) _ -> failwith " Only zmq version 4 or higher is supported " | _ -> true in let assert_event name socket event = let printer x = x in let rec cmp s... |
let test_proxy ( ) = let ctx = Zmq . Context . create ( ) in let pull_endpoint = " inproc :// pull " in let pub_endpoint = " inproc :// pub " in let pull = Zmq . Socket . create ctx pull in let pub = Zmq . Socket . create ctx pub in let proxy ( pull , pub ) pub = Zmq . Socket . bind pull pull_endpoint ; Zmq . Socket . ... |
let test_unix_exceptions = bracket ( fun ( ) -> let ctx = Zmq . Context . create ( ) in let s = Zmq . Socket . create ctx pull in ( ctx , s ) s ) ( fun ( _ , s ) s -> let mask = Zmq . Poll . of_masks [ | s , Zmq . Poll . In ] | in Sys ( . set_signal sigalrm ( Signal_handle ( fun _ -> ( ) ) ) ) ; ignore ( Unix . alarm 1... |
let test_zmq_exception = bracket ( fun ( ) -> let ctx = Zmq . Context . create ( ) in let socket = Zmq . Socket . create ctx req in ( ctx , socket ) socket ) ( fun ( _ , socket ) socket -> assert_raises ( Zmq . ZMQ_exception ( ZMQ_exceptionZmq . EFSM , " Operation cannot be accomplished in current state ) ) " ( fun ( )... |
let test_socket_gc ( ) = let sock = let ctx = Zmq . Context . create ( ) in Zmq . Socket . create ctx Zmq . Socket . req in Gc . compact ( ) ; Zmq . Socket . close sock ; Gc . compact ( ) |
let test_context_gc ( ) = let ctx = let ctx = Zmq . Context . create ( ) in let sock = Zmq . Socket . create ctx Zmq . Socket . pair in Zmq . Socket . connect sock " ipc :// context_gc_socket " ; Zmq . Socket . send sock " test " ; ctx in Gc . compact ( ) ; Zmq . Context . terminate ctx ; ( ) |
let test_z85 ( ) = let binary = " \ xBB \ x88 \ x47 \ x1D \ x65 \ xE2 \ x65 \ x9B " ^ " \ x30 \ xC5 \ x5A \ x53 \ x21 \ xCE \ xBB \ x5A " ^ " \ xAB \ x2B \ x70 \ xA3 \ x98 \ x64 \ x5C \ x26 " ^ " \ xDC \ xA2 \ xB2 \ xFC \ xB4 \ x3F \ xC5 \ x18 " in let ascii = " Yne @$ w - vo < fVvi ] fVvia < NY6T1ed : M $ fCG [ * IaLV... |
let suite = " zmq test " >::: [ " request reply " >:: ( bracket ( fun ( ) -> let ctx = Zmq . Context . create ( ) in let req = create ctx req in let rep = create ctx rep in ctx , req , rep ) ( fun ( _ , req , rep ) rep -> let endpoint = " inproc :// endpoint " in bind rep endpoint ; connect req endpoint ; send req " re... |
module type ZN = sig type t include S . B58_DATA with type t := t include S . ENCODER with type t := t val zero : t val one : t val n : Z . t val ( + ) : t -> t -> t val ( * ) : t -> t -> t val ( - ) : t -> t -> t val ( = ) : t -> t -> bool val of_int : int -> t val of_Z : Z . t -> t val to_Z : t -> Z . t val of_bits_e... |
module type INT = sig val n : Z . t end |
module MakeZn ( N : INT ) ( B : sig val b58_prefix : string end ) : ZN = struct type t = Z . t let n = N . n let max_char_length = 2 * Z . numbits n let zero = Z . zero let one = Z . one let of_Z r = Z . ( erem r n ) let to_Z a = a let of_int u = u |> Z . of_int |> of_Z let to_bits h = h |> Zplus . serialize |> fun s -... |
module Stable = struct module Full_data = struct module V1 = struct module Index = struct type t = int let next = Int . succ let prev = Int . pred let before_first_transition = - 1 let to_external t = max 0 t let of_external ( _ : t ) = - 1 include Binable . Of_binable_without_uuid [ @ alert " - legacy " ] ( Int ) ( st... |
let sexp_of_t t = Sexp . Atom t . name |
let likely_machine_zones = ref [ " America / New_York " ; " Europe / London " ; " Asia / Hong_Kong " ; " America / Chicago " ] ; ; |
let utc = of_utc_offset ~ hours : 0 |
let name zone = zone . name |
let reset_transition_cache t = t . last_regime_index <- Index . before_first_transition |
let get_regime_exn t index = if index < 0 then t . default_local_time_type else t . transitions . ( index ) . new_regime ; ; |
module Mode = struct type t = | Absolute | Date_and_ofday end |
let effective_start_time ~ mode ( x : Transition . t ) = let open Int63 . O in match ( mode : Mode . t ) with | Absolute -> x . start_time_in_seconds_since_epoch | Date_and_ofday -> x . start_time_in_seconds_since_epoch + x . new_regime . utc_offset_in_seconds ; ; |
let index_lower_bound_contains_seconds_since_epoch t index ~ mode seconds = index < 0 || Int63 . ( >= ) seconds ( effective_start_time ~ mode t . transitions . ( index ) ) ; ; |
let index_upper_bound_contains_seconds_since_epoch t index ~ mode seconds = index + 1 >= Array . length t . transitions || Int63 . ( < ) seconds ( effective_start_time ~ mode t . transitions . ( index + 1 ) ) ; ; |
let binary_search_index_of_seconds_since_epoch t ~ mode seconds : Index . t = Array . binary_search_segmented t . transitions ` Last_on_left ~ segment_of ( : fun transition -> if Int63 . ( <= ) ( effective_start_time transition ~ mode ) seconds then ` Left else ` Right ) |> Option . value ~ default : Index . before_fir... |
let index_of_seconds_since_epoch t ~ mode seconds = let index = let index = t . last_regime_index in if not ( index_lower_bound_contains_seconds_since_epoch t index ~ mode seconds ) then ( let index = index - 1 in if not ( index_lower_bound_contains_seconds_since_epoch t index ~ mode seconds ) then binary_search_index_... |
module Time_in_seconds : sig include Zone_intf . Time_in_seconds module Span = struct type t = Int63 . t let of_int63_seconds = ident let to_int63_seconds_round_down_exn = ident end module Absolute = struct type t = Int63 . t let of_span_since_epoch = ident let to_span_since_epoch = ident end module Date_and_ofday = st... |
let index t time = Time_in_seconds . to_span_since_epoch time |> Time_in_seconds . Span . to_int63_seconds_round_down_exn |> index_of_seconds_since_epoch t ~ mode : Absolute ; ; |
let index_of_date_and_ofday t time = Time_in_seconds . Date_and_ofday . to_synthetic_span_since_epoch time |> Time_in_seconds . Span . to_int63_seconds_round_down_exn |> index_of_seconds_since_epoch t ~ mode : Date_and_ofday ; ; |
let index_has_prev_clock_shift t index = index >= 0 && index < Array . length t . transitions |
let index_has_next_clock_shift t index = index_has_prev_clock_shift t ( index + 1 ) |
let index_prev_clock_shift_time_exn t index = let transition = t . transitions . ( index ) in transition . start_time_in_seconds_since_epoch |> Time_in_seconds . Span . of_int63_seconds |> Time_in_seconds . of_span_since_epoch ; ; |
let index_next_clock_shift_time_exn t index = index_prev_clock_shift_time_exn t ( index + 1 ) ; ; |
let index_prev_clock_shift_amount_exn t index = let transition = t . transitions . ( index ) in let after = transition . new_regime in let before = if index = 0 then t . default_local_time_type else t . transitions . ( index - 1 ) . new_regime in Int63 . ( - ) after . utc_offset_in_seconds before . utc_offset_in_second... |
let index_next_clock_shift_amount_exn t index = index_prev_clock_shift_amount_exn t ( index + 1 ) ; ; |
let index_abbreviation_exn t index = let regime = get_regime_exn t index in regime . abbrv ; ; |
let index_offset_from_utc_exn t index = let regime = get_regime_exn t index in Time_in_seconds . Span . of_int63_seconds regime . utc_offset_in_seconds ; ; |
module type Time_in_seconds = sig module Span : sig type t val of_int63_seconds : Int63 . t -> t val to_int63_seconds_round_down_exn : t -> Int63 . t end module Date_and_ofday : sig type t val of_synthetic_span_since_epoch : Span . t -> t val to_synthetic_span_since_epoch : t -> Span . t end type t val of_span_since_ep... |
module type S = sig type t [ @@ deriving sexp_of , compare ] val input_tz_file : zonename : string -> filename : string -> t val likely_machine_zones : string list ref val of_utc_offset : hours : int -> t val utc : t val name : t -> string val original_filename : t -> string option val digest : t -> Md5 . t option modu... |
module type S_stable = sig type t module Full_data : sig module V1 : Stable_module_types . S0_without_comparator with type t = t end end |
module type Zone = sig module type S = S module type S_stable = S_stable include S module Stable : S_stable with type t := t end |
let month_limits = Map . Poly . of_alist_exn [ 1 , 31 ; 2 , 28 ; 3 , 31 ; 4 , 30 ; 5 , 31 ; 6 , 30 ; 7 , 31 ; 8 , 31 ; 9 , 30 ; 10 , 31 ; 11 , 30 ; 12 , 31 ] |
let random_time state = let year = 1970 + Random . State . int state 67 in let month = 1 + ( Random . State . int state 12 ) in let day = 1 + ( Random . State . int state ( Map . find_exn month_limits month ) ) in let hour = Random . State . int state 12 + 8 in let min = Random . State . int state 60 in let sec = Rando... |
let random_time_str state = let year , month , day , hour , min , sec , ms , _mic = random_time state in sprintf " % d . -% 2d . -% 2d . % 2d . :% 2d . :% 2d . . % 3d000 " year month day hour min sec ms ; ; |
let random_tm state = let ( year , month , day , hour , min , sec , _ , _ ) = random_time state in { Unix . tm_sec = sec ; tm_min = min ; tm_hour = hour ; tm_mday = day ; tm_mon = month ; tm_year = year - 1900 ; tm_wday = 0 ; tm_yday = 0 ; tm_isdst = false ; } |
let zone_tests = ref [ ] |
let add name test = zone_tests := ( name >:: test ) :: ! zone_tests |
let add_random_string_round_trip_test state s1 = let pos_neg = if Random . State . bool state then " " + else " " - in let distance = Int . to_string ( Random . State . int state 10 + 1 ) in let s2 = String . concat [ s1 ; pos_neg ; distance ; " : 00 " ] in let zone = ( force Time . Zone . local ) in let s1 = let t = T... |
let add_random_string_round_trip_tests state = for _ = 1 to 100 do add_random_string_round_trip_test state ( random_time_str state ) done ; ; ; |
let add_roundtrip_conversion_test state ( zone_name , ( zone : Time . Zone . t ) ) = add ( " roundtrip conversion " ^ zone_name ) ( fun ( ) -> let tm = random_tm state in let unix_time = 1664476678 . 000 in let time = Time . of_span_since_epoch ( Time . Span . of_sec unix_time ) in let ( zone_date , zone_ofday ) = let ... |
module Localtime_test_data = struct type t = { zone_name : string ; unix_time : float ; localtime_date_string : string ; localtime_ofday_string : string ; our_date_string : string ; our_ofday_string : string ; } [ @@ deriving sexp ] end |
let add_random_localtime_tests state = List . iter ( Time . Zone . initialized_zones ( ) ) ~ f ( : fun ( zone_name , zone ) -> add ( " localtime " ^ zone_name ) ( fun ( ) -> let tm = random_tm state in let tm = Unix . gmtime ( Unix . timegm tm ) in Unix . putenv ~ key " : TZ " ~ data : zone_name ; ignore ( Unix . local... |
let add_roundtrip_conversion_tests state = List . iter ( Time . Zone . initialized_zones ( ) ) ~ f ( : add_roundtrip_conversion_test state ) ; ; |
let add_randomized_tests ( ) = let state = Random . State . make [ | 1 ; 2 ; 3 ; 4 ] | in add_random_string_round_trip_tests state ; add_random_localtime_tests state ; add_roundtrip_conversion_tests state ; ; |
let ( ) = add_randomized_tests ( ) ; ; ; |
let test = " zone " >::: ! zone_tests |
type zenv = { env : Deftypes . tentry Env . t ; ren : Zident . t Env . t ; size : int } |
let zempty = { env = Env . empty ; ren = Env . empty ; size = 0 } |
let zero_from_env env = let select key { t_sort = s } = match s with | Smem { m_kind = Some ( Zero ) } -> true | _ -> false in Env . partition select env |
let vars_of_env vars env = List . filter ( fun { vardec_name = x } -> Env . mem x env ) vars |
let make env2 env1 = let one key _ ( l , acc ) = match l with | [ ] -> assert false | ( key ' , _ ) :: l -> l , Env . add key key ' acc in let l1 = Env . bindings env1 in let _ , ren = Env . fold one env2 ( l1 , Env . empty ) in ren |
let compose r2_by_1 r2 = Env . map ( fun n2 -> try Env . find n2 r2_by_1 with Not_found -> assert false ) r2 |
let parallel { env = env1 ; ren = r1 ; size = s1 } { env = env2 ; ren = r2 ; size = s2 } = { env = Env . append env1 env2 ; ren = Env . append r1 r2 ; size = s1 + s2 } |
let sharp { env = env1 ; ren = r1 ; size = s1 } { env = env2 ; ren = r2 ; size = s2 } = if s1 >= s2 then let r2_by_1 = make env2 env1 in let r = Env . append r1 ( Env . append r2_by_1 ( compose r2_by_1 r2 ) ) in { env = env1 ; ren = r ; size = s1 } else let r1_by_2 = make env1 env2 in let r = Env . append r2 ( Env . ap... |
let rec equation ( { eq_desc = desc } as eq ) = match desc with | EQeq _ | EQpluseq _ | EQder _ | EQinit _ -> eq , zempty | EQmatch ( total , e , m_h_list ) -> let m_h_list , zenv = Zmisc . map_fold ( fun acc ( { m_body = b } as m_h ) -> { eq with eq_desc = EQmatch ( total , e , m_h_list ) } , zenv | EQreset ( eq_list ... |
let rec rename_expression ren ( { e_desc = desc } as e ) = match desc with | Econst _ | Econstr0 _ | Eglobal _ -> e | Elocal ( x ) -> { e with e_desc = Elocal ( apply x ren ) } | Elast ( x ) -> { e with e_desc = Elast ( apply x ren ) } | Etuple ( e_list ) -> { e with e_desc = Etuple ( List . map ( rename_expression ren... |
let local ( { l_eq = eq_list ; l_env = l_env } as l ) = let eq_list , { env = env ; ren = ren } = equation_list eq_list in let eq_list = rename_equation_list ren eq_list in { l with l_eq = eq_list ; l_env = Env . append env l_env } |
let expression ( { e_desc = desc } as e ) = let desc = match desc with | Elet ( l , e ) -> Elet ( local l , e ) | _ -> desc in { e with e_desc = desc } |
let implementation impl = match impl . desc with | Econstdecl ( n , is_static , e ) -> { impl with desc = Econstdecl ( n , is_static , expression e ) } | Efundecl ( n , ( { f_body = e } as body ) ) -> { impl with desc = Efundecl ( n , { body with f_body = expression e } ) } | _ -> impl |
let implementation_list impl_list = Zmisc . iter implementation impl_list |
type kind = | S | AS | A | C | AD | D | P |
type qualident = { qual : name ; id : name } |
type longname = | Name of name | Modname of qualident |
type ' a localized = { desc : ' a ; loc : Zlocation . location } |
type type_expression = type_expression_desc localized | Etypevar of name | Etypeconstr of longname * type_expression list | Etypetuple of type_expression list | Etypevec of type_expression * size | Etypefun of kind * string option * type_expression * type_expression | Sconst of int | Sname of longname | Sop of size_op ... |
type interface = interface_desc localized | Einter_open of name | Einter_typedecl of name * name list * type_decl | Einter_constdecl of name * type_expression | Eabstract_type | Eabbrev of type_expression | Evariant_type of constr_decl list | Erecord_type of ( name * type_expression ) list | Econstr0decl of name | Econ... |
let remove_trailing_null s = let n = String . length s in let i = ref ( n - 1 ) in while ! i >= 0 && s . [ ! i ] = ' \ 000 ' do i := ! i - 1 done ; String . sub s 0 ( ! i + 1 ) |
let serialize z = let n = if Z . ( lt z zero ) then Z . ( neg ( add ( add z z ) one ) ) else Z . ( add z z ) in n |> Z . to_bits |> remove_trailing_null |
let deserialize z = let n = Z . of_bits z in let z = Z . shift_right_trunc n 1 in if Z . ( n land one = zero ) then z else Z . neg z |
let leq a b = Z . compare a b <= 0 |
let geq a b = Z . compare a b >= 0 |
let lt a b = Z . compare a b < 0 |
let gt a b = Z . compare a b > 0 |
let ( < ) = lt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.