text stringlengths 12 786k |
|---|
let interval_num t time = if Time_ns . ( < ) time min_time then raise_s [ % message " Timing_wheel . interval_num got time too far in the past " ( time : Time_ns . t ) ] ; interval_num_unchecked t time ; ; |
let interval_num_start_unchecked t interval_num = Alarm_precision . interval_num_start t . config . alarm_precision ( interval_num |> Interval_num . to_int63 ) ; ; raise_s [ % message " Timing_wheel . interval_num_start got too small interval_num " ( interval_num : Interval_num . t ) (... |
let interval_num_start t interval_num = if Interval_num . ( < ) interval_num min_interval_num then raise_interval_num_start_got_too_small interval_num ; if Interval_num . ( > ) interval_num t . max_interval_num then raise_interval_num_start_got_too_large t interval_num ; interval_num_start_unchecke... |
let compute_max_allowed_alarm_time t = let max_allowed_key = Priority_queue . max_allowed_key t . priority_queue in if Interval_num . ( >= ) max_allowed_key t . max_interval_num then max_time else Time_ns . add ( interval_num_start_unchecked t max_allowed_key ) ( Time_ns . Span . ( - ) (... |
let now_interval_num t = Priority_queue . min_allowed_key t . priority_queue |
let max_allowed_alarm_interval_num t = interval_num t ( max_allowed_alarm_time t ) |
let interval_start t time = interval_num_start_unchecked t ( interval_num t time ) |
let invariant invariant_a t = Invariant . invariant [ % here ] t [ % sexp_of : _ t ] ( fun ( ) -> let check f = Invariant . check_field t f in Fields . iter ~ config ( : check Config . invariant ) ~ start : ( check ( fun start -> assert ( Time_ns . ( >= ) start min_tim... |
let advance_clock t ~ to_ ~ handle_fired = if Time_ns . ( > ) to_ ( now t ) then ( t . now <- to_ ; let key = interval_num_unchecked t to_ in t . now_interval_num_start <- interval_num_start_unchecked t key ; Priority_queue . increase_min_allowed_key t . priority_queue ~ key ~ handle_re... |
let create ~ config ~ start = if Time_ns . ( < ) start Time_ns . epoch then raise_s [ % message " Timing_wheel . create got start before the epoch " ( start : Time_ns . t ) ] ; let t = { config ; start ; max_interval_num = interval_num_internal ~ time : max_time ~ alarm_precis... |
let add_at_interval_num t ~ at value = Internal_elt . to_external ( Priority_queue . internal_add t . priority_queue ~ key : at ~ at ( : interval_num_start t at ) value ) ; ; raise_s [ % message " Timing_wheel cannot schedule alarm that far in the future " ( at : Time_ns . t ) ~ m... |
let ensure_can_schedule_alarm t ~ at = if Time_ns . ( > ) at t . max_allowed_alarm_time then raise_that_far_in_the_future t at ; if Time_ns . ( < ) at t . now_interval_num_start then raise_before_start_of_current_interval t at ; ; |
let add t ~ at value = ensure_can_schedule_alarm t ~ at ; Internal_elt . to_external ( Priority_queue . internal_add t . priority_queue ~ key ( : interval_num_unchecked t at ) ~ at value ) ; ; |
let remove t alarm = Priority_queue . remove t . priority_queue alarm |
let clear t = Priority_queue . clear t . priority_queue |
let mem t alarm = Priority_queue . mem t . priority_queue alarm |
let reschedule_gen t alarm ~ key ~ at = if not ( mem t alarm ) then failwith " Timing_wheel cannot reschedule alarm not in timing wheel " ; ensure_can_schedule_alarm t ~ at ; Priority_queue . change t . priority_queue alarm ~ key ~ at ; ; |
let reschedule t alarm ~ at = reschedule_gen t alarm ~ key ( : interval_num_unchecked t at ) ~ at ; ; |
let reschedule_at_interval_num t alarm ~ at = reschedule_gen t alarm ~ key : at ~ at ( : interval_num_start t at ) ; ; |
let pool t = Priority_queue . pool t . priority_queue |
let min_alarm_interval_num t = let elt = Priority_queue . min_elt_ t . priority_queue in if Internal_elt . is_null elt then None else Some ( Internal_elt . key ( pool t ) elt ) ; ; |
let min_alarm_interval_num_exn t = let elt = Priority_queue . min_elt_ t . priority_queue in if Internal_elt . is_null elt then raise_s [ % message " Timing_wheel . min_alarm_interval_num_exn of empty timing_wheel " ~ timing_wheel ( : t : _ t ) ] else Internal_elt . key ( pool t ) elt ;... |
let max_alarm_time_in_list t elt = let pool = pool t in Internal_elt . max_alarm_time pool elt ~ with_key ( : Internal_elt . key pool elt ) ; ; |
let max_alarm_time_in_min_interval t = let elt = Priority_queue . min_elt_ t . priority_queue in if Internal_elt . is_null elt then None else Some ( max_alarm_time_in_list t elt ) ; ; |
let max_alarm_time_in_min_interval_exn t = let elt = Priority_queue . min_elt_ t . priority_queue in if Internal_elt . is_null elt then raise_s [ % message " Timing_wheel . max_alarm_time_in_min_interval_exn of empty timing wheel " ~ timing_wheel ( : t : _ t ) ] ; max_alarm_time_in_list t e... |
let next_alarm_fires_at_internal t key = interval_num_start t ( Key . succ key ) ; ; |
let next_alarm_fires_at t = let elt = Priority_queue . min_elt_ t . priority_queue in if Internal_elt . is_null elt then None else ( let key = Internal_elt . key ( pool t ) elt in if Interval_num . equal key t . max_interval_num then None else Some ( next_alarm_fires_at_internal t key ) ) ; ... |
let next_alarm_fires_at_exn t = let elt = Priority_queue . min_elt_ t . priority_queue in if Internal_elt . is_null elt then raise_next_alarm_fires_at_exn_of_empty_timing_wheel t ; let key = Internal_elt . key ( pool t ) elt in if Interval_num . equal key t . max_interval_num then raise_next_alarm_... |
let fire_past_alarms t ~ handle_fired = Priority_queue . fire_past_alarms t . priority_queue ~ handle_fired ~ key ( : now_interval_num t ) ~ now : t . now ; ; |
module Private = struct module Num_key_bits = Num_key_bits let interval_num_internal = interval_num_internal let max_time = max_time end |
module type Interval_num = sig module Span : sig type t = private Int63 . t [ @@ deriving sexp_of ] include Comparable . S with type t := t val max : t -> t -> t val zero : t val one : t val max_value : t val of_int63 : Int63 . t -> t val to_int63 : t -> Int63 . t val of_int : int -> t val ... |
module type Alarm_precision = sig type t [ @@ deriving compare , sexp_of ] include Equal . S with type t := t val of_span : Time_ns . Span . t -> t [ @@ deprecated " [ since 2018 - 01 ] Use [ of_span_floor_pow2_ns ] " ] val of_span_floor_pow2_ns : Time_ns . Span . t -> t val t... |
module type Timing_wheel = sig module Alarm_precision : Alarm_precision type ' a t [ @@ deriving sexp_of ] type ' a timing_wheel = ' a t type ' a t_now = ' a t [ @@ deriving sexp_of ] module Interval_num : Interval_num module Alarm : sig type ' a t [ @@ deriving sexp_of ] val null : un... |
type ' a run = Asc of ' a list | Desc of ' a list | [ ] | [ _ ] -> true | x :: y :: r -> compare x y <= 0 && sorted_list compare ( y :: r ) |
type ' a cmp = ' a -> ' a -> int match l with [ ] -> ( ) | [ _ ] -> ( ) | y1 :: ys -> sorted_mem cmp y1 ys | [ ] | [ _ ] -> true | x :: y :: r -> compare x y >= 0 && sorted_list_rev compare ( y :: r ) match l with [ ] -> ( ) | [ _ ] -> ( ) | y... |
let rec next_asc_run_rev compare revrun last len = function | x :: xs -> if compare last x <= 0 then next_asc_run_rev compare ( last :: revrun ) x ( len + 1 ) xs else let xs = x :: xs in ( len , Desc ( last :: revrun ) , xs ) | xs -> ( len , Desc ( last :: revrun ) , xs ) |
let rec next_desc_run_rev compare ( revrun : ' a list ) last len = function | x :: xs -> if compare last x > 0 then next_desc_run_rev compare ( last :: revrun ) x ( len + 1 ) xs else let xs = x :: xs in ( len , Asc ( last :: revrun ) , xs ) | xs -> ( len , Asc ( last :: r... |
let next_run compare xs = match xs with | [ ] -> None | [ _ ] -> Some ( 1 , Asc xs , [ ] ) | x1 :: x2 :: xs -> if compare x1 x2 <= 0 then Some ( next_asc_run_rev compare [ x1 ] x2 2 xs ) else Some ( next_desc_run_rev compare [ x1 ] x2 2 xs ) |
let merge_asc_rev compare xs ys = let rec merge_asc_rev revacc xs ys = match ( xs , ys ) with | [ ] , zs | zs , [ ] -> List . rev_append zs revacc | x :: xs ' , y :: ys ' -> if compare x y <= 0 then merge_asc_rev ( x :: revacc ) xs ' ys else merge_asc_rev ( y :: revacc ) ... |
let merge_desc_rev compare = let rec merge_desc_rev revacc xs ys = match ( xs , ys ) with | [ ] , zs | zs , [ ] -> List . rev_append zs revacc | x :: xs ' , y :: ys ' -> if compare x y > 0 then merge_desc_rev ( x :: revacc ) xs ' ys else merge_desc_rev ( y :: revacc ) xs... |
let merge compare n1 n2 r1 r2 = let run = match ( r1 , r2 ) with | Asc r1 , Asc r2 -> Desc ( merge_asc_rev compare r1 r2 ) | Desc r1 , Desc r2 -> Asc ( merge_desc_rev compare r1 r2 ) | Asc r1 , Desc r2 -> if n1 < n2 then Asc ( merge_desc_rev compare ( List . rev r1 ) r2 ) else Des... |
type ' a stack = ( int * ' a run ) list |
let timsort compare l = let merge = merge compare in let next_run = next_run compare in let rec fetch_next_run remaining stack = match next_run remaining with | Some ( n , r , rem ) -> sort rem ( ( n , r ) :: stack ) | None -> stack and sort remaining stack = match stack with | ( ( n1 ,... |
type untyped_ocaml_value = UInt of int |
let rec string_of_untyped = function UInt i -> Printf . sprintf " UInt % i " i List . fold_left ( ^ ) " " ( List . map ( fun x -> Printf . sprintf " % s ; " ( string_of_untyped x ) ) ( Array . to_list arr ) ) List . fold_left ( ^ ) " " ( List . map ( fu... |
let rec find_tag_in_constdecls x isblock tblock tnonblock = function { pcd_name = { txt } ; pcd_args = Pcstr_tuple [ ] } :: _ when x = tnonblock && not isblock -> ( txt , [ ] ) |
let find_tag_in_variant_type x isblock = function | Ptype_variant constdecls -> Some ( find_tag_in_constdecls x isblock 0 0 constdecls ) | Ptype_abstract -> None | Ptype_record _ -> None | Ptype_open -> None |
let rec lookup_variant_type ( env : Tinyocaml . env ) vartypename x isblock = match env with EnvType ( _ , [ { ptype_name = { txt } ; ptype_kind } ] ) :: r when txt = vartypename -> begin match find_tag_in_variant_type x isblock ptype_kind with Some x -> x | None -> lookup_variant_ty... |
let rec read_untyped env debug_typ v typ = match v , typ . ptyp_desc with | UInt n , Ptyp_constr ( { txt = Longident . Lident " int " } , _ ) -> Int n | UInt n , Ptyp_constr ( { txt = Longident . Lident " bool " } , _ ) -> Bool ( n <> 0 ) | UInt n , Ptyp_constr ... |
let parse_type typ = typ |> Lexing . from_string |> Parse . core_type |
let of_ocaml_value env x typ = read_untyped env typ ( untyped_of_ocaml_value x ) ( parse_type typ ) |
type op = Add | Sub | Mul | Div |
type cmp = LT | EQ | GT | EQLT | EQGT | NEQ |
type control = Underline | Bold |
type forkind = UpTo | DownTo |
type pattern = PatAny EnvBinding of bool * binding list ref ModTypeSignature of t TypChar Unit |
let rec iter f x = f x ; match x with | ( Bool _ | Float _ | Var _ | Int _ | Int32 _ | Int64 _ | NativeInt _ | Char _ | String _ | OutChannel _ | InChannel _ | Unit | Nil | ModuleIdentifier _ | Raise ( _ , None ) | ExceptionDef _ | TypeDef _ | Open _ ) -> ( ) | Contr... |
let rec recurse f exp = match exp with | ( Bool _ | Float _ | Var _ | Int _ | Int32 _ | Int64 _ | NativeInt _ | Char _ | String _ | OutChannel _ | InChannel _ | Unit | Nil | ModuleIdentifier _ ) as x -> x | Op ( op , a , b ) -> Op ( op , f a , f b ) | And ( a , b )... |
let string_of_op = function Add -> " " + | Sub -> " " - | Mul -> " " * | Div -> " " / |
let string_of_cmp = function LT -> " " < | EQ -> " " = | GT -> " " > | EQLT -> " " <= | EQGT -> " " >= | NEQ -> " " <> |
let op_of_string = function " " + -> Add | " " - -> Sub | " " * -> Mul | " " / -> Div |
let cmp_of_string = function " " < -> LT | " " = -> EQ | " " > -> GT | " " <= -> EQLT | " " >= -> EQGT | " " <> -> NEQ |
let string_of_coretype t = let f = Format . str_formatter in Pprintast . core_type f t ; Format . flush_str_formatter ( ) |
let string_of_constructor_arg = function Pcstr_tuple coretypes -> string_of_coretype { ptyp_desc = Ptyp_tuple coretypes ; ptyp_loc = Location . none ; ptyp_attributes = [ ] ; ptyp_loc_stack = [ ] } |
let rec dots_between = function [ ] -> " " |
let string_of_longident l = dots_between ( Longident . flatten l ) |
let rec to_string = function Unit -> " Unit " Printf . sprintf " Op ( % s , % s , % s ) " ( to_string_op op ) ( to_string l ) ( to_string r ) Printf . sprintf " And ( % s , % s ) " ( to_string a ) ( to_string b ) Printf . sprintf " Or ( % s , % s ) " ... |
let rec bound_in_pattern = function PatAny -> [ ] |
let bound_in_bindings bindings = List . flatten ( List . map bound_in_pattern ( List . map fst bindings ) ) |
let begins_with n s = String . length n <= String . length s && n = String . sub s 0 ( String . length n ) |
let rec pattern_begins_with n = function PatVar s when begins_with n s -> true |
let binding_begins_with n ( p , e ) = pattern_begins_with n p |
let string_loc_begins_with n ( { txt } : string loc ) = begins_with n txt |
let bindings_beginning_with n env = option_map ( function envitem -> match envitem with EnvFunctor ( func_name , input_module_name , modtype , e , env ) -> if begins_with n func_name then Some envitem else None | EnvBinding ( recflag , bindings ) -> if List . for_all ( binding_begins_with n... |
let cut n s = String . sub s ( String . length n + 1 ) ( String . length s - String . length n - 1 ) |
let rec strip_pattern n = function PatVar s -> PatVar ( cut n s ) |
let strip_binding n ( p , e ) = ( strip_pattern n p , e ) |
let strip_constructor n c = match c with { pcd_name = ( { txt } as loc ) } -> { c with pcd_name = { loc with txt = cut n txt } } |
let strip_ptype_kind n = function Ptype_abstract -> Ptype_abstract |
let strip_typedecl n t = { t with ptype_name = { t . ptype_name with txt = cut n t . ptype_name . txt } ; ptype_kind = strip_ptype_kind n t . ptype_kind } |
let strip_bindings n = function EnvFunctor ( s , input_module_name , modtype , e , env ) -> EnvFunctor ( cut n s , input_module_name , modtype , e , env ) EnvBinding ( recflag , ref ( List . map ( strip_binding n ) ! bs ) ) EnvType ( recflag , List . map ( strip_typede... |
let open_module n ( env : env ) = List . map ( strip_bindings n ) ( bindings_beginning_with n env ) @ env |
let rec prefix_pattern prefix = function PatVar s -> PatVar ( prefix ^ " . " ^ s ) |
let prefix_binding prefix ( p , e ) = ( prefix_pattern prefix p , e ) |
let prefix_bindings p = function EnvBinding ( recflag , bs ) -> EnvBinding ( recflag , ref ( List . map ( prefix_binding p ) ! bs ) ) EnvFunctor ( p ^ n , input_module_name , modtype , e , env ) |
let alias_module current alias ( env : env ) = let replaced = List . map ( prefix_bindings alias ) ( List . map ( strip_bindings current ) ( bindings_beginning_with current env ) ) in replaced @ env |
let bindings_of_struct_item p = function | LetDef ( b , ld ) -> Some ( prefix_bindings p ( EnvBinding ( b , ref ld ) ) ) | _ -> None |
let open_struct_as_module name items ( env : env ) = let bindings = option_map ( bindings_of_struct_item name ) items in let top_level_binding = EnvBinding ( false , ref [ ( PatVar name , Struct ( false , items ) ) ] ) in top_level_binding :: bindings @ env |
let realops = ref false |
let rec tag_of_constructor_name_constdecls valnum blocknum str = function [ ] -> valnum , blocknum , None if args = [ ] then valnum , blocknum , Some valnum else valnum , blocknum , Some blocknum if args = [ ] then tag_of_constructor_name_constdecls ( valnum + 1 ) blocknum str t else t... |
let rec tag_of_constructor_name_envtype valnum blocknum str ( recflag , typedecls ) = match typedecls with [ ] -> None | { ptype_kind = Ptype_variant constdecls } :: more -> begin match tag_of_constructor_name_constdecls valnum blocknum str constdecls with _ , _ , Some tag -> Some tag | valn... |
let rec tag_of_constructor_name env str = match env with [ ] -> begin match str with " Invalid_argument " | " Failure " | " None " | " Some " | " Stream . Error " | " Stream . Failure " | " GenHashTable . EDead " | " GenHashTable . EFalse " | " GenHashTable . ET... |
let tag_of_constructor_name env str = try tag_of_constructor_name env str with e -> Printf . printf " TAG_OF_CONSTRUCTOR failed . . . . . " ; ! print_endline ( to_string_env env ) ; raise e |
let rec of_real_ocaml_expression_desc env = function Pexp_constant ( Pconst_integer ( s , None ) ) -> Int ( int_of_string s ) Cons ( of_real_ocaml env e , of_real_ocaml env e ' ) let str = string_of_longident txt in Constr ( tag_of_constructor_name env str , str , None ) let str = stri... |
let of_real_ocaml env x = let env ' , str = of_real_ocaml_structure env [ ] x in ( env ' , Struct ( false , str ) ) |
let _ = Ocamliprim . of_real_ocaml := of_real_ocaml |
let rec to_real_ocaml_expression_desc = function | Control ( _ , x ) -> to_real_ocaml_expression_desc x | Unit -> Pexp_construct ( { txt = Longident . Lident " ( ) " ; loc = Location . none } , None ) | Int i -> Pexp_constant ( Pconst_integer ( string_of_int i , None ) ) ... |
let to_real_ocaml = function | Struct ( _ , xs ) -> List . map ( function LetDef ( recflag , bindings ) -> { pstr_desc = Pstr_value ( ( if recflag then Recursive else Nonrecursive ) , List . map to_real_ocaml_binding bindings ) ; pstr_loc = Location . none } | x -> { pstr_... |
let extract_from_let = function LetDef ( _ , [ ( _ , e ) ] ) -> e |
let of_string s = match of_real_ocaml [ ] ( ast s ) with env , Struct ( _ , ( _ :: _ as l ) ) -> ( env , extract_from_let ( List . hd ( List . rev l ) ) ) | _ -> failwith " Tinyocaml . of_string " |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.