text stringlengths 0 601k |
|---|
let phrase_buffer = Buffer . create 1024 |
let first_line = ref true |
let got_eof = ref false |
let read_input_default prompt buffer len = output_string stdout prompt ; flush stdout ; let i = ref 0 in try while true do if ! i >= len then raise Exit ; let c = input_char stdin in Bytes . set buffer ! i c ; Buffer . add_char phrase_buffer c ; incr i ; if c = ' \ n ' then raise Exit ; done ; ( ! i , false ) with | En... |
let read_interactive_input = ref read_input_default |
let refill_lexbuf buffer len = if ! got_eof then ( got_eof := false ; 0 ) else begin let prompt = if ! Clflags . noprompt then " " else if ! first_line then " # " else if ! Clflags . nopromptcont then " " else if Lexer . in_comment ( ) then " * " else " " in first_line := false ; let ( len , eof ) = ! read_interactive_... |
let set_paths ( ) = let expand = Misc . expand_directory Config . standard_library in let current_load_path = Load_path . get_paths ( ) in let load_path = List . concat [ [ " " ] ; List . map expand ( List . rev ! Compenv . first_include_dirs ) ; List . map expand ( List . rev ! Clflags . include_dirs ) ; List . map ex... |
let initialize_toplevel_env ( ) = toplevel_env := Compmisc . initial_env ( ) " caml_sys_modify_argv " |
let override_sys_argv new_argv = caml_sys_modify_argv new_argv ; Arg . current := 0 |
type directive_fun = | Directive_none of ( unit -> unit ) | Directive_string of ( string -> unit ) | Directive_int of ( int -> unit ) | Directive_ident of ( Longident . t -> unit ) | Directive_bool of ( bool -> unit ) |
type directive_info = { section : string ; doc : string ; } |
let directive_table = ( Hashtbl . create 23 : ( string , directive_fun ) Hashtbl . t ) |
let directive_info_table = ( Hashtbl . create 23 : ( string , directive_info ) Hashtbl . t ) |
let add_directive name dir_fun dir_info = Hashtbl . add directive_table name dir_fun ; Hashtbl . add directive_info_table name dir_info |
let get_directive name = Hashtbl . find_opt directive_table name |
let get_directive_info name = Hashtbl . find_opt directive_info_table name |
let all_directive_names ( ) = Hashtbl . fold ( fun dir _ acc -> dir :: acc ) directive_table [ ] |
let try_run_directive ppf dir_name pdir_arg = begin match get_directive dir_name with | None -> fprintf ppf " Unknown directive ` % s ' . " dir_name ; let directives = all_directive_names ( ) in Misc . did_you_mean ppf ( fun ( ) -> Misc . spellcheck directives dir_name ) ; fprintf ppf " . " ; @ false | Some d -> match ... |
let section_run = " Loading code " |
let section_env = " Environment queries " |
let section_options = " Compiler options " |
let order_of_sections = ( [ section_general ; section_run ; section_env ; ] , [ section_print ; section_trace ; section_options ; section_undocumented ; ] ) |
let dir_quit ( ) = exit 0 |
let _ = add_directive " quit " ( Directive_none dir_quit ) { section = section_general ; doc = " Exit the toplevel . " ; } |
let dir_directory s = let d = expand_directory Config . standard_library s in Dll . add_path [ d ] ; let dir = Load_path . Dir . create d in Load_path . add dir ; toplevel_env := Stdlib . String . Set . fold ( fun name env -> Env . add_persistent_structure ( Ident . create_persistent name ) env ) ( Env . persistent_str... |
let _ = add_directive " directory " ( Directive_string dir_directory ) { section = section_run ; doc = " Add the given directory to search path for source and compiled \ files . " ; } |
let dir_remove_directory s = let d = expand_directory Config . standard_library s in let keep id = match Load_path . find_uncap ( Ident . name id ^ " . cmi " ) with | exception Not_found -> true | fn -> Filename . dirname fn <> d in toplevel_env := Env . filter_non_loaded_persistent keep ! toplevel_env ; Load_path . re... |
let _ = add_directive " remove_directory " ( Directive_string dir_remove_directory ) { section = section_run ; doc = " Remove the given directory from the search path . " ; } |
let dir_cd s = Sys . chdir s |
let _ = add_directive " cd " ( Directive_string dir_cd ) { section = section_run ; doc = " Change the current working directory . " ; } |
let check_consistency ppf filename cu = try Env . import_crcs ~ source : filename cu . cu_imports with Persistent_env . Consistbl . Inconsistency ( name , user , auth ) -> fprintf ppf " [ @< hv 0 > The files % s @ and % s @ \ disagree over interface % s ] . " @@ user auth name ; raise Load_failed |
let load_compunit ic filename ppf compunit = check_consistency ppf filename compunit ; seek_in ic compunit . cu_pos ; let code_size = compunit . cu_codesize + 8 in let code = LongString . create code_size in LongString . input_bytes_into code ic compunit . cu_codesize ; LongString . set code compunit . cu_codesize ( Ch... |
let rec load_file recursive ppf name = let filename = try Some ( Load_path . find name ) with Not_found -> None in match filename with | None -> fprintf ppf " Cannot find file % s . . " @ name ; false | Some filename -> let ic = open_in_bin filename in Misc . try_finally ~ always ( : fun ( ) -> close_in ic ) ( fun ( ) ... |
let dir_load ppf name = ignore ( load_file false ppf name ) |
let _ = add_directive " load " ( Directive_string ( dir_load std_out ) ) { section = section_run ; doc = " Load in memory a bytecode object , produced by ocamlc . " ; } |
let dir_load_rec ppf name = ignore ( load_file true ppf name ) |
let _ = add_directive " load_rec " ( Directive_string ( dir_load_rec std_out ) ) { section = section_run ; doc = " As # load , but loads dependencies recursively . " ; } |
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 ; ( ty_arg , None ) |
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 . newconstr printer_type [ ty_var ] ) args in let ty_e... |
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_type_old , true ) with Ct... |
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 for a printing function . . " @ Print... |
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 ) ) else ( fun formatter repr -> Obj .... |
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 ! toplevel_env path in if Obj . is_block ... |
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_pointer f . closure f . actual_code ; fprintf p... |
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 , { md with md_attributes = attribute :: md . md_attributes } , ... |
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 ; raise Exit in let id = Ident . create_persi... |
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 then Some Predef . type_exn else None in let... |
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 . find_module path env in accum_aliases md ... |
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 section ( ( name , dir , doc ) :: ( t... |
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 with | None -> fprintf ppf " #% s % s . " @ name param... |
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 module HPM = Hashtbl . Make ( P ) let solve box st vs =... |
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 module HPM = Hashtbl . Make ( P ) let solve box st vs ... |
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 type phase = Widen | Narrow let solve box st vs = let s... |
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 type phase = Widen | Narrow let solve box st vs = let s... |
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 err | Ctype . Tags ( l , l ' ) -> ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.