text stringlengths 0 601k |
|---|
let stat p = try Ok ( Unix . stat ( Fpath . to_string p ) ) with |
let lstat p = try Ok ( Unix . lstat ( Fpath . to_string p ) ) with |
let rec truncate p size = try Ok ( Unix . truncate ( Fpath . to_string p ) size ) with |
let err_malformed_pat s = strf " malformed named string pattern : % a " String . dump s |
type lexeme = Lit of string | Var of string |
type t = lexeme list |
let dom p = let add acc = function Lit _ -> acc | Var v -> String . Set . add v acc in List . fold_left add String . Set . empty p |
let equal p p ' = p = p ' |
let compare p p ' = Stdlib . compare p p ' |
type parse_state = S_lit | S_dollar | S_var |
let of_string s = let b = Buffer . create 255 in let flush b = let s = Buffer . contents b in ( Buffer . clear b ; s ) in let err ( ) = Error ( ` Msg ( err_malformed_pat s ) ) in let push_lit b acc = if Buffer . length b <> 0 then Lit ( flush b ) :: acc else acc in let max_i = String . length s - 1 in let rec loop acc ... |
let v s = match of_string s with Ok v -> v | Error ( ` Msg e ) -> invalid_arg e |
let to_string p = let b = Buffer . create 255 in let add = function | Lit l -> let max_i = String . length l - 1 in let rec loop start i = if i > max_i then Buffer . add_substring b l start ( i - start ) else if l . [ i ] <> ' ' $ then loop start ( i + 1 ) else begin Buffer . add_substring b l start ( i - start + 1 ) ;... |
let escape_dollar s = let len = String . length s in let max_idx = len - 1 in let rec escaped_len i l = if i > max_idx then l else match String . unsafe_get s i with | ' ' $ -> escaped_len ( i + 1 ) ( l + 2 ) | _ -> escaped_len ( i + 1 ) ( l + 1 ) in let escaped_len = escaped_len 0 0 in if escaped_len = len then s else... |
let rec pp ppf = function |
let dump ppf p = let rec dump ppf = function | [ ] -> ( ) | Lit l :: p -> Fmt . string ppf ( String . Ascii . escape_string ( escape_dollar l ) ) ; pp ppf p | Var v :: p -> Fmt . pf ppf " ( $% s ) " v ; pp ppf p in Fmt . pf ppf " " \% a " " \ dump p |
type defs = string String . map |
let subst ( ? undef = fun _ -> None ) defs p = let subst acc = function | Lit _ as l -> l :: acc | Var v as var -> match String . Map . find v defs with | Some lit -> ( Lit lit ) :: acc | None -> match undef v with | Some lit -> ( Lit lit ) :: acc | None -> var :: acc in List . ( rev ( fold_left subst [ ] p ) ) |
let format ( ? undef = fun _ -> " " ) defs p = let b = Buffer . create 255 in let add = function | Lit l -> Buffer . add_string b l | Var v -> match String . Map . find v defs with | Some s -> Buffer . add_string b s | None -> Buffer . add_string b ( undef v ) in List . iter add p ; Buffer . contents b |
let match_literal pos s lit = let l_len = String . length lit in let s_len = String . length s - pos in if l_len > s_len then None else try for i = 0 to l_len - 1 do if lit . [ i ] <> s . [ pos + i ] then raise Exit done ; Some ( pos + l_len ) with Exit -> None |
let match_pat ~ env pos s pat = let init , no_env = match env with | None -> Some String . Map . empty , true | Some m as init -> init , false in let rec loop pos = function | [ ] -> if pos = String . length s then init else None | Lit lit :: p -> begin match ( match_literal pos s lit ) with | None -> None | Some pos -... |
let matches p s = ( match_pat ~ env : None 0 s p ) <> None |
let query ( ? init = String . Map . empty ) p s = match_pat ~ env ( : Some init ) 0 s p |
type t = Continuation . t list |
let print ppf t = Format . pp_print_list ~ pp_sep : Format . pp_print_space Continuation . print ppf t |
let create conts = match conts with | [ ] -> Misc . fatal_error " No continuations provided to [ Bound_continuations . create ] " | _ :: _ -> let conts_set = Continuation . Set . of_list conts in if List . length conts <> Continuation . Set . cardinal conts_set then Misc . fatal_errorf " Continuations provided to [ Bou... |
let free_names t = List . fold_left ( fun free_names cont -> Name_occurrences . add_continuation free_names cont ~ has_traps : true ) Name_occurrences . empty t |
let apply_renaming t renaming = List . map ( Renaming . apply_continuation renaming ) t |
let all_ids_for_export t = List . fold_left Ids_for_export . add_continuation Ids_for_export . empty t |
let rename t = List . map Continuation . rename t |
let renaming t1 ~ guaranteed_fresh : t2 = try List . fold_left2 Renaming . add_continuation Renaming . empty t1 t2 with Invalid_argument _ -> assert ( List . compare_lengths t1 t2 <> 0 ) ; Misc . fatal_errorf " Continuation lists are of differing lengths :@ % a @ and @ % a " print t1 print t2 |
type t = { return_continuation : Continuation . t ; exn_continuation : Continuation . t ; params : Bound_parameters . t ; my_closure : Variable . t ; my_depth : Variable . t } { return_continuation ; exn_continuation ; params ; my_closure ; my_depth } = Format . fprintf ppf " [ @< hov 1 ( >\ [ @< hov 1 ( > return_conti... |
let create ~ return_continuation ~ exn_continuation ~ params ~ my_closure ~ my_depth = Bound_parameters . check_no_duplicates params ; ( if Flambda_features . check_invariants ( ) then let params_set = Bound_parameters . var_set params in if Variable . equal my_closure my_depth || Variable . Set . mem my_closure params... |
let return_continuation t = t . return_continuation |
let exn_continuation t = t . exn_continuation |
let params t = t . params |
let my_closure t = t . my_closure |
let my_depth t = t . my_depth |
let free_names { return_continuation ; exn_continuation ; params ; my_closure ; my_depth } = let free_names = Name_occurrences . add_continuation Name_occurrences . empty return_continuation ~ has_traps : true in let free_names = Name_occurrences . add_continuation free_names exn_continuation ~ has_traps : true in let ... |
let apply_renaming { return_continuation ; exn_continuation ; params ; my_closure ; my_depth } renaming = let return_continuation = Renaming . apply_continuation renaming return_continuation in let exn_continuation = Renaming . apply_continuation renaming exn_continuation in let params = Bound_parameters . apply_renami... |
let all_ids_for_export { return_continuation ; exn_continuation ; params ; my_closure ; my_depth } = let ids = Ids_for_export . add_continuation Ids_for_export . empty return_continuation in let ids = Ids_for_export . add_continuation ids exn_continuation in let ids = Ids_for_export . union ids ( Bound_parameters . all... |
let rename { return_continuation ; exn_continuation ; params ; my_closure ; my_depth } = { return_continuation = Continuation . rename return_continuation ; exn_continuation = Continuation . rename exn_continuation ; params = Bound_parameters . rename params ; my_closure = Variable . rename my_closure ; my_depth = Vari... |
let renaming { return_continuation = return_continuation1 ; exn_continuation = exn_continuation1 ; params = params1 ; my_closure = my_closure1 ; my_depth = my_depth1 } ~ guaranteed_fresh : { return_continuation = return_continuation2 ; exn_continuation = exn_continuation2 ; params = params2 ; my_closure = my_closure2 ;... |
type t = { param : Variable . t ; kind : Flambda_kind . With_subkind . t } type nonrec t = t let compare { param = param1 ; kind = kind1 } { param = param2 ; kind = kind2 } = let c = Variable . compare param1 param2 in if c <> 0 then c else Flambda_kind . With_subkind . compare kind1 kind2 let equal t1 t2 = compare t1 ... |
let create param kind = { param ; kind } |
let var t = t . param |
let name t = Name . var ( var t ) |
let simple t = Simple . var ( var t ) |
let kind t = t . kind |
let with_kind t kind = { t with kind } |
let rename t = { t with param = Variable . rename t . param } |
let equal_kinds t1 t2 = Flambda_kind . With_subkind . equal t1 . kind t2 . kind |
let free_names ( { param = _ ; kind = _ } as t ) = Name_occurrences . singleton_variable ( var t ) Name_mode . normal |
let apply_renaming ( { param = _ ; kind } as t ) perm = Name . pattern_match ( Renaming . apply_name perm ( name t ) ) ~ var ( : fun var -> create var kind ) ~ symbol ( : fun _ -> Misc . fatal_errorf " Illegal name permutation on [ Bound_parameter ] : % a " Renaming . print perm ) |
let all_ids_for_export { param ; kind = _ } = Ids_for_export . add_variable Ids_for_export . empty param |
type t = BP . t list |
let print ppf t = Format . fprintf ppf " [ @< hov 0 >% a ] " @ ( Format . pp_print_list ~ pp_sep : Format . pp_print_space BP . print ) t |
let create params = ( if Flambda_features . check_invariants ( ) then let params_set = BP . Set . of_list params in if List . length params <> BP . Set . cardinal params_set then Misc . fatal_errorf " Names provided to [ Bound_parameters . create ] must be disjoint :@ % a " print params ) ; params |
let cons param t = create ( param :: t ) |
let append t1 t2 = create ( t1 @ t2 ) |
let to_list t = t |
let is_empty t = match t with [ ] -> true | _ :: _ -> false |
let same_number t1 t2 = List . compare_lengths t1 t2 = 0 |
let cardinal t = List . length t |
let vars t = List . map BP . var t |
let simples t = List . map BP . simple t |
let to_set t = Bound_parameter . Set . of_list t |
let var_set t = Variable . Set . of_list ( vars t ) |
let rename t = List . map ( fun t -> BP . rename t ) t |
let arity t = List . map ( fun t -> Flambda_kind . With_subkind . kind ( BP . kind t ) ) t |> Flambda_arity . create |
let arity_with_subkinds t = List . map ( fun t -> BP . kind t ) t |> Flambda_arity . With_subkinds . create |
let free_names t = List . fold_left ( fun result param -> Name_occurrences . union result ( BP . free_names param ) ) Name_occurrences . empty t |
let apply_renaming t perm = List . map ( fun param -> BP . apply_renaming param perm ) t |
let all_ids_for_export t = Ids_for_export . union_list ( List . map BP . all_ids_for_export t ) |
let check_no_duplicates t = if not ( Flambda_features . check_invariants ( ) ) then ( ) else let t_set = BP . Set . of_list t in if BP . Set . cardinal t_set <> List . length t then Misc . fatal_errorf " Duplicates in bound parameter list :@ % a " print t |
let renaming t1 ~ guaranteed_fresh : t2 = try List . fold_left2 ( fun renaming param1 param2 -> Renaming . add_variable renaming ( BP . var param1 ) ( BP . var param2 ) ) Renaming . empty t1 t2 with Invalid_argument _ -> assert ( List . compare_lengths t1 t2 <> 0 ) ; Misc . fatal_errorf " Parameter lists are of differi... |
let filter f t = List . filter f t |
let exists f t = List . exists f t |
type t = | Singleton of Bound_var . t | Set_of_closures of Bound_var . t list | Static of Bound_static . t |
let [ @ ocamlformat " disable " ] print ppf t = match t with | Singleton bound_var -> Bound_var . print ppf bound_var | Set_of_closures bound_vars -> Format . fprintf ppf " [ @< hov 1 ( >% a ) ] " @ ( Format . pp_print_list ~ pp_sep : Format . pp_print_space Bound_var . print ) bound_vars | Static bound_static -> Forma... |
let free_names t = match t with | Singleton bound_var -> Name_occurrences . singleton_variable ( Bound_var . var bound_var ) Name_mode . normal | Set_of_closures bound_vars -> List . fold_left ( fun free_names bound_var -> Name_occurrences . add_variable free_names ( Bound_var . var bound_var ) Name_mode . normal ) Nam... |
let rec map_sharing f l0 = match l0 with | a :: l -> let a ' = f a in let l ' = map_sharing f l in if a ' == a && l ' == l then l0 else a ' :: l ' | [ ] -> [ ] |
let apply_renaming t renaming = match t with | Singleton bound_var -> let bound_var ' = Bound_var . apply_renaming bound_var renaming in if bound_var == bound_var ' then t else Singleton bound_var ' | Set_of_closures bound_vars -> let bound_vars ' = map_sharing ( fun bound_var -> Bound_var . apply_renaming bound_var re... |
let all_ids_for_export t = match t with | Singleton bound_var -> Bound_var . all_ids_for_export bound_var | Set_of_closures bound_vars -> List . fold_left ( fun ids bound_var -> Ids_for_export . union ids ( Bound_var . all_ids_for_export bound_var ) ) Ids_for_export . empty bound_vars | Static bound_static -> Bound_sta... |
let rename t = match t with | Singleton bound_var -> Singleton ( Bound_var . rename bound_var ) | Set_of_closures bound_vars -> let bound_vars = List . map ( fun bound_var -> Bound_var . rename bound_var ) bound_vars in Set_of_closures bound_vars | Static _ -> t |
let renaming t1 ~ guaranteed_fresh : t2 = match t1 , t2 with | Singleton bound_var1 , Singleton bound_var2 -> Renaming . add_fresh_variable Renaming . empty ( Bound_var . var bound_var1 ) ~ guaranteed_fresh ( : Bound_var . var bound_var2 ) | Set_of_closures bound_vars1 , Set_of_closures bound_vars2 -> if List . compare... |
let singleton var = Singleton var |
let set_of_closures bound_vars = let name_mode = List . fold_left ( fun name_mode bound_var -> let next_name_mode = Bound_var . name_mode bound_var in match name_mode with | None -> Some next_name_mode | Some name_mode -> if not ( Name_mode . equal name_mode next_name_mode ) then Misc . fatal_errorf " Mismatching name ... |
let static bound_static = Static bound_static |
let name_mode t = match t with | Singleton bound_var | Set_of_closures ( bound_var :: _ ) -> Bound_var . name_mode bound_var | Set_of_closures [ ] -> assert false | Static _ -> Name_mode . normal |
let with_name_mode t name_mode = match t with | Singleton bound_var -> Singleton ( Bound_var . with_name_mode bound_var name_mode ) | Set_of_closures bound_vars -> Set_of_closures ( List . map ( fun bound_var -> Bound_var . with_name_mode bound_var name_mode ) bound_vars ) | Static _ -> t |
let must_be_singleton t = match t with | Singleton bound_var -> bound_var | Set_of_closures _ | Static _ -> Misc . fatal_errorf " Bound pattern is not [ Singleton ] :@ % a " print t |
let must_be_singleton_opt t = match t with | Singleton bound_var -> Some bound_var | Set_of_closures _ | Static _ -> None |
let must_be_set_of_closures t = match t with | Set_of_closures bound_vars -> bound_vars | Singleton _ | Static _ -> Misc . fatal_errorf " Bound pattern is not [ Set_of_closures ] :@ % a " print t |
let must_be_static t = match t with | Static bound_static -> bound_static | Singleton _ | Set_of_closures _ -> Misc . fatal_errorf " Bound pattern is not [ Static ] :@ % a " print t |
let may_be_static t = match t with | Static bound_static -> Some bound_static | Singleton _ | Set_of_closures _ -> None |
let exists_all_bound_vars t ~ f = match t with | Singleton var -> f var | Set_of_closures bound_vars -> ListLabels . exists bound_vars ~ f | Static _ -> false |
let fold_all_bound_vars t ~ init ~ f = match t with | Singleton bound_var -> f init bound_var | Set_of_closures bound_vars -> ListLabels . fold_left bound_vars ~ init ~ f | Static _ -> init |
let fold_all_bound_names t ~ init ~ var ~ symbol ~ code_id = match t with | Singleton bound_var -> var init bound_var | Set_of_closures bound_vars -> ListLabels . fold_left bound_vars ~ init ~ f : var | Static bound_static -> Code_id . Set . fold ( fun cid acc -> code_id acc cid ) ( Bound_static . code_being_defined bo... |
module Pattern = struct type t = | Code of Code_id . t | Set_of_closures of Symbol . t Function_slot . Lmap . t | Block_like of Symbol . t let code code_id = Code code_id let set_of_closures closure_symbols = Set_of_closures closure_symbols let block_like symbol = Block_like symbol let [ @ ocamlformat " disable " ] pri... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.