text stringlengths 12 786k |
|---|
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 . ... |
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... |
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... |
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_i... |
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 v... |
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... |
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 = R... |
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 = (... |
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_... |
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 ~ ... |
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 = ma... |
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 ( ... |
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 wi... |
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 ... |
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 | S... |
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 | Econstr0de... |
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 |
let ( > ) = gt |
let ( <= ) = leq |
let ( >= ) = geq |
let invert a n = try Some ( Z . invert a n ) with Division_by_zero -> None |
let pr ch x = output_string ch ( I . to_string x ) ; flush ch |
let pr2 ch ( x , y ) = Printf . fprintf ch " % s , % s " ( I . to_string x ) ( I . to_string y ) ; flush ch |
let pr3 ch ( x , y , z ) = Printf . fprintf ch " % s , % s , % s " ( I . to_string x ) ( I . to_string y ) ( I . to_string z ) ; flush ch |
let prfloat ch ( x , y : float * float ) = if x = y then Printf . fprintf ch " OK " else Printf . fprintf ch " WRONG ! ( expected % g , got % g ) " y x |
let prmarshal ch ( x , y : I . t * I . t ) = ( if I . equal x y then Printf . fprintf ch " OK " else Printf . fprintf ch " WRONG ! ( expected % a , got % a ) " pr y pr x ) ; flush ch |
let pow2 n = let rec doit acc n = if n <= 0 then acc else doit ( I . add acc acc ) ( n - 1 ) in doit I . one n |
let fact n = let rec doit acc n = if n <= 1 then acc else doit ( I . mul acc ( I . of_int n ) ) ( n - 1 ) in doit I . one n |
let pow a b = let rec doit b = if b <= 0 then I . one else let acc = doit ( b lsr 1 ) in if b land 1 = 1 then I . mul ( I . mul acc acc ) ( I . of_int a ) else I . mul acc acc in doit b |
let cvt_int x = try string_of_int ( I . to_int x ) with I . Overflow -> " ovf " |
let cvt_int32 x = try Int32 . to_string ( I . to_int32 x ) with I . Overflow -> " ovf " |
let cvt_int64 x = try Int64 . to_string ( I . to_int64 x ) with I . Overflow -> " ovf " |
let cvt_nativeint x = try Nativeint . to_string ( I . to_nativeint x ) with I . Overflow -> " ovf " |
let p2 = I . of_int 2 |
let p30 = pow2 30 |
let p62 = pow2 62 |
let p300 = pow2 300 |
let p120 = pow2 120 |
let p121 = pow2 121 |
let maxi = I . of_int max_int |
let mini = I . of_int min_int |
let maxi32 = I . of_int32 Int32 . max_int |
let mini32 = I . of_int32 Int32 . min_int |
let maxi64 = I . of_int64 Int64 . max_int |
let mini64 = I . of_int64 Int64 . min_int |
let maxni = I . of_nativeint Nativeint . max_int |
let minni = I . of_nativeint Nativeint . min_int |
let chk_bits x = Printf . printf " to_bits % a \ n " = pr x ; String . iter ( fun c -> Printf . printf " % 02x " ( Char . code c ) ) ( I . to_bits x ) ; Printf . printf " \ n " ; assert ( I . equal ( I . abs x ) ( I . of_bits ( I . to_bits x ) ) ) ... |
let chk_extract ( x , o , l ) = let expected = I . logand ( I . shift_right x o ) ( I . pred ( I . shift_left ( I . of_int 1 ) l ) ) and actual = I . extract x o l in Printf . printf " extract % a % d % d = % a " pr x o l pr actual ; if I . equal actual expected th... |
let chk_signed_extract ( x , o , l ) = let uns_res = I . extract x o l in let expected = if I . compare uns_res ( I . shift_left ( I . of_int 1 ) ( l - 1 ) ) >= 0 then I . sub uns_res ( I . shift_left ( I . of_int 1 ) l ) else uns_res in let actual = I . signed_extr... |
let chk_numbits_tz x = Printf . printf " numbits / trailing_zeros % a " pr x ; let n = I . numbits x and z = I . trailing_zeros x in if if I . equal x I . zero then n = 0 && z = max_int else n > 0 && z >= 0 && z < n && I . leq ( I . shift_left I . one ( n - 1 ) ) ( I .... |
let chk_testbit x = Printf . printf " testbit % a " pr x ; let n = I . numbits x in let ok = ref true in for i = 0 to n + 64 do let actual = I . testbit x i and expected = I . extract x i 1 in if not ( I . equal expected ( if actual then I . one else I . zero ) ) then begin Printf... |
let test_Z ( ) = Printf . printf " 0 \ n = % a \ n " pr I . zero ; Printf . printf " 1 \ n = % a \ n " pr I . one ; Printf . printf " - 1 \ n = % a \ n " pr I . minus_one ; Printf . printf " 42 \ n = % a \ n " pr ( I . of_int 42 ) ; Printf . print... |
let gcd2 a b = if Z . sign a = 0 then b else if Z . sign b = 0 then a else Z . gcd a b |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.