text stringlengths 12 786k |
|---|
let eval_class_path env path = eval_path Env . find_class_address env path |
module EvalPath = struct type valu = Obj . t exception Error let eval_address addr = try eval_address addr with _ -> raise Error let same_value v1 v2 = ( v1 == v2 ) end |
let max_printer_depth = ref 100 |
let max_printer_steps = ref 300 |
let print_untyped_exception ppf obj = ! print_out_value ppf ( Printer . outval_of_untyped_exception obj ) |
let outval_of_value env obj ty = Printer . outval_of_value ! max_printer_steps ! max_printer_depth ( fun _ _ _ -> None ) env obj ty |
let print_value env obj ppf ty = ! print_out_value ppf ( outval_of_value env obj ty ) |
type ( ' a , ' b ) gen_printer = ( ' a , ' b ) Genprintval . gen_printer = | Zero of ' b | Succ of ( ' a -> ( ' a , ' b ) gen_printer ) |
let parse_toplevel_phrase = ref Parse . toplevel_phrase |
let parse_use_file = ref Parse . use_file |
let parse_mod_use_file name lb = let modname = String . capitalize_ascii ( Filename . remove_extension ( Filename . basename name ) ) in let items = List . concat ( List . map ( function Ptop_def s -> s | Ptop_dir _ -> [ ] ) ( ! parse_use_file lb ) ) in [ Ptop_def [ Str . ... |
let toplevel_startup_hook = ref ( fun ( ) -> ( ) ) |
type event += | Startup | After_setup |
let hooks = ref [ ] |
let add_hook f = hooks := f :: ! hooks |
let ( ) = add_hook ( function | Startup -> ! toplevel_startup_hook ( ) | _ -> ( ) ) |
let run_hooks hook = List . iter ( fun f -> f hook ) ! hooks |
let phrase_seqid = ref 0 |
let phrase_name = ref " TOP " |
module Backend = struct let symbol_for_global ' = Compilenv . symbol_for_global ' let closure_symbol = Compilenv . closure_symbol let really_import_approx = Import_approx . really_import_approx let import_symbol = Import_approx . import_symbol let size_int = Arch . size_int let big_endian = Arch . ... |
let backend = ( module Backend : Backend_intf . S ) |
let default_load ppf ( program : Lambda . program ) = let dll = if ! Clflags . keep_asm_file then ! phrase_name ^ ext_dll else Filename . temp_file ( " caml " ^ ! phrase_name ) ext_dll in let filename = Filename . chop_extension dll in if Config . flambda2 then begin Asmgen . compile_im... |
let load_lambda ppf ~ module_ident ~ required_globals 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 slam ; let p... |
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 toplevel_env = ref Env . empty |
let print_out_exception ppf exn outv = ! print_out_phrase ppf ( Ophr_exception ( exn , outv ) ) |
let print_exception_outcome ppf exn = if exn = Out_of_memory then Gc . full_major ( ) ; let outv = outval_of_value ! toplevel_env ( Obj . repr exn ) Predef . type_exn in print_out_exception ppf exn outv |
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 name_expression ~ loc ~ attrs exp = let name = " _ " $ in let id = Ident . create_local name in let vd = { val_type = exp . exp_type ; val_kind = Val_reg ; val_loc = loc ; val_attributes = attrs ; val_uid = Uid . internal_not_actually_unique ; } in let sg = [ Sig_value ( id... |
let execute_phrase print_outcome ppf phr = match phr with | Ptop_def sstr -> let oldenv = ! toplevel_env in incr phrase_seqid ; phrase_name := Printf . sprintf " TOP % i " ! phrase_seqid ; Compilenv . reset ? packname : None ! phrase_name ; Typecore . reset_delayed_checks ( ) ; let ( ... |
let use_print_results = ref true |
let preprocess_phrase ppf phr = let phr = match phr with | Ptop_def str -> let str = Pparse . apply_rewriters_str ~ restore : true ~ tool_name " : ocaml " str in Ptop_def str | phr -> phr in if ! Clflags . dump_parsetree then Printast . top_phrase ppf phr ; if ! Clflags . dump_source then Ppr... |
let use_channel ppf ~ wrap_in_module ic name filename = let lb = Lexing . from_channel ic in Location . init lb filename ; Lexer . skip_hash_bang lb ; let success = protect_refs [ R ( Location . input_name , filename ) ] ( fun ( ) -> try List . iter ( fun ph -> let ph = preprocess... |
let use_output ppf command = let fn = Filename . temp_file " ocaml " " _toploop . ml " in Misc . try_finally ~ always ( : fun ( ) -> try Sys . remove fn with Sys_error _ -> ( ) ) ( fun ( ) -> match Printf . ksprintf Sys . command " % s > % s " command ( Filename .... |
let use_file ppf ~ wrap_in_module name = match name with | " " -> use_channel ppf ~ wrap_in_module stdin name " ( stdin ) " | _ -> match Load_path . find name with | filename -> let ic = open_in_bin filename in Misc . try_finally ~ always ( : fun ( ) -> close_in ic ) ( fun ( ) ... |
let mod_use_file ppf name = use_file ppf ~ wrap_in_module : true name |
let use_file ppf name = use_file ppf ~ wrap_in_module : false name |
let use_silently ppf name = protect_refs [ R ( use_print_results , false ) ] ( fun ( ) -> use_file ppf name ) |
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 ; incr i ; if c = ' \ n ' then raise Exit ; done ; ( ! i , false ) with | E... |
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 := ... |
let _ = Sys . interactive := true ; Compmisc . init_path ( ) ; Clflags . dlcode := true ; ( ) |
let find_ocamlinit ( ) = let ocamlinit = " . ocamlinit " in if Sys . file_exists ocamlinit then Some ocamlinit else let getenv var = match Sys . getenv var with | exception Not_found -> None | " " -> None | v -> Some v in let exists_in_dir dir file = match dir with | None -> None | Some d... |
let load_ocamlinit ppf = if ! Clflags . noinit then ( ) else match ! Clflags . init_file with | Some f -> if Sys . file_exists f then ignore ( use_silently ppf f ) else fprintf ppf " Init file not found : " \% s " . . " \@ f | None -> match find_ocamlinit ( ) with | None -> ( ... |
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... |
let initialize_toplevel_env ( ) = toplevel_env := Compmisc . initial_env ( ) |
let loop ppf = Location . formatter_for_warnings := ppf ; if not ! Clflags . noversion then fprintf ppf " OCaml version % s - native toplevel . . " @@ Config . version ; initialize_toplevel_env ( ) ; let lb = Lexing . from_function refill_lexbuf in Location . init lb " // toplevel ... |
let override_sys_argv new_argv = caml_sys_modify_argv new_argv ; Arg . current := 0 |
let run_script ppf name args = override_sys_argv args ; Compmisc . init_path ~ dir ( : Filename . dirname name ) ( ) ; toplevel_env := Compmisc . initial_env ( ) ; Sys . interactive := false ; run_hooks After_setup ; let explicit_name = if Filename . is_implicit name then Filename ... |
let usage = " Usage : ocamlnat < options > < object - files > [ script - file ] \ noptions are " : |
let preload_objects = ref [ ] |
let first_nonexpanded_pos = ref 0 |
let current = ref ( ! Arg . current ) |
let argv = ref Sys . argv |
let is_expanded pos = pos < ! first_nonexpanded_pos |
let expand_position pos len = if pos < ! first_nonexpanded_pos then first_nonexpanded_pos := ! first_nonexpanded_pos + len else first_nonexpanded_pos := pos + len + 2 |
let prepare ppf = Opttoploop . set_paths ( ) ; try let res = List . for_all ( Opttopdirs . load_file ppf ) ( List . rev ! preload_objects ) in Opttoploop . run_hooks Opttoploop . Startup ; res with x -> try Location . report_exception ppf x ; false with x -> Format . fprintf ppf "... |
let file_argument name = let ppf = Format . err_formatter in if Filename . check_suffix name " . cmxs " || Filename . check_suffix name " . cmx " || Filename . check_suffix name " . cmxa " then preload_objects := name :: ! preload_objects else if is_expanded ! current then begin Printf... |
let wrap_expand f s = let start = ! current in let arr = f s in expand_position start ( Array . length arr ) ; arr |
module Options = Flambda_backend_args . Make_opttop_options ( struct include Flambda_backend_args . Default . Opttopmain let _stdin ( ) = file_argument " " let _args = wrap_expand Arg . read_arg let _args0 = wrap_expand Arg . read_arg0 let anonymous s = file_argument s end ) ; ; |
let ( ) = let extra_paths = match Sys . getenv " OCAMLTOP_INCLUDE_PATH " with | exception Not_found -> [ ] | s -> Misc . split_path_contents s in Clflags . include_dirs := List . rev_append extra_paths ! Clflags . include_dirs |
let main ( ) = Clflags . native_code := true ; Clflags . Opt_flag_handler . set Flambda_backend_flags . opt_flag_handler ; let list = ref Options . list in begin try Arg . parse_and_expand_argv_dynamic current argv list file_argument usage ; with | Arg . Bad msg -> Format . fprintf Format... |
let main ( ) = match main ( ) with | exception Exit_with_status n -> n | ( ) -> 0 |
module M : sig val x : int val y : int val z : int let f ( ) = let g ( ) = 42 in g , g let x = let _ = f in let f , _ = f ( ) in f ( ) external getenv : string -> string = " caml_sys_getenv " let y = match match getenv " foo " with _ -> Some 1 | exception _ -> Some 2 w... |
let ( ) = assert ( Sys . getenv_opt " FOOBAR_UNLIKELY_TO_EXIST_42 " = None ) ; assert ( int_of_string_opt " foo " = None ) ; assert ( int_of_string_opt " 42 " = Some 42 ) ; assert ( int_of_string_opt ( String . make 100 ' 9 ' ) = None ) ; assert ( Nativeint... |
type ordering = Greater | Equal | NotGE |
let ge_ord order pair = match order pair with NotGE -> false | _ -> true |
let rec rem_eq equiv x = function [ ] -> failwith " rem_eq " | y :: l -> if equiv ( x , y ) then l else y :: rem_eq equiv x l |
let diff_eq equiv ( x , y ) = let rec diffrec = function ( [ ] , _ ) as p -> p | ( h :: t , y ) -> try diffrec ( t , rem_eq equiv h y ) with Failure _ -> let ( x ' , y ' ) = diffrec ( t , y ) in ( h :: x ' , y ' ) in if List . length x > List . lengt... |
let mult_ext order = function Term ( _ , sons1 ) , Term ( _ , sons2 ) -> begin match diff_eq ( eq_ord order ) ( sons1 , sons2 ) with ( [ ] , [ ] ) -> Equal | ( l1 , l2 ) -> if List . for_all ( fun n -> List . exists ( fun m -> gt_ord order ( m , n ) ) ... |
let lex_ext order = function ( Term ( _ , sons1 ) as m ) , ( Term ( _ , sons2 ) as n ) -> let rec lexrec = function ( [ ] , [ ] ) -> Equal | ( [ ] , _ ) -> NotGE | ( _ , [ ] ) -> Greater | ( x1 :: l1 , x2 :: l2 ) -> match order ( x1 , x2 ... |
let rpo op_order ext = let rec rporec ( m , n ) = if m = n then Equal else match m with Var vm -> NotGE | Term ( op1 , sons1 ) -> match n with Var vn -> if occurs vn m then Greater else NotGE | Term ( op2 , sons2 ) -> match ( op_order op1 op2 ) with Greater -> if List . for_all ( fun... |
type ' a t = | Ok of ' a | Bottom |
let print f ppf t = match t with | Ok contents -> Format . fprintf ppf " [ ( @ Ok % a ) ] " @ f contents | Bottom -> Format . pp_print_string ppf " Bottom " |
let both t1 t2 ~ f = match t1 , t2 with | Ok contents1 , Ok contents2 -> Ok ( f contents1 contents2 ) | Bottom , _ | _ , Bottom -> Bottom |
let map t ~ f = match t with Ok contents -> Ok ( f contents ) | Bottom -> Bottom |
let value_map t ~ bottom ~ f = match t with Ok contents -> f contents | Bottom -> bottom |
let all ts = let contents = List . filter_map ( fun t -> match t with Ok contents -> Some contents | Bottom -> None ) ts in if List . compare_lengths ts contents <> 0 then Bottom else Ok contents |
let bind t ~ f = match t with Bottom -> Bottom | Ok contents -> f contents |
module Let_syntax = struct let ( let <* ) x f = bind x ~ f let ( let <+ ) x f = map x ~ f end |
type ' a t = | Known of ' a | Unknown |
let print f ppf t = let colour = Flambda_colours . top_or_bottom_type ( ) in match t with | Known contents -> Format . fprintf ppf " % a " f contents | Unknown -> if Flambda_features . unicode ( ) then Format . fprintf ppf " % s @< 1 >\ u { 22a4 } % s " colour ( Flambda_colour... |
let compare compare_contents t1 t2 = match t1 , t2 with | Unknown , Unknown -> 0 | Known contents1 , Known contents2 -> compare_contents contents1 contents2 | Unknown , Known _ -> - 1 | Known _ , Unknown -> 1 |
let equal equal_contents t1 t2 = match t1 , t2 with | Unknown , Unknown -> true | Known contents1 , Known contents2 -> equal_contents contents1 contents2 | Unknown , Known _ | Known _ , Unknown -> false |
let bind t ~ f = match t with Known contents -> f contents | Unknown -> Unknown |
let map t ~ f = match t with Known contents -> Known ( f contents ) | Unknown -> Unknown |
let map_sharing t ~ f = match t with | Known contents -> let contents ' = f contents in if contents == contents ' then t else Known contents ' | Unknown -> Unknown |
let free_names free_names_contents t = match t with | Known contents -> free_names_contents contents | Unknown -> Name_occurrences . empty |
let all_ids_for_export all_ids_for_export_contents t = match t with | Known contents -> all_ids_for_export_contents contents | Unknown -> Ids_for_export . empty |
let apply_renaming t renaming rename_contents = match t with | Known contents -> Known ( rename_contents contents renaming ) | Unknown -> Unknown |
module Lift ( I : Container_types . S ) = struct type nonrec t = I . t t include Container_types . Make ( struct type nonrec t = t let print ppf t = print I . print ppf t let compare t1 t2 = compare I . compare t1 t2 let equal t1 t2 = equal I . equal t1 t2 let hash t = match t with | Unknown ... |
module Let_syntax = struct let ( let >* ) x f = bind x ~ f let ( let >+ ) x f = map x ~ f let ( let >+$ ) x f = map_sharing x ~ f end |
type ' a t = | Unknown | Ok of ' a | Bottom |
let print f ppf t = match t with | Unknown -> Format . pp_print_string ppf " Unknown " | Ok contents -> Format . fprintf ppf " [ ( @ Ok % a ) ] " @ f contents | Bottom -> Format . pp_print_string ppf " Bottom " |
let equal eq_contents t1 t2 = match t1 , t2 with | Unknown , Unknown -> true | Ok contents1 , Ok contents2 -> eq_contents contents1 contents2 | Bottom , Bottom -> true | ( Unknown | Ok _ | Bottom ) , _ -> false |
let bind t ~ f = match t with | Unknown -> Unknown | Bottom -> Bottom | Ok contents -> f contents |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.