text
stringlengths
12
786k
let hg_describe ~ dirty r ~ rev = let get_distance s = try Ok ( int_of_string s ) s with | Failure _ -> R . error_msgf " % s : Could not parse hg tag distance . " ( dir r ) r in let parent t = run_hg r Topkg_cmd ( . v " parent " % " -- rev " % rev % " -- template " % t ) t Topkg...
let hg_tags r = run_hg r Topkg_cmd ( . v " tags " % " -- quiet " ) Topkg_os . Cmd . out_lines
let hg_changes r ~ after ~ until = let rev = Topkg_string . strf " % s ::% s " after until in let changes = Topkg_cmd ( . v " log " % " -- template " % { " node | short } short { desc | firstline } firstline \\ n " % " -- rev " % rev ) rev in run_hg r changes Topkg_os . Cmd ...
let hg_tracked_files r ~ rev = run_hg r Topkg_cmd ( . v " manifest " % " -- rev " % rev ) rev Topkg_os . Cmd . out_lines
let hg_clone r ~ dir : d = let clone = Topkg_cmd ( . v " clone " % ( dir r ) r % d ) d in run_hg r clone Topkg_os . Cmd . out_stdout
let hg_checkout r ~ branch ~ rev = run_hg r Topkg_cmd ( . v " update " % " -- rev " % rev ) rev Topkg_os . Cmd . out_string >>= fun _ -> match branch with | None -> Ok ( ) | Some branch -> run_hg r Topkg_cmd ( . v " branch " % branch ) branch Topkg_os . Cmd . out_string >>= fu...
let hg_commit_files r ~ msg files = let msg = match msg with | None -> Topkg_cmd . empty | Some m -> Topkg_cmd ( . v " - m " % m ) m in let files = Topkg_cmd ( . of_list @@ List . map p files ) files in run_hg r Topkg_cmd ( . v " commit " %% msg %% files ) files Topkg_os . Cmd . o...
let hg_tag r ~ force ~ sign ~ msg ~ rev tag = if sign then R . error_msgf " Tag signing is not supported by hg " else let msg = match msg with | None -> Topkg_cmd . empty | Some m -> Topkg_cmd ( . v " - m " % m ) m in run_hg r Topkg_cmd ( . v " tag " %% on force ( v " - f ) " ...
let hg_delete_tag r tag = run_hg r Topkg_cmd ( . v " tag " % " -- remove " % tag ) tag Topkg_os . Cmd . out_stdout
let find ? dir ( ) = match dir with begin find_git ( ) >>= function | Some _ as v -> Ok v | None -> find_hg ( ) end let git_dir = Topkg_fpath . append dir " . git " in Topkg_os . Dir . exists git_dir >>= function | true -> begin Lazy . force git >>= function | ( _ , cmd ) cmd ->...
let get ? dir ( ) = find ? dir ( ) >>= function let dir = match dir with | None -> Topkg_os . Dir . current ( ) | Some dir -> Ok dir in dir >>= function dir -> R . error_msgf " % s : No VCS repository found " dir
let pp ppf r = Format . fprintf ppf ( " % a , % s ) s " pp_kind ( kind r ) r ( dir r ) r
let not_dirty r = is_dirty r >>= function
let file_is_dirty r file = match r with
let head ( ? dirty = true ) true = function
let commit_id ( ? dirty = true ) true ( ? commit_ish = " HEAD ) " = function
let commit_ptime_s ( ? commit_ish = " HEAD ) " = function
let describe ( ? dirty = true ) true ( ? commit_ish = " HEAD ) " = function
let changes ( ? until = " HEAD ) " r ~ after = match r with
let tracked_files ( ? tree_ish = " HEAD ) " = function
let clone r ~ dir = match r with
let checkout ? branch r ~ commit_ish = match r with
let commit_files ? msg r files = match r with
let tag ( ? force = false ) false ( ? sign = false ) false ? msg ( ? commit_ish = " HEAD ) " r tag = match r with | ( ` Git , _ , _ as r ) r -> git_tag r ~ force ~ sign ~ msg ~ commit_ish tag | ( ` Hg , _ , _ as r ) r -> hg_tag r ~ force ~ sign ~ msg ~ rev ( ...
let delete_tag r tag = match r with
let init top = let module O = Options in top # init ~ nopervasives :! O . nopervasives ~ pkgs :! O . findlib_pkgs ~ use_threads ( : Std . Various . use_threads ( ) ) ~ cma_files :! O . cma_files ( )
let set_absname x = Clflags . absname := x # else Location . absname := x # endif
let serialize_location_error x = let main = x . Location . main in let b = Buffer . create 128 in let fmt = Format . formatter_of_buffer b in Format . fprintf fmt " [ @% t ] " @ main . Location . txt ; Format . pp_print_flush fmt ( ) ; ( main . Location . loc , Buffer . ...
let set_argv new_argv = caml_sys_modify_argv new_argv ; # else let orig_argv_length = Array . length Sys . argv in let new_argv_length = Array . length new_argv in assert ( new_argv_length <= orig_argv_length ) ; ArrayLabels . blit ~ src : new_argv ~ src_pos : 0 ~ dst : Sys . argv ~ dst_p...
let run_main in_channel ~ the_fpm ~ the_execution_engine = let anonymous_func_count = ref 0 in let supplier = Parser . MenhirInterpreter . lexer_lexbuf_to_supplier Lexer . read ( Lexing . from_channel in_channel ) in let rec run_loop the_fpm the_execution_engine supplier = let incremental = Parser ....
let main input = Hashtbl . add_exn Ast . binop_precedence ~ key ' ' := ~ data : 2 ; Hashtbl . add_exn Ast . binop_precedence ~ key ' ' :< ~ data : 10 ; Hashtbl . add_exn Ast . binop_precedence ~ key ' ' :+ ~ data : 20 ; Hashtbl . add_exn Ast . binop_precedence ~ key ' ...
module Make ( P : sig val np : int val mem : int end ) ( ) = struct open P let with_workflow w ~ f = let open Scheduler in let db = Db . init_exn " _bistro " in let loggers = [ Console_logger . create ( ) ] in let sched = create ~ np : np ~ mem ( ` : GB mem ) ~ loggers db in...
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 phrase_buffer = Buffer . create 1024
let toplevel_value_bindings : Obj . t String . Map . t ref = ref String . Map . empty
let getvalue name = try String . Map . find name ! toplevel_value_bindings with Not_found -> fatal_error ( name ^ " unbound at toplevel " )
let setvalue name v = toplevel_value_bindings := String . Map . add name v ! toplevel_value_bindings
let rec eval_address = function | Env . Aident id -> if Ident . persistent id || Ident . global id then Symtable . get_global_value id else begin let name = Translmod . toplevel_name id in try String . Map . find name ! toplevel_value_bindings with Not_found -> raise ( Symtable . Error ( Symt...
let eval_path find env path = match find path env with | addr -> eval_address addr | exception Not_found -> fatal_error ( " Cannot find address for : " ^ ( Path . name path ) )
let eval_module_path env path = eval_path Env . find_module_address env path
let eval_value_path env path = eval_path Env . find_value_address env path
let eval_extension_path env path = eval_path Env . find_constructor_address env path
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 Symtable . Error _ -> 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 may_trace = ref false
type evaluation_outcome = Result of Obj . t | Exception of exn
let backtrace = ref None
let record_backtrace ( ) = if Printexc . backtrace_status ( ) then backtrace := Some ( Printexc . get_backtrace ( ) )
let load_lambda ppf lam = 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 ( init_code , fun_code ) = Bytegen ...
let pr_item = Printtyp . print_items ( fun env -> function | Sig_value ( id , { val_kind = Val_reg ; val_type } , _ ) -> Some ( outval_of_value env ( getvalue ( Translmod . toplevel_name 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 ; if Printexc . backtrace_status ( ) then match ! backtrace with | None -> ( ) | ...
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 execute_phrase print_outcome ppf phr = match phr with | Ptop_def sstr -> let oldenv = ! toplevel_env in Typecore . reset_delayed_checks ( ) ; let ( str , sg , sn , newenv ) = Typemod . type_toplevel_phrase oldenv sstr in if ! Clflags . dump_typedtree then Printtyped . implementation p...
let execute_phrase print_outcome ppf phr = try execute_phrase print_outcome ppf phr with exn -> Warnings . reset_fatal ( ) ; raise exn
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_file ppf wrap_mod name = try let ( filename , ic , must_close ) = if name = " " then ( " ( stdin ) " , stdin , false ) else begin let filename = Load_path . find name in let ic = open_in_bin filename in ( filename , ic , true ) end in let lb = Lexing . from_channel ...
let mod_use_file ppf name = use_file ppf true name
let use_file ppf name = use_file ppf 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 ; Buffer . add_char phrase_buffer c ; incr i ; if c = ' \ n ' then raise Exit ; d...
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 _ = if ! Sys . interactive then invalid_arg " The ocamltoplevel . cma library from compiler - libs \ cannot be loaded inside the OCaml toplevel " ; Sys . interactive := true ; let crc_intfs = Symtable . init_toplevel ( ) in Compmisc . init_path ( ) ; Env . import_crcs ~ source ...
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 = Clflags . debug := true ; Location . formatter_for_warnings := ppf ; if not ! Clflags . noversion then fprintf ppf " OCaml version % s . . " @@ Config . version ; begin try initialize_toplevel_env ( ) with Env . Error _ | Typetexp . Error _ as exn -> Location . r...
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 ) ( ) ; begin try toplevel_env := Compmisc . initial_env ( ) with Env . Error _ | Typetexp . Error _ as exn -> Location . report_exception ppf exn ; exit 2 end ; Sys . ...
module Ppx = struct let ppx_rewriters = ref [ ] let ( ) = Ast_mapper . register_function := ( fun _ f -> ppx_rewriters := f :: ! ppx_rewriters ) let preprocess_structure str = let open Ast_mapper in List . fold_right ( fun ppx_rewriter str -> let mapper = ppx_rewriter [ ] in mapper . ...
let warnings = ref [ ]
let ( ) = Location . warning_reporter := ( fun loc w -> match Warnings . report w with | ` Inactive -> None | ` Active { Warnings . id = _ ; message ; is_error = _ ; sub_locs } -> let r = ( loc , message ) , sub_locs in warnings := r :: ! warnings ; None )
let return_success ( e : ' a ) : ' a toplevel_result = Ok ( e , ! warnings )
let return_error e : ' a toplevel_result = Error ( e , ! warnings )
let error_of_exn exn = match Location . error_of_exn exn with | None | Some ` Already_displayed -> let msg = match exn with | Failure msg -> msg | exn -> Printexc . to_string exn in let main = { Location . txt = ( fun fmt -> Format . pp_print_text fmt msg ) ; loc = Location . none } i...
let return_exn exn = return_error ( of_report ( error_of_exn exn ) )