text stringlengths 12 786k |
|---|
let load_file = load_file false |
let dir_use ppf name = ignore ( Toploop . use_file ppf name ) |
let dir_mod_use ppf name = ignore ( Toploop . mod_use_file ppf name ) |
let _ = add_directive " use " ( Directive_string ( dir_use std_out ) ) { section = section_run ; doc = " Read , compile and execute source phrases from the given file . " ; } |
let _ = add_directive " mod_use " ( Directive_string ( dir_mod_use std_out ) ) { section = section_run ; doc = " Usage is identical to # use but # mod_use \ wraps the contents in a module . " ; } |
let filter_arrow ty = let ty = Ctype . expand_head ! toplevel_env ty in match ty . desc with | Tarrow ( lbl , l , r , _ ) when not ( Btype . is_optional lbl ) -> Some ( l , r ) | _ -> None |
let rec extract_last_arrow desc = match filter_arrow desc with | None -> raise ( Ctype . Unify [ ] ) | Some ( _ , r as res ) -> try extract_last_arrow r with Ctype . Unify _ -> res |
let extract_target_type ty = fst ( extract_last_arrow ty ) |
let extract_target_parameters ty = let ty = extract_target_type ty |> Ctype . expand_head ! toplevel_env in match ty . desc with | Tconstr ( path , ( _ :: _ as args ) , _ ) when Ctype . all_distinct_vars ! toplevel_env args -> Some ( path , args ) | _ -> None |
type ' a printer_type_new = Format . formatter -> ' a -> unit |
type ' a printer_type_old = ' a -> unit |
let printer_type ppf typename = let printer_type = match Env . find_type_by_name ( Ldot ( Lident " Topdirs " , typename ) ) ! toplevel_env with | path , _ -> path | exception Not_found -> fprintf ppf " Cannot find type Topdirs . % s . . " @ typename ; raise Exit in printer_type |
let match_simple_printer_type desc printer_type = Ctype . begin_def ( ) ; let ty_arg = Ctype . newvar ( ) in Ctype . unify ! toplevel_env ( Ctype . newconstr printer_type [ ty_arg ] ) ( Ctype . instance desc . val_type ) ; Ctype . end_def ( ) ; Ctype . generalize ty_arg ... |
let match_generic_printer_type desc path args printer_type = Ctype . begin_def ( ) ; let args = List . map ( fun _ -> Ctype . newvar ( ) ) args in let ty_target = Ctype . newty ( Tconstr ( path , args , ref Mnil ) ) in let ty_args = List . map ( fun ty_var -> Ctype . newco... |
let match_printer_type ppf desc = let printer_type_new = printer_type ppf " printer_type_new " in let printer_type_old = printer_type ppf " printer_type_old " in try ( match_simple_printer_type desc printer_type_new , false ) with Ctype . Unify _ -> try ( match_simple_printer_type desc printer_ty... |
let find_printer_type ppf lid = match Env . find_value_by_name lid ! toplevel_env with | ( path , desc ) -> begin match match_printer_type ppf desc with | ( ty_arg , is_old_style ) -> ( ty_arg , path , is_old_style ) | exception Ctype . Unify _ -> fprintf ppf " % a has a wrong type f... |
let dir_install_printer ppf lid = try let ( ( ty_arg , ty ) , path , is_old_style ) = find_printer_type ppf lid in let v = eval_value_path ! toplevel_env path in match ty with | None -> let print_function = if is_old_style then ( fun _formatter repr -> Obj . obj v ( Obj . obj repr ) ) ... |
let dir_remove_printer ppf lid = try let ( _ty_arg , path , _is_old_style ) = find_printer_type ppf lid in begin try remove_printer path with Not_found -> fprintf ppf " No printer named % a . . " @ Printtyp . longident lid end with Exit -> ( ) |
let _ = add_directive " install_printer " ( Directive_ident ( dir_install_printer std_out ) ) { section = section_print ; doc = " Registers a printer for values of a certain type . " ; } |
let _ = add_directive " remove_printer " ( Directive_ident ( dir_remove_printer std_out ) ) { section = section_print ; doc = " Remove the named function from the table of toplevel printers . " ; } |
let tracing_function_ptr = get_code_pointer ( Obj . repr ( fun arg -> Trace . print_trace ( current_environment ( ) ) arg ) ) |
let dir_trace ppf lid = match Env . find_value_by_name lid ! toplevel_env with | ( path , desc ) -> begin match desc . val_kind with | Val_prim _ -> fprintf ppf " % a is an external function and cannot be traced . . " @ Printtyp . longident lid | _ -> let clos = eval_value_path ! tople... |
let dir_untrace ppf lid = match Env . find_value_by_name lid ! toplevel_env with | ( path , _desc ) -> let rec remove = function | [ ] -> fprintf ppf " % a was not traced . . " @ Printtyp . longident lid ; [ ] | f :: rem -> if Path . same f . path path then begin set_code_po... |
let dir_untrace_all ppf ( ) = List . iter ( fun f -> set_code_pointer f . closure f . actual_code ; fprintf ppf " % a is no longer traced . . " @ Printtyp . path f . path ) ! traced_functions ; traced_functions := [ ] |
let parse_warnings ppf iserr s = try Warnings . parse_options iserr s with Arg . Bad err -> fprintf ppf " % s . . " @ err |
let trim_signature = function Mty_signature sg -> Mty_signature ( List . map ( function Sig_module ( id , pres , md , rs , priv ) -> let attribute = Ast_helper . Attr . mk ( Location . mknoloc " . . . " ) ( Parsetree . PStr [ ] ) in Sig_module ( id , pres , { ... |
let show_prim to_sig ppf lid = let env = ! Toploop . toplevel_env in let loc = Location . none in try let s = match lid with | Longident . Lident s -> s | Longident . Ldot ( _ , s ) -> s | Longident . Lapply _ -> fprintf ppf " Invalid path % a . " @ Printtyp . longident lid ; ra... |
let all_show_funs = ref [ ] |
let reg_show_prim name to_sig doc = all_show_funs := to_sig :: ! all_show_funs ; add_directive name ( Directive_ident ( show_prim to_sig std_out ) ) { section = section_env ; doc ; } |
let ( ) = reg_show_prim " show_val " ( fun env loc id lid -> let _path , desc = Env . lookup_value ~ loc lid env in [ Sig_value ( id , desc , Exported ) ] ) " Print the signature of the corresponding value . " |
let ( ) = reg_show_prim " show_type " ( fun env loc id lid -> let _path , desc = Env . lookup_type ~ loc lid env in [ Sig_type ( id , desc , Trec_not , Exported ) ] ) " Print the signature of the corresponding type constructor . " |
let ( ) = reg_show_prim " show_exception " ( fun env loc id lid -> let desc = Env . lookup_constructor ~ loc Env . Positive lid env in if not ( Ctype . equal env true [ desc . cstr_res ] [ Predef . type_exn ] ) then raise Not_found ; let ret_type = if desc . cstr_generalized the... |
let ( ) = reg_show_prim " show_module " ( fun env loc id lid -> let rec accum_aliases md acc = let acc = Sig_module ( id , Mp_present , { md with md_type = trim_signature md . md_type } , Trec_not , Exported ) :: acc in match md . md_type with | Mty_alias path -> let md = Env . ... |
let ( ) = reg_show_prim " show_module_type " ( fun env loc id lid -> let _path , desc = Env . lookup_modtype ~ loc lid env in [ Sig_modtype ( id , desc , Exported ) ] ) " Print the signature of the corresponding module type . " |
let ( ) = reg_show_prim " show_class " ( fun env loc id lid -> let _path , desc = Env . lookup_class ~ loc lid env in [ Sig_class ( id , desc , Trec_not , Exported ) ] ) " Print the signature of the corresponding class . " |
let ( ) = reg_show_prim " show_class_type " ( fun env loc id lid -> let _path , desc = Env . lookup_cltype ~ loc lid env in [ Sig_class_type ( id , desc , Trec_not , Exported ) ] ) " Print the signature of the corresponding class type . " |
let show env loc id lid = let sg = List . fold_left ( fun sg f -> try ( f env loc id lid ) @ sg with _ -> sg ) [ ] ! all_show_funs in if sg = [ ] then raise Not_found else sg |
let ( ) = add_directive " show " ( Directive_ident ( show_prim show std_out ) ) { section = section_env ; doc = " Print the signatures of components \ from any of the categories below . " ; } |
let _ = add_directive " trace " ( Directive_ident ( dir_trace std_out ) ) { section = section_trace ; doc = " All calls to the function \ named function - name will be traced . " ; } |
let _ = add_directive " untrace " ( Directive_ident ( dir_untrace std_out ) ) { section = section_trace ; doc = " Stop tracing the given function . " ; } |
let _ = add_directive " untrace_all " ( Directive_none ( dir_untrace_all std_out ) ) { section = section_trace ; doc = " Stop tracing all functions traced so far . " ; } |
let _ = add_directive " print_depth " ( Directive_int ( fun n -> max_printer_depth := n ) ) { section = section_print ; doc = " Limit the printing of values to a maximal depth of n . " ; } |
let _ = add_directive " print_length " ( Directive_int ( fun n -> max_printer_steps := n ) ) { section = section_print ; doc = " Limit the number of value nodes printed to at most n . " ; } |
let _ = add_directive " labels " ( Directive_bool ( fun b -> Clflags . classic := not b ) ) { section = section_options ; doc = " Choose whether to ignore labels in function types . " ; } |
let _ = add_directive " principal " ( Directive_bool ( fun b -> Clflags . principal := b ) ) { section = section_options ; doc = " Make sure that all types are derived in a principal way . " ; } |
let _ = add_directive " rectypes " ( Directive_none ( fun ( ) -> Clflags . recursive_types := true ) ) { section = section_options ; doc = " Allow arbitrary recursive types during type - checking . " ; } |
let _ = add_directive " ppx " ( Directive_string ( fun s -> Clflags . all_ppx := s :: ! Clflags . all_ppx ) ) { section = section_options ; doc = " After parsing , pipe the abstract \ syntax tree through the preprocessor command . " ; } |
let _ = add_directive " warnings " ( Directive_string ( parse_warnings std_out false ) ) { section = section_options ; doc = " Enable or disable warnings according to the argument . " ; } |
let _ = add_directive " warn_error " ( Directive_string ( parse_warnings std_out true ) ) { section = section_options ; doc = " Treat as errors the warnings enabled by the argument . " ; } |
let directive_sections ( ) = let sections = Hashtbl . create 10 in let add_dir name dir = let section , doc = match Hashtbl . find directive_info_table name with | { section ; doc } -> section , Some doc | exception Not_found -> " Undocumented " , None in Hashtbl . replace sections se... |
let print_directive ppf ( name , directive , doc ) = let param = match directive with | Directive_none _ -> " " | Directive_string _ -> " < str " > | Directive_int _ -> " < int " > | Directive_bool _ -> " < bool " > | Directive_ident _ -> " < ident " > in match doc w... |
let print_section ppf ( section , directives ) = if directives <> [ ] then begin fprintf ppf " % 30s % s . " @ " " section ; List . iter ( print_directive ppf ) directives ; fprintf ppf " . " ; @ end |
let print_directives ppf ( ) = List . iter ( print_section ppf ) ( directive_sections ( ) ) |
let _ = add_directive " help " ( Directive_none ( print_directives std_out ) ) { section = section_general ; doc = " Prints a list of all available directives , with \ corresponding argument type if appropriate . " ; } |
module WP = functor ( S : EqConstrSys ) -> functor ( HM : Hashtbl . S with type key = S . v ) -> struct include Generic . SolverStats ( S ) ( HM ) module VS = Set . Make ( S . Var ) module P = struct type t = S . Var . t * S . Var . t [ @@ deriving eq , hash ] end ... |
let _ = Selector . add_solver ( " topdown " , ( module EqIncrSolverFromEqSolver ( WP ) ) ) ; |
module TD3 = functor ( S : EqConstrSys ) -> functor ( HM : Hashtbl . S with type key = S . v ) -> struct include Generic . SolverStats ( S ) ( HM ) module VS = Set . Make ( S . Var ) module P = struct type t = S . Var . t * S . Var . t [ @@ deriving eq , hash ] end... |
let _ = Selector . add_solver ( " topdown_deprecated " , ( module EqIncrSolverFromEqSolver ( TD3 ) ) ) ; |
module WP = functor ( S : EqConstrSys ) -> functor ( HM : Hashtbl . S with type key = S . v ) -> struct include Generic . SolverStats ( S ) ( HM ) module VS = Set . Make ( S . Var ) module P = struct type t = S . Var . t * S . Var . t [ @@ deriving eq , hash ] end ... |
let _ = Selector . add_solver ( " topdown_space_cache_term " , ( module EqIncrSolverFromEqSolver ( WP ) ) ) ; |
module WP = functor ( S : EqConstrSys ) -> functor ( HM : Hashtbl . S with type key = S . v ) -> struct include Generic . SolverStats ( S ) ( HM ) module VS = Set . Make ( S . Var ) module P = struct type t = S . Var . t * S . Var . t [ @@ deriving eq , hash ] end ... |
let _ = Selector . add_solver ( " topdown_term " , ( module EqIncrSolverFromEqSolver ( WP ) ) ) ; |
let report_error ppf exn = let report ppf = function | Lexer . Error ( err , l ) -> Location . print_error ppf l ; Lexer . report_error ppf err | Syntaxerr . Error err -> Syntaxerr . report_error ppf err | Env . Error err -> Location . print_error_cur_file ppf ; Env . report_error ppf ... |
let implementation_label = " native toplevel " |
let global_symbol id = let sym = Compilenv . symbol_for_global id in match Tophooks . lookup sym with | None -> fatal_error ( " Toploop . global_symbol " ^ ( Ident . unique_name id ) ) | Some obj -> obj |
let remembered = ref Ident . empty |
let rec remember phrase_name i = function | [ ] -> ( ) | Sig_value ( id , _ , _ ) :: rest | Sig_module ( id , _ , _ , _ , _ ) :: rest | Sig_typext ( id , _ , _ , _ ) :: rest | Sig_class ( id , _ , _ , _ ) :: rest -> remembered := Ident . add id ... |
let toplevel_value id = try Ident . find_same id ! remembered with _ -> Misc . fatal_error @@ " Unknown ident : " ^ Ident . unique_name id |
let close_phrase lam = let open Lambda in Ident . Set . fold ( fun id l -> let glb , pos = toplevel_value id in let glob = Lprim ( Pfield ( pos , Pointer , Mutable ) , [ Lprim ( Pgetglobal glb , [ ] , Loc_unknown ) ] , Loc_unknown ) in Llet ( Strict , Pgenval , id , g... |
let toplevel_value id = let glob , pos = if Config . flambda then toplevel_value id else Translmod . nat_toplevel_name id in ( Obj . magic ( global_symbol glob ) ) . ( pos ) |
module EvalBase = struct let eval_ident id = try if Ident . persistent id || Ident . global id then global_symbol id else toplevel_value id with _ -> raise ( Undefined_global ( Ident . name id ) ) end |
let may_trace = ref false |
let load_lambda ppf ~ module_ident ~ required_globals phrase_name lam size = if ! Clflags . dump_rawlambda then fprintf ppf " % a . " @ Printlambda . lambda lam ; let slam = Simplif . simplify_lambda lam in if ! Clflags . dump_lambda then fprintf ppf " % a . " @ Printlambda . lambda sl... |
let pr_item = Printtyp . print_items ( fun env -> function | Sig_value ( id , { val_kind = Val_reg ; val_type } , _ ) -> Some ( outval_of_value env ( toplevel_value id ) val_type ) | _ -> None ) |
let phrase_seqid = ref 0 |
let execute_phrase print_outcome ppf phr = match phr with | Ptop_def sstr -> let oldenv = ! toplevel_env in incr phrase_seqid ; let phrase_name = " TOP " ^ string_of_int ! phrase_seqid in Compilenv . reset ? packname : None phrase_name ; Typecore . reset_delayed_checks ( ) ; let sstr , rew... |
let getvalue _ = assert false |
let setvalue _ _ = assert false |
let load_file _ ppf name0 = let name = try Some ( Load_path . find name0 ) with Not_found -> None in match name with | None -> fprintf ppf " File not found : % s . " @ name0 ; false | Some name -> let fn , tmp = if Filename . check_suffix name " . cmx " || Filename . check_suffix ... |
let init ( ) = Compmisc . init_path ( ) ; Clflags . dlcode := true ; ( ) |
let rec uniq = function x :: l when List . mem x l -> uniq l | x :: l -> x :: uniq l | l -> l |
let split_in_words s = let l = String . length s in let rec split i j = if j < l then let j ' = succ j in match s . [ j ] with ( ' ' ' |\ t ' ' |\ n ' ' |\ r ' ' , ' ) | -> let rem = split j ' j ' in if i < j then ( String . sub s i ( j - i ) ) :: rem else... |
let normalize_dirname d = let s = String . copy d in let l = String . length d in let norm_dir_unix ( ) = for k = 1 to l - 1 do if s . [ k ] = ' ' / && s . [ k - 1 ] = ' ' / then s . [ k ] <- Char . chr 0 ; if s . [ k ] = ' ' / && k = l - 1 then s .... |
let forbidden = ref ( [ ] : string list ) |
let loaded = ref ( [ ] : string list ) |
let predicates = ref ( [ ] : string list ) |
let add_directory d = let d = normalize_dirname d in let d = expand_directory Config . standard_library d in if not ( List . mem d ! Config . load_path ) then begin Config . load_path := d :: ! Config . load_path ; if real_toploop then fprintf std_formatter " [ ` @% s ' added to search p... |
let add_predicates pl = predicates := uniq ( pl @ ! predicates ) |
let syntax s = add_predicates [ " syntax " ; s ] |
let standard_syntax ( ) = syntax " camlp4o " |
let revised_syntax ( ) = syntax " camlp4r " |
let load pl = List . iter ( fun p -> if not ( List . mem p ! loaded ) then begin let d = Findlib . package_directory p in add_directory d ; if not ( List . mem p ! forbidden ) then begin let archive = ( try Findlib . package_property ! predicates p " archive " with Not_found -> " "... |
let load_deeply pl = load ( Findlib . package_deep_ancestors ! predicates pl ) |
let don ' t_load pl = forbidden := uniq ( pl @ ! forbidden ) ; List . iter ( fun p -> ignore ( Findlib . package_directory p ) ) pl |
let don ' t_load_deeply pl = List . iter ( fun p -> ignore ( Findlib . package_directory p ) ) pl ; don ' t_load ( Findlib . package_deep_ancestors ! predicates pl ) |
let protect f x = try ignore ( f x ) with Failure s -> fprintf err_formatter " [ @% s ] . " @@ s |
let reset ( ) = loaded := [ ] ; Hashtbl . replace directive_table " require " ( Directive_string ( protect ( fun s -> load_deeply ( split_in_words s ) ) ) ) ; Hashtbl . replace directive_table " predicates " ( Directive_string ( protect ( fun s -> add_predicates ( spl... |
let announce ( ) = if real_toploop then begin print_endline ( " Findlib has been successfully loaded . Additional directives :\ n " ^ " # require " \ package " ; ; \ to load a package \ n " ^ " # list ; ; to list the available packages \ n " ^ " # camlp4o ; ; to load ca... |
let lookup sym = Dynlink . unsafe_get_global_value ~ bytecode_or_asm_symbol : sym |
let need_symbol sym = Option . is_none ( Dynlink . unsafe_get_global_value ~ bytecode_or_asm_symbol : sym ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.