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 | End_of_file -> ( ! i , true ) | Exit -> ( ! i , false )
|
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_input prompt buffer len in if eof then begin Location . echo_eof ( ) ; if len > 0 then got_eof := true ; len end else len end
|
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 expand ( List . rev ! Compenv . last_include_dirs ) ; current_load_path ; [ expand " + camlp4 " ] ; ] in Load_path . init load_path ; Dll . add_path load_path
|
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 d , pdir_arg with | Directive_none f , None -> f ( ) ; true | Directive_string f , Some { pdira_desc = Pdir_string s } -> f s ; true | Directive_int f , Some { pdira_desc = Pdir_int ( n , None ) } -> begin match Misc . Int_literal_converter . int n with | n -> f n ; true | exception _ -> fprintf ppf " Integer literal exceeds the range of \ representable integers for directive ` % s ' . . " @ dir_name ; false end | Directive_int _ , Some { pdira_desc = Pdir_int ( _ , Some _ ) } -> fprintf ppf " Wrong integer literal for directive ` % s ' . . " @ dir_name ; false | Directive_ident f , Some { pdira_desc = Pdir_ident lid } -> f lid ; true | Directive_bool f , Some { pdira_desc = Pdir_bool b } -> f b ; true | _ -> let dir_type = match d with | Directive_none _ -> " no argument " | Directive_string _ -> " a ` string ' literal " | Directive_int _ -> " an ` int ' literal " | Directive_ident _ -> " an identifier " | Directive_bool _ -> " a ` bool ' literal " in let arg_type = match pdir_arg with | None -> " no argument " | Some { pdira_desc = Pdir_string _ } -> " a ` string ' literal " | Some { pdira_desc = Pdir_int _ } -> " an ` int ' literal " | Some { pdira_desc = Pdir_ident _ } -> " an identifier " | Some { pdira_desc = Pdir_bool _ } -> " a ` bool ' literal " in fprintf ppf " Directive ` % s ' expects % s , got % s . . " @ dir_name dir_type arg_type ; false end
|
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_structures_of_dir dir ) ! toplevel_env
|
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 . remove_dir s ; Dll . remove_path [ d ]
|
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 ( Char . chr Opcodes . opRETURN ) ; LongString . blit_string " \ 000 \ 000 \ 000 \ 001 \ 000 \ 000 \ 000 " 0 code ( compunit . cu_codesize + 1 ) 7 ; let initial_symtable = Symtable . current_state ( ) in Symtable . patch_object code compunit . cu_reloc ; Symtable . update_global_table ( ) ; let events = if compunit . cu_debug = 0 then [ | ] | else begin seek_in ic compunit . cu_debug ; [ | input_value ic ] | end in begin try may_trace := true ; let _bytecode , closure = Meta . reify_bytecode code events None in ignore ( closure ( ) ) ; may_trace := false ; with exn -> record_backtrace ( ) ; may_trace := false ; Symtable . restore_state initial_symtable ; print_exception_outcome ppf exn ; raise Load_failed end
|
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 ( ) -> really_load_file recursive ppf name filename ic ) let buffer = really_input_string ic ( String . length Config . cmo_magic_number ) in try if buffer = Config . cmo_magic_number then begin let compunit_pos = input_binary_int ic in seek_in ic compunit_pos ; let cu : compilation_unit = input_value ic in if recursive then List . iter ( function | ( Reloc_getglobal id , _ ) when not ( Symtable . is_global_defined id ) -> let file = Ident . name id ^ " . cmo " in begin match Load_path . find_uncap file with | exception Not_found -> ( ) | file -> if not ( load_file recursive ppf file ) then raise Load_failed end | _ -> ( ) ) cu . cu_reloc ; load_compunit ic filename ppf cu ; true end else if buffer = Config . cma_magic_number then begin let toc_pos = input_binary_int ic in seek_in ic toc_pos ; let lib = ( input_value ic : library ) in List . iter ( fun dllib -> let name = Dll . extract_dll_name dllib in try Dll . open_dlls Dll . For_execution [ name ] with Failure reason -> fprintf ppf " Cannot load required shared library % s . . @ Reason : % s . . " @ name reason ; raise Load_failed ) lib . lib_dllibs ; List . iter ( load_compunit ic filename ppf ) lib . lib_units ; true end else begin fprintf ppf " File % s is not a bytecode object file . . " @ name ; false end with Load_failed -> false
|
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_expected = List . fold_right ( fun ty_arg ty -> Ctype . newty ( Tarrow ( Asttypes . Nolabel , ty_arg , ty , Cunknown ) ) ) ty_args ( Ctype . newconstr printer_type [ ty_target ] ) in Ctype . unify ! toplevel_env ty_expected ( Ctype . instance desc . val_type ) ; Ctype . end_def ( ) ; Ctype . generalize ty_expected ; if not ( Ctype . all_distinct_vars ! toplevel_env args ) then raise ( Ctype . Unify [ ] ) ; ( ty_expected , Some ( path , ty_args ) )
|
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 Ctype . Unify _ as exn -> match extract_target_parameters desc . val_type with | None -> raise exn | Some ( path , args ) -> ( match_generic_printer_type desc path args printer_type_new , false )
|
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 . . " @ Printtyp . longident lid ; raise Exit end | exception Not_found -> fprintf ppf " Unbound value % a . . " @ Printtyp . longident lid ; raise Exit
|
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 . obj v formatter ( Obj . obj repr ) ) in install_printer path ty_arg print_function | Some ( ty_path , ty_args ) -> let rec build v = function | [ ] -> let print_function = if is_old_style then ( fun _formatter repr -> Obj . obj v ( Obj . obj repr ) ) else ( fun formatter repr -> Obj . obj v formatter ( Obj . obj repr ) ) in Zero print_function | _ :: args -> Succ ( fun fn -> build ( ( Obj . obj v : _ -> Obj . t ) fn ) args ) in install_generic_printer ' path ty_path ( build v ty_args ) with Exit -> ( )
|
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 clos && ( Obj . tag clos = Obj . closure_tag || Obj . tag clos = Obj . infix_tag ) && ( match Ctype . ( repr ( expand_head ! toplevel_env desc . val_type ) ) with { desc = Tarrow _ } -> true | _ -> false ) then begin match is_traced clos with | Some opath -> fprintf ppf " % a is already traced ( under the name % a ) . . " @ Printtyp . path path Printtyp . path opath | None -> traced_functions := { path = path ; closure = clos ; actual_code = get_code_pointer clos ; instrumented_fun = instrument_closure ! toplevel_env lid ppf desc . val_type } :: ! traced_functions ; set_code_pointer clos tracing_function_ptr ; fprintf ppf " % a is now traced . . " @ Printtyp . longident lid end else fprintf ppf " % a is not a function . . " @ Printtyp . longident lid end | exception Not_found -> fprintf ppf " Unbound value % a . . " @ Printtyp . longident lid
|
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 ppf " % a is no longer traced . . " @ Printtyp . longident lid ; rem end else f :: remove rem in traced_functions := remove ! traced_functions | exception Not_found -> fprintf ppf " Unbound value % a . . " @ Printtyp . longident lid
|
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 } , rs , priv ) | item -> item ) sg ) | mty -> mty
|
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_persistent s in let sg = to_sig env loc id lid in Printtyp . wrap_printing_env ~ error : false env ( fun ( ) -> fprintf ppf " [ @% a ] . " @@ Printtyp . signature sg ) with | Not_found -> fprintf ppf " [ @ Unknown element . ] . " @@ | Exit -> ( )
|
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 ext = { ext_type_path = Predef . path_exn ; ext_type_params = [ ] ; ext_args = Cstr_tuple desc . cstr_args ; ext_ret_type = ret_type ; ext_private = Asttypes . Public ; Types . ext_loc = desc . cstr_loc ; Types . ext_attributes = desc . cstr_attributes ; } in [ Sig_typext ( id , ext , Text_exception , Exported ) ] ) " Print the signature of the corresponding exception . "
|
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 acc | Mty_ident _ | Mty_signature _ | Mty_functor _ -> List . rev acc in let _ , md = Env . lookup_module ~ loc lid env in accum_aliases md [ ] ) " Print the signature of the corresponding module . "
|
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 ) :: ( try Hashtbl . find sections section with Not_found -> [ ] ) ) in Hashtbl . iter add_dir directive_table ; let take_section section = if not ( Hashtbl . mem sections section ) then ( section , [ ] ) else begin let section_dirs = Hashtbl . find sections section |> List . sort ( fun ( n1 , _ , _ ) ( n2 , _ , _ ) -> String . compare n1 n2 ) in Hashtbl . remove sections section ; ( section , section_dirs ) end in let before , after = order_of_sections in let sections_before = List . map take_section before in let sections_after = List . map take_section after in let sections_user = Hashtbl . fold ( fun section _ acc -> section :: acc ) sections [ ] |> List . sort String . compare |> List . map take_section in sections_before @ sections_user @ sections_after
|
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 | Some doc -> fprintf ppf " [ @< hov 2 >#% s % s @\ n % a ] . " @@ name param Format . pp_print_text doc
|
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 stable = HM . create 10 in let infl = HM . create 10 in let set = HM . create 10 in let sidevs = HM . create 10 in let called = HM . create 10 in let rho = HM . create 10 in let rho ' = HPM . create 10 in let wpoint = HM . create 10 in let add_infl y x = if tracing then trace " sol2 " " add_infl % a % a \ n " S . Var . pretty_trace y S . Var . pretty_trace x ; HM . replace infl y ( VS . add x ( try HM . find infl y with Not_found -> VS . empty ) ) in let add_set x y d = HM . replace set y ( VS . add x ( try HM . find set y with Not_found -> VS . empty ) ) ; HPM . add rho ' ( x , y ) d ; HM . replace sidevs y ( ) in let is_side x = HM . mem set x in let rec destabilize x = let w = HM . find_default infl x VS . empty in HM . replace infl x VS . empty ; VS . iter ( fun y -> HM . remove stable y ; if tracing then trace " sol2 " " destabilize % a \ n " S . Var . pretty_trace y ; if not ( HM . mem called y ) then destabilize y ) w and solve x = if tracing then trace " sol2 " " solve % a , called : % b , stable : % b \ n " S . Var . pretty_trace x ( HM . mem called x ) ( HM . mem stable x ) ; if not ( HM . mem called x || HM . mem stable x ) then ( HM . replace stable x ( ) ; HM . replace called x ( ) ; let wpx = HM . mem wpoint x in init x ; let old = HM . find rho x in let tmp ' = eq x ( eval x ) ( side x ) in let tmp = S . Dom . join tmp ' ( sides x ) in if tracing then trace " sol " " Var : % a \ n " S . Var . pretty_trace x ; if tracing then trace " sol " " Contrib :% a \ n " S . Dom . pretty tmp ; let tmp = if is_side x then S . Dom . widen old ( S . Dom . join old tmp ) else if wpx then box x old tmp else tmp in HM . remove called x ; if not ( S . Dom . equal old tmp ) then ( if tracing then if is_side x then trace " sol2 " " solve side : old = % a , tmp = % a , widen = % a \ n " S . Dom . pretty old S . Dom . pretty tmp S . Dom . pretty ( S . Dom . widen old ( S . Dom . join old tmp ) ) ; update_var_event x old tmp ; if tracing then trace " sol " " New Value :% a \ n \ n " S . Dom . pretty tmp ; if tracing then trace " sol2 " " new value for % a ( wpx : % b , is_side : % b ) is % a . Old value was % a \ n " S . Var . pretty_trace x ( HM . mem rho x ) ( is_side x ) S . Dom . pretty tmp S . Dom . pretty old ; HM . replace rho x tmp ; destabilize x ; ) ; ( solve [ @ tailcall ] ) x ) and eq x get set = if tracing then trace " sol2 " " eq % a \ n " S . Var . pretty_trace x ; eval_rhs_event x ; match S . system x with | None -> S . Dom . bot ( ) | Some f -> let effects = ref Set . empty in let sidef y d = if not ( Set . mem y ! effects ) then ( HPM . replace rho ' ( x , y ) ( S . Dom . bot ( ) ) ; effects := Set . add y ! effects ) ; set y d in f get sidef and eval x y = if tracing then trace " sol2 " " eval % a ## % a \ n " S . Var . pretty_trace x S . Var . pretty_trace y ; get_var_event y ; if HM . mem called y || S . system y = None then HM . replace wpoint y ( ) ; solve y ; add_infl y x ; HM . find rho y and sides x = let w = try HM . find set x with Not_found -> VS . empty in let d = Enum . fold ( fun d y -> let r = try S . Dom . join d ( HPM . find rho ' ( y , x ) ) with Not_found -> d in if tracing then trace " sol2 " " sides : side % a from % a : % a \ n " S . Var . pretty_trace x S . Var . pretty_trace y S . Dom . pretty r ; r ) ( S . Dom . bot ( ) ) ( VS . enum w ) in if tracing then trace " sol2 " " sides % a ## % a \ n " S . Var . pretty_trace x S . Dom . pretty d ; d and side x y d = if tracing then trace " sol2 " " side % a ## % a ( wpx : % b ) ## % a \ n " S . Var . pretty_trace x S . Var . pretty_trace y ( HM . mem rho y ) S . Dom . pretty d ; let old = try HPM . find rho ' ( x , y ) with Not_found -> S . Dom . bot ( ) in if not ( S . Dom . equal old d ) then ( add_set x y ( S . Dom . join old d ) ; HM . remove stable y ; solve y ; ) and init x = if tracing then trace " sol2 " " init % a \ n " S . Var . pretty_trace x ; if not ( HM . mem rho x ) then ( new_var_event x ; HM . replace rho x ( S . Dom . bot ( ) ) ) in let set_start ( x , d ) = if tracing then trace " sol2 " " set_start % a ## % a \ n " S . Var . pretty_trace x S . Dom . pretty d ; init x ; add_set x x d ; solve x in start_event ( ) ; List . iter set_start st ; List . iter init vs ; List . iter solve vs ; let keys h = HM . fold ( fun k _ a -> k :: a ) h [ ] in let n = ref 1 in let rec solve_sidevs ( ) = let gs = keys sidevs in HM . clear sidevs ; if gs <> [ ] then ( if tracing then trace " sol2 " " Round % d : % d side - effected variables to solve \ n " ! n ( List . length gs ) ; incr n ; List . iter solve gs ; List . iter solve vs ; solve_sidevs ( ) ) in solve_sidevs ( ) ; stop_event ( ) ; HM . clear stable ; HM . clear infl ; HM . clear set ; HPM . clear rho ' ; rho 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 module HPM = Hashtbl . Make ( P ) let solve box st vs = let wpoint = HM . create 10 in let stable = HM . create 10 in let infl = HM . create 10 in let set = HM . create 10 in let sidevs = HM . create 10 in let called = HM . create 10 in let rho = HM . create 10 in let rho ' = HPM . create 10 in let add_infl y x = HM . replace infl y ( VS . add x ( try HM . find infl y with Not_found -> VS . empty ) ) in let add_set x y d = HM . replace set y ( VS . add x ( try HM . find set y with Not_found -> VS . empty ) ) ; HPM . add rho ' ( x , y ) d ; HM . add sidevs y ( ) in let is_side x = HM . mem set x in let make_wpoint x = if tracing then trace " sol2 " " make_wpoint % a \ n " S . Var . pretty_trace x ; HM . replace wpoint x ( ) in let rec destabilize x = if tracing then trace " sol2 " " destabilize % a \ n " S . Var . pretty_trace x ; let t = HM . find_default infl x VS . empty in HM . replace infl x VS . empty ; VS . iter ( fun y -> HM . remove stable y ; if not ( HM . mem called y ) then destabilize y ) t and solve x = if tracing then trace " sol2 " " solve % a , called : % b , stable : % b \ n " S . Var . pretty_trace x ( HM . mem called x ) ( HM . mem stable x ) ; if not ( HM . mem called x || HM . mem stable x ) then begin HM . replace called x ( ) ; let wpx = HM . mem wpoint x in HM . remove wpoint x ; HM . replace stable x ( ) ; let old = HM . find rho x in let tmp = eq x ( eval x ) ( side x ) in let tmp = S . Dom . join tmp ( sides x ) in if tracing then trace " sol " " Var : % a \ n " S . Var . pretty_trace x ; if tracing then trace " sol " " Contrib :% a \ n " S . Dom . pretty tmp ; let tmp = if is_side x then S . Dom . widen old ( S . Dom . join old tmp ) else if wpx then box x old tmp else tmp in HM . remove called x ; if not ( S . Dom . equal old tmp ) then begin update_var_event x old tmp ; if tracing then trace " sol " " New Value :% a \ n \ n " S . Dom . pretty tmp ; if tracing then trace " sol2 " " new value for % a ( wpx : % b , is_side : % b ) is % a . Old value was % a \ n " S . Var . pretty_trace x wpx ( is_side x ) S . Dom . pretty tmp S . Dom . pretty old ; HM . replace rho x tmp ; destabilize x ; ( solve [ @ tailcall ] ) x ; end ; end ; and eq x get set = if tracing then trace " sol2 " " eq % a \ n " S . Var . pretty_trace x ; eval_rhs_event x ; match S . system x with | None -> S . Dom . bot ( ) | Some f -> let effects = ref Set . empty in let sidef y d = if not ( Set . mem y ! effects ) then ( HPM . replace rho ' ( x , y ) ( S . Dom . bot ( ) ) ; effects := Set . add y ! effects ) ; set y d in f get sidef and eval x y = if tracing then trace " sol2 " " eval % a ## % a \ n " S . Var . pretty_trace x S . Var . pretty_trace y ; get_var_event y ; if not ( HM . mem rho y ) then init y ; if HM . mem called y then make_wpoint y else if neg is_side y then solve y ; add_infl y x ; HM . find rho y and sides x = let w = try HM . find set x with Not_found -> VS . empty in let d = Enum . fold ( fun d z -> try S . Dom . join d ( HPM . find rho ' ( z , x ) ) with Not_found -> d ) ( S . Dom . bot ( ) ) ( VS . enum w ) in if tracing then trace " sol2 " " sides % a ## % a \ n " S . Var . pretty_trace x S . Dom . pretty d ; d and side x y d = if S . Dom . is_bot d then ( ) else if tracing then trace " sol2 " " side % a ## % a ( wpx : % b ) ## % a \ n " S . Var . pretty_trace x S . Var . pretty_trace y ( HM . mem wpoint y ) S . Dom . pretty d ; if not ( HM . mem rho y ) then begin init y ; add_set x y d ; solve y end else begin let old = HPM . find rho ' ( x , y ) in if not ( S . Dom . equal old d ) then begin add_set x y ( S . Dom . join old d ) ; HM . remove stable y ; HM . replace sidevs y ( ) ; end end and init x = if tracing then trace " sol2 " " init % a \ n " S . Var . pretty_trace x ; if not ( HM . mem rho x ) then begin new_var_event x ; HM . replace rho x ( S . Dom . bot ( ) ) ; HM . replace infl x ( VS . add x VS . empty ) end in let set_start ( x , d ) = if tracing then trace " sol2 " " set_start % a ## % a \ n " S . Var . pretty_trace x S . Dom . pretty d ; init x ; add_set x x d ; solve x in start_event ( ) ; List . iter set_start st ; List . iter init vs ; List . iter solve vs ; let get_gs ( ) = let vs = ref [ ] in HM . iter ( fun k _ -> vs := k :: ! vs ) sidevs ; HM . clear sidevs ; ! vs in let rec solveg ( ) = let gs = get_gs ( ) in if gs <> [ ] then ( List . iter solve gs ; List . iter solve vs ; solveg ( ) ) in solveg ( ) ; stop_event ( ) ; HM . clear wpoint ; HM . clear stable ; HM . clear infl ; HM . clear set ; HPM . clear rho ' ; rho 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 type phase = Widen | Narrow let solve box st vs = let stable = HM . create 10 in let infl = HM . create 10 in let called = HM . create 10 in let rho = HM . create 10 in let rho ' = HM . create 10 in let cache_sizes = ref [ ] in let add_infl y x = if tracing then trace " sol2 " " add_infl % a % a \ n " S . Var . pretty_trace y S . Var . pretty_trace x ; HM . replace infl y ( VS . add x ( try HM . find infl y with Not_found -> VS . empty ) ) in let rec destabilize x = if tracing then trace " sol2 " " destabilize % a \ n " S . Var . pretty_trace x ; let w = HM . find_default infl x VS . empty in HM . replace infl x VS . empty ; VS . iter ( fun y -> HM . remove stable y ; if not ( HM . mem called y ) then destabilize y ) w and solve x phase = if tracing then trace " sol2 " " solve % a , called : % b , stable : % b \ n " S . Var . pretty_trace x ( HM . mem called x ) ( HM . mem stable x ) ; if not ( HM . mem called x || HM . mem stable x ) then ( HM . replace stable x ( ) ; HM . replace called x ( ) ; let old = HM . find rho x in let l = HM . create 10 in let tmp = eq x ( eval l x ) ( side l ) in let tmp = S . Dom . join tmp ( try HM . find rho ' x with Not_found -> S . Dom . bot ( ) ) in if tracing then trace " sol " " Var : % a \ n " S . Var . pretty_trace x ; if tracing then trace " sol " " Contrib :% a \ n " S . Dom . pretty tmp ; HM . remove called x ; let tmp = match phase with Widen -> S . Dom . widen old ( S . Dom . join old tmp ) | Narrow -> S . Dom . narrow old tmp in if tracing then trace " cache " " cache size % d for % a \ n " ( HM . length l ) S . Var . pretty_trace x ; cache_sizes := HM . length l :: ! cache_sizes ; if not ( S . Dom . equal old tmp ) then ( update_var_event x old tmp ; if tracing then trace " sol " " New Value :% a \ n \ n " S . Dom . pretty tmp ; HM . replace rho x tmp ; destabilize x ; ( solve [ @ tailcall ] ) x phase ; ) else if not ( HM . mem stable x ) then ( ( solve [ @ tailcall ] ) x Widen ; ) else if phase = Widen then ( HM . remove stable x ; ( solve [ @ tailcall ] ) x Narrow ; ) ; ) and eq x get set = if tracing then trace " sol2 " " eq % a \ n " S . Var . pretty_trace x ; eval_rhs_event x ; match S . system x with | None -> S . Dom . bot ( ) | Some f -> f get set and simple_solve l x y = if tracing then trace " sol2 " " simple_solve % a ( rhs : % b ) \ n " S . Var . pretty_trace y ( S . system y <> None ) ; if S . system y = None then init y ; if HM . mem rho y then ( solve y Widen ; HM . find rho y ) else if HM . mem called y then ( init y ; HM . remove l y ; HM . find rho y ) else if HM . mem l y then HM . find l y else ( HM . replace called y ( ) ; let tmp = eq y ( eval l x ) ( side l ) in HM . remove called y ; if HM . mem rho y then ( HM . remove l y ; solve y Widen ; HM . find rho y ) else ( HM . replace l y tmp ; tmp ) ) and eval l x y = if tracing then trace " sol2 " " eval % a ## % a \ n " S . Var . pretty_trace x S . Var . pretty_trace y ; get_var_event y ; let tmp = simple_solve l x y in if HM . mem rho y then add_infl y x ; tmp and side l y d = if tracing then trace " sol2 " " side to % a ( wpx : % b ) ## value : % a \ n " S . Var . pretty_trace y ( HM . mem rho y ) S . Dom . pretty d ; let old = try HM . find rho ' y with Not_found -> S . Dom . bot ( ) in if not ( S . Dom . leq d old ) then ( HM . replace rho ' y ( S . Dom . join old d ) ; HM . remove l y ; HM . remove stable y ; init y ; solve y Widen ; ) and init x = if tracing then trace " sol2 " " init % a \ n " S . Var . pretty_trace x ; if not ( HM . mem rho x ) then ( new_var_event x ; HM . replace rho x ( S . Dom . bot ( ) ) ) in let set_start ( x , d ) = if tracing then trace " sol2 " " set_start % a ## % a \ n " S . Var . pretty_trace x S . Dom . pretty d ; init x ; HM . replace rho x d ; HM . replace rho ' x d ; solve x Widen in start_event ( ) ; List . iter set_start st ; List . iter init vs ; List . iter ( fun x -> solve x Widen ) vs ; let rec solve_sidevs ( ) = let non_stable = List . filter ( neg ( HM . mem stable ) ) vs in if non_stable <> [ ] then ( List . iter ( fun x -> solve x Widen ) non_stable ; solve_sidevs ( ) ) in solve_sidevs ( ) ; let visited = HM . create 10 in let rec get x = if HM . mem visited x then ( if not ( HM . mem rho x ) then ( ignore @@ Pretty . printf " Found an unknown that should be a widening point : % a \ n " S . Var . pretty_trace x ; S . Dom . top ( ) ) else HM . find rho x ) else ( HM . replace visited x ( ) ; let check_side y d = let d ' = try HM . find rho y with Not_found -> S . Dom . bot ( ) in if not ( S . Dom . leq d d ' ) then ignore @@ Pretty . printf " Fixpoint not reached in restore step at side - effected variable % a : % a not leq % a \ n " S . Var . pretty_trace y S . Dom . pretty d S . Dom . pretty d ' in let eq x = match S . system x with | None -> if HM . mem rho x then HM . find rho x else S . Dom . bot ( ) | Some f -> f get check_side in if HM . mem rho x then ( let d1 = HM . find rho x in let d2 = eq x in if not ( S . Dom . leq d2 d1 ) then ignore @@ Pretty . printf " Fixpoint not reached in restore step at % a \ n [ @ Variable :\ n % a \ nRight - Hand - Side :\ n % a \ nCalculating one more step changes : % a \ n ] " @ S . Var . pretty_trace x S . Dom . pretty d1 S . Dom . pretty d2 S . Dom . pretty_diff ( d1 , d2 ) ; d1 ) else ( let d = eq x in HM . replace rho x d ; d ) ) in if GobConfig . get_bool " solvers . wp . restore " then ( if ( GobConfig . get_bool " dbg . verbose " ) then print_endline ( " Restoring missing values . " ) ; let restore ( ) = let get x = let d = get x in if tracing then trace " sol2 " " restored var % a ## % a \ n " S . Var . pretty_trace x S . Dom . pretty d in List . iter get vs in Stats . time " restore " restore ( ) ; if ( GobConfig . get_bool " dbg . verbose " ) then ignore @@ Pretty . printf " Solved % d vars . Total of % d vars after restore . \ n " ! Goblintutil . vars ( HM . length rho ) ; ) ; let avg xs = float_of_int ( BatList . sum xs ) . / float_of_int ( List . length xs ) in if tracing then trace " cache " " # caches : % d , max : % d , avg : . % 2f \ n " ( List . length ! cache_sizes ) ( List . max ! cache_sizes ) ( avg ! cache_sizes ) ; stop_event ( ) ; HM . clear stable ; HM . clear infl ; rho 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 type phase = Widen | Narrow let solve box st vs = let stable = HM . create 10 in let infl = HM . create 10 in let called = HM . create 10 in let rho = HM . create 10 in let rho ' = HM . create 10 in let wpoint = HM . create 10 in let add_infl y x = if tracing then trace " sol2 " " add_infl % a % a \ n " S . Var . pretty_trace y S . Var . pretty_trace x ; HM . replace infl y ( VS . add x ( try HM . find infl y with Not_found -> VS . empty ) ) in let rec destabilize x = if tracing then trace " sol2 " " destabilize % a \ n " S . Var . pretty_trace x ; let w = HM . find_default infl x VS . empty in HM . replace infl x VS . empty ; VS . iter ( fun y -> HM . remove stable y ; if not ( HM . mem called y ) then destabilize y ) w and solve x phase = if tracing then trace " sol2 " " solve % a , called : % b , stable : % b \ n " S . Var . pretty_trace x ( HM . mem called x ) ( HM . mem stable x ) ; if not ( HM . mem called x || HM . mem stable x ) then ( HM . replace stable x ( ) ; HM . replace called x ( ) ; let wpx = HM . mem wpoint x in init x ; let old = HM . find rho x in let tmp = eq x ( eval x ) side in let tmp = S . Dom . join tmp ( try HM . find rho ' x with Not_found -> S . Dom . bot ( ) ) in if tracing then trace " sol " " Var : % a \ n " S . Var . pretty_trace x ; if tracing then trace " sol " " Contrib :% a \ n " S . Dom . pretty tmp ; HM . remove called x ; let tmp = if wpx then match phase with Widen -> S . Dom . widen old ( S . Dom . join old tmp ) | Narrow -> S . Dom . narrow old tmp else tmp in if not ( S . Dom . equal old tmp ) then ( update_var_event x old tmp ; if tracing then trace " sol " " New Value :% a \ n \ n " S . Dom . pretty tmp ; HM . replace rho x tmp ; destabilize x ; ( solve [ @ tailcall ] ) x phase ; ) else if not ( HM . mem stable x ) then ( ( solve [ @ tailcall ] ) x Widen ; ) else if phase = Widen && S . system x <> None then ( HM . remove stable x ; ( solve [ @ tailcall ] ) x Narrow ; ) ; ) and eq x get set = if tracing then trace " sol2 " " eq % a \ n " S . Var . pretty_trace x ; eval_rhs_event x ; match S . system x with | None -> S . Dom . bot ( ) | Some f -> f get set and eval x y = if tracing then trace " sol2 " " eval % a ## % a \ n " S . Var . pretty_trace x S . Var . pretty_trace y ; get_var_event y ; if HM . mem called y then HM . replace wpoint y ( ) ; solve y Widen ; add_infl y x ; HM . find rho y and side y d = let old = try HM . find rho ' y with Not_found -> S . Dom . bot ( ) in if not ( S . Dom . leq d old ) then ( HM . replace rho ' y ( S . Dom . widen old d ) ; HM . remove stable y ; init y ; solve y Widen ; ) and init x = if tracing then trace " sol2 " " init % a \ n " S . Var . pretty_trace x ; if not ( HM . mem rho x ) then ( new_var_event x ; HM . replace rho x ( S . Dom . bot ( ) ) ) in let set_start ( x , d ) = if tracing then trace " sol2 " " set_start % a ## % a \ n " S . Var . pretty_trace x S . Dom . pretty d ; init x ; HM . replace rho x d ; solve x Widen in start_event ( ) ; List . iter set_start st ; List . iter init vs ; List . iter ( fun x -> solve x Widen ) vs ; let rec solve_sidevs ( ) = let non_stable = List . filter ( neg ( HM . mem stable ) ) vs in if non_stable <> [ ] then ( List . iter ( fun x -> solve x Widen ) non_stable ; solve_sidevs ( ) ) in solve_sidevs ( ) ; stop_event ( ) ; HM . clear stable ; HM . clear infl ; HM . clear rho ' ; rho 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 err | Ctype . Tags ( l , l ' ) -> Location . print_error_cur_file ppf ; fprintf ppf " In this program , @ variant constructors @ ` % s and ` % s @ \ have the same hash value . @ Change one of them . " l l ' | Typecore . Error ( loc , err ) -> Location . print_error ppf loc ; Typecore . report_error ppf err | Typetexp . Error ( loc , err ) -> Location . print_error ppf loc ; Typetexp . report_error ppf err | Typedecl . Error ( loc , err ) -> Location . print_error ppf loc ; Typedecl . report_error ppf err | Typeclass . Error ( loc , err ) -> Location . print_error ppf loc ; Typeclass . report_error ppf err | Includemod . Error err -> Location . print_error_cur_file ppf ; Includemod . report_error ppf err | Typemod . Error ( loc , err ) -> Location . print_error ppf loc ; Typemod . report_error ppf err | Translcore . Error ( loc , err ) -> Location . print_error ppf loc ; Translcore . report_error ppf err | Translclass . Error ( loc , err ) -> Location . print_error ppf loc ; Translclass . report_error ppf err | Translmod . Error ( loc , err ) -> Location . print_error ppf loc ; Translmod . report_error ppf err | Compilenv . Error code -> Location . print_error_cur_file ppf ; Compilenv . report_error ppf code | Jitlink . Error err -> Location . print_error_cur_file ppf ; Jitlink . report_error ppf err | Findlib . No_such_package ( pkg , reason ) -> fprintf ppf " No such package : % s " pkg ; if reason <> " " then fprintf ppf " - % s " reason | Findlib . Package_loop pkg -> fprintf ppf " Package requires itself : % s " pkg | Sys_error msg -> Location . print_error_cur_file ppf ; fprintf ppf " I / O error : % s " msg | Warnings . Errors ( n ) -> Location . print_error_cur_file ppf ; fprintf ppf " Error - enabled warnings ( % d occurrences ) " n | x -> fprintf ppf " ] " ; @ raise x in fprintf ppf " [ @% a ] . " @@ report exn
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.