text stringlengths 12 786k |
|---|
let print_out_exception ppf exn outv = match exn with Sys . Break -> fprintf ppf " Interrupted . . " @ | Out_of_memory -> fprintf ppf " Out of memory during evaluation . . " @ | Stack_overflow -> fprintf ppf " Stack overflow during evaluation ( looping recursion ) . . " ?@ | _ ... |
let rec print_items ppf = function [ ] -> ( ) | ( Osig_typext ( ext , Oext_first ) , None ) :: items -> let rec gather_extensions acc items = match items with ( Osig_typext ( ext , Oext_next ) , None ) :: items -> gather_extensions ( ( ext . oext_name , ext . oext_args ... |
let print_out_phrase ppf = function Ophr_eval ( outv , ty ) -> fprintf ppf " [ @- : % a @ =@ % a ] . " @@ ! out_type ty ! out_value outv | Ophr_signature [ ] -> ( ) | Ophr_signature items -> fprintf ppf " [ @< v >% a ] . " @@ print_items items | Ophr_exception ( ex... |
let out_phrase = ref print_out_phrase |
module type XOR = sig type t val xor : t -> t -> t [ @@ logic ] end |
module type CIPHER = sig type elt type t val cipher : t -> t -> t end |
module Make ( X : XOR ) : CIPHER with type elt = X . t = struct type elt = X . t type t = elt list let rec cipher key msg = match ( key , msg ) with | [ ] , [ ] -> [ ] | x :: xs , y :: ys -> X . xor x y :: cipher xs ys | _ -> assert false let correct msg key = let r = ... |
module XBool : XOR with type t = bool = struct type t = bool let [ @ logic ] xor t1 t2 = ( ( not t1 ) && t2 ) || ( t1 && not t2 ) end |
module XBool2 : XOR with type t = bool = struct type t = bool let [ @ logic ] xor t1 t2 = if t1 then not t2 else t2 end |
module XBit : XOR = struct type t = Zero | One let [ @ logic ] xor t1 t2 = match ( t1 , t2 ) with Zero , Zero | One , One -> Zero | _ -> One end |
module CBool = Make ( XBool ) |
module CBool2 = Make ( XBool2 ) |
module CBit = Make ( XBit ) |
module Make ( A : sig val rewrite : Path . t -> Outcometree . out_ident end ) = struct |
let unique_names = ref Ident . empty |
let ident_name id = try Ident . find_same id ! unique_names with Not_found -> Ident . name id |
let add_unique id = try ignore ( Ident . find_same id ! unique_names ) with Not_found -> unique_names := Ident . add id ( Ident . unique_toplevel_name id ) ! unique_names |
let ident ppf id = pp_print_string ppf ( ident_name id ) |
let ident_pervasive = Ident . create_persistent " Pervasives " |
let rec tree_of_path = function | Pident id -> Oide_ident ( ident_name id ) | Pdot ( Pident id , s , _pos ) when Ident . same id ident_pervasive -> Oide_ident s | Pdot ( p , s , _pos ) -> Oide_dot ( tree_of_path p , s ) | Papply ( p1 , p2 ) -> Oide_apply ( tree_of_path p1 ... |
let tree_of_path p = A . rewrite p |
let rec path ppf = function | Pident id -> ident ppf id | Pdot ( Pident id , s , _pos ) when Ident . same id ident_pervasive -> pp_print_string ppf s | Pdot ( p , s , _pos ) -> path ppf p ; pp_print_char ppf ' . ' ; pp_print_string ppf s | Papply ( p1 , p2 ) -> fprintf ppf "... |
let rec string_of_out_ident = function | Oide_ident s -> s | Oide_dot ( id , s ) -> String . concat " . " [ string_of_out_ident id ; s ] | Oide_apply ( id1 , id2 ) -> String . concat " " [ string_of_out_ident id1 ; " ( " ; string_of_out_ident id2 ; " ) " ] |
let tree_of_rec = function | Trec_not -> Orec_not | Trec_first -> Orec_first | Trec_next -> Orec_next |
let raw_list pr ppf = function [ ] -> fprintf ppf " [ ] " | a :: l -> fprintf ppf " [ @< 1 [ >% a % t ] ] " @ pr a ( fun ppf -> List . iter ( fun x -> fprintf ppf " ; , @% a " pr x ) l ) |
let kind_vars = ref [ ] |
let kind_count = ref 0 |
let rec safe_kind_repr v = function Fvar { contents = Some k } -> if List . memq k v then " Fvar loop " else safe_kind_repr ( k :: v ) k | Fvar r -> let vid = try List . assq r ! kind_vars with Not_found -> let c = incr kind_count ; ! kind_count in kind_vars := ( r , c ) :: ! kind_... |
let rec safe_commu_repr v = function Cok -> " Cok " | Cunknown -> " Cunknown " | Clink r -> if List . memq r v then " Clink loop " else safe_commu_repr ( r :: v ) ! r |
let rec safe_repr v = function { desc = Tlink t } when not ( List . memq t v ) -> safe_repr ( t :: v ) t | t -> t |
let rec list_of_memo = function Mnil -> [ ] | Mcons ( _priv , p , _t1 , _t2 , rem ) -> p :: list_of_memo rem | Mlink rem -> list_of_memo ! rem |
let print_name ppf = function None -> fprintf ppf " None " | Some name -> fprintf ppf " " \% s " " \ name |
let string_of_label = function Nolabel -> " " | Labelled s -> s | Optional s -> " " ?^ s |
type param_subst = Id | Nth of int | Map of int list |
let is_nth = function Nth _ -> true | _ -> false |
let compose l1 = function | Id -> Map l1 | Map l2 -> Map ( List . map ( List . nth l1 ) l2 ) | Nth n -> Nth ( List . nth l1 n ) |
let apply_subst s1 tyl = match s1 with Nth n1 -> [ List . nth tyl n1 ] | Map l1 -> List . map ( List . nth tyl ) l1 | Id -> tyl |
type best_path = Paths of Path . t list | Best of Path . t |
let printing_env = ref Env . empty |
let printing_depth = ref 0 |
let printing_cont = ref ( [ ] : Env . iter_cont list ) |
let printing_old = ref Env . empty |
let printing_pers = ref Concr . empty |
let printing_map = ref PathMap . empty |
let rec index l x = match l with [ ] -> raise Not_found | a :: l -> if x == a then 0 else 1 + index l x |
let rec uniq = function [ ] -> true | a :: l -> not ( List . memq a l ) && uniq l |
let rec normalize_type_path ( ? cache = false ) env p = try let ( params , ty , _ ) = Env . find_type_expansion p env in let params = List . map repr params in match repr ty with { desc = Tconstr ( p1 , tyl , _ ) } -> let tyl = List . map repr tyl in if List . length params = ... |
let penalty s = if s <> " " && s . [ 0 ] = ' _ ' then 10 else try for i = 0 to String . length s - 2 do if s . [ i ] = ' _ ' && s . [ i + 1 ] = ' _ ' then raise Exit done ; 1 with Exit -> 10 |
let rec path_size = function Pident id -> penalty ( Ident . name id ) , - Ident . binding_time id | Pdot ( p , _ , _ ) -> let ( l , b ) = path_size p in ( 1 + l , b ) | Papply ( p1 , p2 ) -> let ( l , b ) = path_size p1 in ( l + fst ( path_size p2 ) , b ) ... |
let same_printing_env env = let used_pers = Env . used_persistent ( ) in Env . same_types ! printing_old env && Concr . equal ! printing_pers used_pers |
let set_printing_env env = printing_env := if ! Clflags . real_paths then Env . empty else env ; if ! printing_env == Env . empty || same_printing_env env then ( ) else begin printing_old := env ; printing_pers := Env . used_persistent ( ) ; printing_map := PathMap . empty ; printing_... |
let wrap_printing_env env f = set_printing_env env ; try_finally f ( fun ( ) -> set_printing_env Env . empty ) |
let wrap_printing_env env f = Env . without_cmis ( wrap_printing_env env ) f |
let is_unambiguous path env = let l = Env . find_shadowed_types path env in List . exists ( Path . same path ) l || match l with [ ] -> true | p :: rem -> let normalize p = fst ( normalize_type_path ~ cache : true env p ) in let p ' = normalize p in List . for_all ( fun p -> Path . ... |
let rec get_best_path r = match ! r with Best p ' -> p ' | Paths [ ] -> raise Not_found | Paths l -> r := Paths [ ] ; List . iter ( fun p -> match ! r with Best p ' when path_size p >= path_size p ' -> ( ) | _ -> if is_unambiguous p ! printing_env then r := Best p ) l ; ge... |
let best_type_path p = if ! Clflags . real_paths || ! printing_env == Env . empty then ( p , Id ) else let ( p ' , s ) = normalize_type_path ! printing_env p in let get_path ( ) = get_best_path ( PathMap . find p ' ! printing_map ) in while ! printing_cont <> [ ] && try fst... |
let names = ref ( [ ] : ( type_expr * string ) list ) |
let name_counter = ref 0 |
let named_vars = ref ( [ ] : string list ) |
let reset_names ( ) = names := [ ] ; name_counter := 0 ; named_vars := [ ] |
let add_named_var ty = match ty . desc with Tvar ( Some name ) | Tunivar ( Some name ) -> if List . mem name ! named_vars then ( ) else named_vars := name :: ! named_vars | _ -> ( ) |
let rec new_name ( ) = let name = if ! name_counter < 26 then String . make 1 ( Char . chr ( 97 + ! name_counter ) ) else String . make 1 ( Char . chr ( 97 + ! name_counter mod 26 ) ) ^ string_of_int ( ! name_counter / 26 ) in incr name_counter ; if List . mem name ... |
let name_of_type t = try List . assq t ! names with Not_found -> let name = match t . desc with Tvar ( Some name ) | Tunivar ( Some name ) -> let current_name = ref name in let i = ref 0 in while List . exists ( fun ( _ , name ' ) -> ! current_name = name ' ) ! names do current... |
let check_name_of_type t = ignore ( name_of_type t ) |
let remove_names tyl = let tyl = List . map repr tyl in names := List . filter ( fun ( ty , _ ) -> not ( List . memq ty tyl ) ) ! names |
let visited_objects = ref ( [ ] : type_expr list ) |
let aliased = ref ( [ ] : type_expr list ) |
let delayed = ref ( [ ] : type_expr list ) |
let add_delayed t = if not ( List . memq t ! delayed ) then delayed := t :: ! delayed |
let is_aliased ty = List . memq ( proxy ty ) ! aliased |
let add_alias ty = let px = proxy ty in if not ( is_aliased px ) then begin aliased := px :: ! aliased ; add_named_var px end |
let aliasable ty = match ty . desc with Tvar _ | Tunivar _ | Tpoly _ -> false | Tconstr ( p , _ , _ ) -> not ( is_nth ( snd ( best_type_path p ) ) ) | _ -> true |
let namable_row row = row . row_name <> None && List . for_all ( fun ( _ , f ) -> match row_field_repr f with | Reither ( c , l , _ , _ ) -> row . row_closed && if c then l = [ ] else List . length l = 1 | _ -> true ) row . row_fields |
let rec mark_loops_rec visited ty = let ty = repr ty in let px = proxy ty in if List . memq px visited && aliasable ty then add_alias px else let visited = px :: visited in match ty . desc with | Tvar _ -> add_named_var ty | Tarrow ( _ , ty1 , ty2 , _ ) -> mark_loops_rec visited ty1 ; mark_... |
let mark_loops ty = normalize_type Env . empty ty ; mark_loops_rec [ ] ty ; ; |
let reset_loop_marks ( ) = visited_objects := [ ] ; aliased := [ ] ; delayed := [ ] |
let reset ( ) = unique_names := Ident . empty ; reset_names ( ) ; reset_loop_marks ( ) |
let reset_and_mark_loops ty = reset ( ) ; mark_loops ty |
let reset_and_mark_loops_list tyl = reset ( ) ; List . iter mark_loops tyl |
let print_labels = ref true |
let rec tree_of_typexp sch ty = let ty = repr ty in let px = proxy ty in if List . mem_assq px ! names && not ( List . memq px ! delayed ) then let mark = is_non_gen sch ty in Otyp_var ( mark , name_of_type px ) else let pr_typ ( ) = match ty . desc with | Tvar _ -> Otyp_var ( is_non_ge... |
let typexp sch ppf ty = ! Xoprint . out_type ppf ( tree_of_typexp sch ty ) |
let type_expr ppf ty = typexp false ppf ty |
let type_scheme_max ( ? b_reset_names = true ) ppf ty = if b_reset_names then reset_names ( ) ; typexp true ppf ty |
let tree_of_type_scheme ty = reset_and_mark_loops ty ; tree_of_typexp true ty |
let tree_of_constraints params = List . fold_right ( fun ty list -> let ty ' = unalias ty in if proxy ty != proxy ty ' then let tr = tree_of_typexp true ty in ( tr , tree_of_typexp true ty ' ) :: list else list ) params [ ] |
let filter_params tyl = let params = List . fold_left ( fun tyl ty -> let ty = repr ty in if List . memq ty tyl then Btype . newgenty ( Tsubst ty ) :: tyl else ty :: tyl ) [ ] tyl in List . rev params |
let mark_loops_constructor_arguments = function | Cstr_tuple l -> List . iter mark_loops l | Cstr_record l -> List . iter ( fun l -> mark_loops l . ld_type ) l |
let rec tree_of_type_decl id decl = reset ( ) ; let params = filter_params decl . type_params in begin match decl . type_manifest with | Some ty -> let vars = free_variables ty in List . iter ( function { desc = Tvar ( Some " _ " ) } as ty -> if List . memq ty vars then ty . desc ... |
let tree_of_type_declaration id decl rs = Osig_type ( tree_of_type_decl id decl , tree_of_rec rs ) |
let tree_of_extension_constructor id ext es = reset ( ) ; let ty_name = Path . name ext . ext_type_path in let ty_params = filter_params ext . ext_type_params in List . iter add_alias ty_params ; List . iter mark_loops ty_params ; List . iter check_name_of_type ( List . map proxy ty_params ... |
let tree_of_value_description id decl = let id = Ident . name id in let ty = tree_of_type_scheme decl . val_type in let vd = { oval_name = id ; oval_type = ty ; oval_prims = [ ] ; oval_attributes = [ ] } in let vd = match decl . val_kind with | Val_prim p -> Primitive . print p vd ... |
let method_type ( _ , kind , ty ) = match field_kind_repr kind , repr ty with Fpresent , { desc = Tpoly ( ty , tyl ) } -> ( ty , tyl ) | _ , ty -> ( ty , [ ] ) |
let tree_of_metho sch concrete csil ( lab , kind , ty ) = if lab <> dummy_method then begin let kind = field_kind_repr kind in let priv = kind <> Fpresent in let virt = not ( Concr . mem lab concrete ) in let ( ty , tyl ) = method_type ( lab , kind , ty ) in let tty = tree_of_typexp ... |
let rec prepare_class_type params = function | Cty_constr ( _p , tyl , cty ) -> let sty = Ctype . self_type cty in if List . memq ( proxy sty ) ! visited_objects || not ( List . for_all is_Tvar params ) || List . exists ( deep_occur sty ) tyl then prepare_class_type params cty else L... |
let rec tree_of_class_type sch params = function | Cty_constr ( p ' , tyl , cty ) -> let sty = Ctype . self_type cty in if List . memq ( proxy sty ) ! visited_objects || not ( List . for_all is_Tvar params ) then tree_of_class_type sch params cty else Octy_constr ( tree_of_path p ' , ... |
let tree_of_class_param param variance = ( match tree_of_typexp true param with Otyp_var ( _ , s ) -> s | _ -> " " ) , ? if is_Tvar ( repr param ) then ( true , true ) else variance |
let class_variance = List . map Variance . ( fun v -> mem May_pos v , mem May_neg v ) |
let tree_of_class_declaration id cl rs = let params = filter_params cl . cty_params in reset ( ) ; List . iter add_alias params ; prepare_class_type params cl . cty_type ; let sty = Ctype . self_type cl . cty_type in List . iter mark_loops params ; List . iter check_name_of_type ( List . ... |
let tree_of_cltype_declaration id cl rs = let params = List . map repr cl . clty_params in reset ( ) ; List . iter add_alias params ; prepare_class_type params cl . clty_type ; let sty = Ctype . self_type cl . clty_type in List . iter mark_loops params ; List . iter check_name_of_type ( ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.