text stringlengths 12 786k |
|---|
module Assert_subtype ( X : DSL ) : Integer_dependent with type bar_style := X . Bar_style . t = X |
module type S = sig include DSL with type integer := int module Integer_dependent : sig module type S = Integer_dependent with type ' a t := ' a t and type color := color and type duration := duration and type ' a printer := ' a printer and type bar_style := Bar_style . t module Make ( Integer : I... |
module type Line = sig module type S = S type ' a t module Make ( _ : Platform . S ) : sig include S with type ' a t := ' a t and type color := Terminal . Color . t and type duration := Duration . t and type ' a printer := ' a Printer . t val to_primitive : Config . t -> ' a t ->... |
type ' a pp = Format . formatter -> ' a -> unit |
type ' a t = | Noop | Theta of { pp : Line_buffer . t -> event -> unit ; width : int } | Alpha of { pp : Line_buffer . t -> event -> ' a -> unit ; initial : [ ` Theta of Line_buffer . t -> unit | ` Val of ' a ] ; width : int } | Alpha_unsized of { pp : width ( : ... |
let noop ( ) = Noop |
let array ts = Group ts |
let of_pp ~ width ~ initial pp = let pp buf x = Line_buffer . with_ppf buf ( fun ppf -> pp ppf x ) in Alpha { pp ; width ; initial = ` Val initial } |
let alpha ~ width ~ initial pp = Alpha { pp ; initial ; width } |
let alpha_unsized ~ initial pp = Alpha_unsized { pp ; initial } |
let theta ~ width pp = Theta { pp ; width } |
let conditional pred s = Cond { if_ = pred ; then_ = s } |
let contramap ~ f x = Contramap ( x , f ) |
let on_finalise final inner = On_finalise { final ; inner } |
let ticker interval : unit -> bool = let ticker = ref 0 in fun ( ) -> ticker := ( ! ticker + 1 ) mod interval ; ! ticker = 0 |
let stateful f = Staged f |
let periodic interval t = match interval with | n when n <= 0 -> Format . kasprintf invalid_arg " Non - positive interval : % d " n | 1 -> t | _ -> stateful ( fun ( ) -> let should_update = ticker interval in conditional ( fun _ -> should_update ( ) ) t ) |
let box_dynamic ( ? pad = ` none ) width contents = Box { contents ; width = Dynamic width ; pad } |
let box_fixed ( ? pad = ` none ) width contents = Box { contents ; width = Static width ; pad } |
let pair ( ? sep = noop ( ) ) a b = Pair { left = a ; sep ; right = b } |
let accumulator combine zero s = stateful ( fun ( ) -> let state = ref zero in contramap s ~ f ( : fun a -> state := combine ! state a ; ! state ) ) |
module Compiled = struct type ' a t = | Noop | Alpha of { pp : Line_buffer . t -> event -> ' a -> int ; mutable latest : Line_buffer . t -> int } | Theta of { pp : Line_buffer . t -> event -> int } | Contramap : ' a t * ( ' b -> ' a ) -> ' b t | On_finalise of { fin... |
module Compiler_state : sig type ' a t module Syntax : sig val return : ' a -> ' a t val ( let + ) : ' a t -> ( ' a -> ' b ) -> ' b t val ( let * ) : ' a t -> ( ' a -> ' b t ) -> ' b t end val consume_space : int Sta_dyn . t -> unit t val measure_consumed : ' a... |
let compile top = let rec inner : type a . a t -> a Compiled . t Compiler_state . t = let open Compiler_state . Syntax in function | Noop -> return Compiled . Noop | Staged s -> inner ( s ( ) ) | Theta { pp ; width } -> let pp ppf event = pp ppf event ; width in let + ( ) = Co... |
let apply_padding dir width = match dir with | ` right -> Staged . inj ( fun inner buf -> let inner_width = inner buf in let outer_width = Sta_dyn . get width in for _ = inner_width + 1 to outer_width do Line_buffer . add_char buf ' ' done ; outer_width ) | ` left intermediate_buf -> Sta... |
let report compiled = let rec aux : type a . [ ` report | ` finish ] -> a Compiled . t -> ( Line_buffer . t -> a -> int ) Staged . t = fun typ -> function | Noop -> Staged . inj ( fun _ _ -> 0 ) | Theta { pp } -> Staged . inj ( fun buf ( _ : a ) -> pp buf ` re... |
let update top = let rec aux : type a . a Compiled . t -> ( bool -> [ ` rerender | ` tick | ` finish ] -> Line_buffer . t -> int ) Staged . t = function | Noop -> Staged . inj ( fun _ _ _ -> 0 ) | Theta { pp } -> Staged . inj ( fun _ event buf -> pp buf ( event ... |
let finalise t = Staged . map ( update t ) ~ f ( : fun f -> f ~ unconditional : true ` finish ) |
let tick t = Staged . map ( update t ) ~ f ( : fun f -> f ~ unconditional : true ` tick ) |
let update t = Staged . map ( update t ) ~ f ( : fun f ~ unconditional buf -> f ~ unconditional ` rerender buf ) |
let report t = report ` report t |
module type Counter = sig type t val counter : unit -> t val count : t -> Mtime . span end |
module Types = struct type event = [ ` report | ` rerender | ` tick | ` finish ] end |
module type S = sig type ' a t include module type of Types type theta := Line_buffer . t -> event -> unit type ' a alpha := Line_buffer . t -> event -> ' a -> unit val noop : unit -> _ t val theta : width : int -> theta -> _ t val alpha : width : int -> initial [ : ` Theta of Line_buf... |
module type Line_primitives = sig module type S = S include S module Compiled : sig type ' a t val pp_dump : Format . formatter -> ' a t -> unit end val compile : ' a t -> ' a Compiled . t val update : ' a Compiled . t -> ( unconditional : bool -> Line_buffer . t -> int ) Staged . t... |
type class_intervals = { mutable ci_fixed : Interval . t list ; mutable ci_active : Interval . t list ; mutable ci_inactive : Interval . t list ; } |
let active = Array . init Proc . num_register_classes ( fun _ -> { ci_fixed = [ ] ; ci_active = [ ] ; ci_inactive = [ ] } ) |
let rec insert_interval_sorted i = function [ ] -> [ i ] | j :: _ as il when j . iend <= i . iend -> i :: il | j :: il -> j :: insert_interval_sorted i il |
let rec release_expired_fixed pos = function i :: il when i . iend >= pos -> Interval . remove_expired_ranges i pos ; i :: release_expired_fixed pos il | _ -> [ ] |
let rec release_expired_active ci pos = function i :: il when i . iend >= pos -> Interval . remove_expired_ranges i pos ; if Interval . is_live i pos then i :: release_expired_active ci pos il else begin ci . ci_inactive <- insert_interval_sorted i ci . ci_inactive ; release_expired_active ci pos il... |
let rec release_expired_inactive ci pos = function i :: il when i . iend >= pos -> Interval . remove_expired_ranges i pos ; if not ( Interval . is_live i pos ) then i :: release_expired_inactive ci pos il else begin ci . ci_active <- insert_interval_sorted i ci . ci_active ; release_expired_inac... |
let allocate_stack_slot num_stack_slots i = let cl = Proc . register_class i . reg in let ss = num_stack_slots . ( cl ) in num_stack_slots . ( cl ) <- succ ss ; i . reg . loc <- Stack ( Local ss ) ; i . reg . spill <- true |
let allocate_free_register num_stack_slots i = begin match i . reg . loc , i . reg . spill with Unknown , true -> allocate_stack_slot num_stack_slots i | Unknown , _ -> let cl = Proc . register_class i . reg in begin match Proc . num_available_registers . ( cl ) with 0 -> raise Not_fou... |
let allocate_blocked_register num_stack_slots i = let cl = Proc . register_class i . reg in let ci = active . ( cl ) in match ci . ci_active with | ilast :: il when ilast . iend > i . iend && let chk r = r . reg . loc = ilast . reg . loc && Interval . overlap r i in not ( List . ... |
let walk_interval num_stack_slots i = let pos = i . ibegin land ( lnot 0x01 ) in Array . iter ( fun ci -> ci . ci_fixed <- release_expired_fixed pos ci . ci_fixed ; ci . ci_active <- release_expired_active ci pos ci . ci_active ; ci . ci_inactive <- release_expired_inactive ci pos ci . ... |
let allocate_registers ( ) = for cl = 0 to Proc . num_register_classes - 1 do active . ( cl ) <- { ci_fixed = [ ] ; ci_active = [ ] ; ci_inactive = [ ] } ; done ; let num_stack_slots = Array . make Proc . num_register_classes 0 in List . iter ( fun i -> let ci = ... |
type ' a t = ' a list = [ ] | ( ) :: of ' a * ' a list |
let rec length_aux len = function [ ] -> len | _ :: l -> length_aux ( len + 1 ) l |
let length l = length_aux 0 l |
let cons a l = a :: l |
let hd = function [ ] -> failwith " hd " | a :: _ -> a |
let tl = function [ ] -> failwith " tl " | _ :: l -> l |
let nth l n = if n < 0 then invalid_arg " List . nth " else let rec nth_aux l n = match l with | [ ] -> failwith " nth " | a :: l -> if n = 0 then a else nth_aux l ( n - 1 ) in nth_aux l n |
let nth_opt l n = if n < 0 then invalid_arg " List . nth " else let rec nth_aux l n = match l with | [ ] -> None | a :: l -> if n = 0 then Some a else nth_aux l ( n - 1 ) in nth_aux l n |
let rec rev_append l1 l2 = match l1 with [ ] -> l2 | a :: l -> rev_append l ( a :: l2 ) |
let rev l = rev_append l [ ] |
let rec init_tailrec_aux acc i n f = if i >= n then acc else init_tailrec_aux ( f i :: acc ) ( i + 1 ) n f |
let rec init_aux i n f = if i >= n then [ ] else let r = f i in r :: init_aux ( i + 1 ) n f |
let rev_init_threshold = match Sys . backend_type with | Sys . Native | Sys . Bytecode -> 10_000 | Sys . Other _ -> 50 |
let init len f = if len < 0 then invalid_arg " List . init " else if len > rev_init_threshold then rev ( init_tailrec_aux [ ] 0 len f ) else init_aux 0 len f |
let rec flatten = function [ ] -> [ ] | l :: r -> l @ flatten r |
let rec map f = function [ ] -> [ ] | a :: l -> let r = f a in r :: map f l |
let rec mapi i f = function [ ] -> [ ] | a :: l -> let r = f i a in r :: mapi ( i + 1 ) f l |
let mapi f l = mapi 0 f l |
let rev_map f l = let rec rmap_f accu = function | [ ] -> accu | a :: l -> rmap_f ( f a :: accu ) l in rmap_f [ ] l |
let rec iter f = function [ ] -> ( ) | a :: l -> f a ; iter f l |
let rec iteri i f = function [ ] -> ( ) | a :: l -> f i a ; iteri ( i + 1 ) f l |
let iteri f l = iteri 0 f l |
let rec fold_left f accu l = match l with [ ] -> accu | a :: l -> fold_left f ( f accu a ) l |
let rec fold_right f l accu = match l with [ ] -> accu | a :: l -> f a ( fold_right f l accu ) |
let rec map2 f l1 l2 = match ( l1 , l2 ) with ( [ ] , [ ] ) -> [ ] | ( a1 :: l1 , a2 :: l2 ) -> let r = f a1 a2 in r :: map2 f l1 l2 | ( _ , _ ) -> invalid_arg " List . map2 " |
let rev_map2 f l1 l2 = let rec rmap2_f accu l1 l2 = match ( l1 , l2 ) with | ( [ ] , [ ] ) -> accu | ( a1 :: l1 , a2 :: l2 ) -> rmap2_f ( f a1 a2 :: accu ) l1 l2 | ( _ , _ ) -> invalid_arg " List . rev_map2 " in rmap2_f [ ] l1 l2 |
let rec iter2 f l1 l2 = match ( l1 , l2 ) with ( [ ] , [ ] ) -> ( ) | ( a1 :: l1 , a2 :: l2 ) -> f a1 a2 ; iter2 f l1 l2 | ( _ , _ ) -> invalid_arg " List . iter2 " |
let rec fold_left2 f accu l1 l2 = match ( l1 , l2 ) with ( [ ] , [ ] ) -> accu | ( a1 :: l1 , a2 :: l2 ) -> fold_left2 f ( f accu a1 a2 ) l1 l2 | ( _ , _ ) -> invalid_arg " List . fold_left2 " |
let rec fold_right2 f l1 l2 accu = match ( l1 , l2 ) with ( [ ] , [ ] ) -> accu | ( a1 :: l1 , a2 :: l2 ) -> f a1 a2 ( fold_right2 f l1 l2 accu ) | ( _ , _ ) -> invalid_arg " List . fold_right2 " |
let rec for_all p = function [ ] -> true | a :: l -> p a && for_all p l |
let rec exists p = function [ ] -> false | a :: l -> p a || exists p l |
let rec for_all2 p l1 l2 = match ( l1 , l2 ) with ( [ ] , [ ] ) -> true | ( a1 :: l1 , a2 :: l2 ) -> p a1 a2 && for_all2 p l1 l2 | ( _ , _ ) -> invalid_arg " List . for_all2 " |
let rec exists2 p l1 l2 = match ( l1 , l2 ) with ( [ ] , [ ] ) -> false | ( a1 :: l1 , a2 :: l2 ) -> p a1 a2 || exists2 p l1 l2 | ( _ , _ ) -> invalid_arg " List . exists2 " |
let rec mem x = function [ ] -> false | a :: l -> compare a x = 0 || mem x l |
let rec memq x = function [ ] -> false | a :: l -> a == x || memq x l |
let rec assoc x = function [ ] -> raise Not_found | ( a , b ) :: l -> if compare a x = 0 then b else assoc x l |
let rec assoc_opt x = function [ ] -> None | ( a , b ) :: l -> if compare a x = 0 then Some b else assoc_opt x l |
let rec assq x = function [ ] -> raise Not_found | ( a , b ) :: l -> if a == x then b else assq x l |
let rec assq_opt x = function [ ] -> None | ( a , b ) :: l -> if a == x then Some b else assq_opt x l |
let rec mem_assoc x = function | [ ] -> false | ( a , _ ) :: l -> compare a x = 0 || mem_assoc x l |
let rec mem_assq x = function | [ ] -> false | ( a , _ ) :: l -> a == x || mem_assq x l |
let rec remove_assoc x = function | [ ] -> [ ] | ( a , _ as pair ) :: l -> if compare a x = 0 then l else pair :: remove_assoc x l |
let rec remove_assq x = function | [ ] -> [ ] | ( a , _ as pair ) :: l -> if a == x then l else pair :: remove_assq x l |
let rec find p = function | [ ] -> raise Not_found | x :: l -> if p x then x else find p l |
let rec find_opt p = function | [ ] -> None | x :: l -> if p x then Some x else find_opt p l |
let rec find_map f = function | [ ] -> None | x :: l -> begin match f x with | Some _ as result -> result | None -> find_map f l end |
let find_all p = let rec find accu = function | [ ] -> rev accu | x :: l -> if p x then find ( x :: accu ) l else find accu l in find [ ] |
let filteri p l = let rec aux i acc = function | [ ] -> rev acc | x :: l -> aux ( i + 1 ) ( if p i x then x :: acc else acc ) l in aux 0 [ ] l |
let filter_map f = let rec aux accu = function | [ ] -> rev accu | x :: l -> match f x with | None -> aux accu l | Some v -> aux ( v :: accu ) l in aux [ ] |
let concat_map f l = let rec aux f acc = function | [ ] -> rev acc | x :: l -> let xs = f x in aux f ( rev_append xs acc ) l in aux f [ ] l |
let fold_left_map f accu l = let rec aux accu l_accu = function | [ ] -> accu , rev l_accu | x :: l -> let accu , x = f accu x in aux accu ( x :: l_accu ) l in aux accu [ ] l |
let partition p l = let rec part yes no = function | [ ] -> ( rev yes , rev no ) | x :: l -> if p x then part ( x :: yes ) no l else part yes ( x :: no ) l in part [ ] [ ] l |
let partition_map p l = let rec part left right = function | [ ] -> ( rev left , rev right ) | x :: l -> begin match p x with | Either . Left v -> part ( v :: left ) right l | Either . Right v -> part left ( v :: right ) l end in part [ ] [ ] l |
let rec split = function [ ] -> ( [ ] , [ ] ) | ( x , y ) :: l -> let ( rx , ry ) = split l in ( x :: rx , y :: ry ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.