text
stringlengths
0
601k
let rec list_rev_iter f = function | [ ] -> ( ) | x :: xs -> list_rev_iter f xs ; f x
let flatten_commands quiet pretend cmd = let rec loop acc = function | [ ] -> acc | Nop :: xs -> loop acc xs | Cmd spec :: xs -> loop ( string_print_of_command_spec spec quiet pretend :: acc ) xs | Echo ( texts , dest_path ) :: xs -> loop ( Primitives . echo texts dest_path :: acc ) xs | Seq l :: xs -> loop ( loop acc ...
let execute_many ( ? quiet = false ) ( ? pretend = false ) cmds = add_parallel_stat ( List . length cmds ) ; let degraded = !* My_unix . is_degraded || Sys . os_type = " Win32 " in let jobs = ! jobs in if jobs < 0 then invalid_arg " jobs < 0 " ; let max_jobs = if jobs = 0 then None else Some jobs in let ticker = Log . ...
let execute ? quiet ? pretend cmd = match execute_many ? quiet ? pretend [ cmd ] with | Some ( _ , exn ) -> raise exn | _ -> ( )
let iter_tags f x = let rec spec x = match x with | N | A _ | Sh _ | P _ | Px _ | V _ | Quote _ -> ( ) | S l -> List . iter spec l | T tags -> f tags in let rec cmd x = match x with | Nop | Echo _ -> ( ) | Cmd ( s ) -> spec s | Seq ( s ) -> List . iter cmd s in cmd x
let fold_pathnames f x = let rec spec = function | N | A _ | Sh _ | V _ | Quote _ | T _ -> fun acc -> acc | P p | Px p -> f p | S l -> List . fold_right spec l in let rec cmd = function | Nop -> fun acc -> acc | Echo ( _ , p ) -> f p | Cmd ( s ) -> spec s | Seq ( s ) -> List . fold_right cmd s in cmd x
let rec reduce x = let rec self x acc = match x with | N -> acc | A _ | Sh _ | P _ | Px _ | V _ -> x :: acc | S l -> List . fold_right self l acc | T tags -> self ( ! tag_handler tags ) acc | Quote s -> Quote ( reduce s ) :: acc in match self x [ ] with | [ ] -> N | [ x ] -> x | xs -> S xs
let digest = let list = List . fold_right in let text x acc = Digest . string x :: acc in let rec cmd = function | Cmd spec -> fun acc -> string_of_command_spec spec :: acc | Seq seq -> list cmd seq | Nop -> fun acc -> acc | Echo ( texts , dest_path ) -> list text ( dest_path :: texts ) in fun x -> match cmd x [ ] with...
let all_deps_of_tags = ref [ ]
let cons deps acc = List . rev & List . fold_left begin fun acc dep -> if List . mem dep acc then acc else dep :: acc end acc deps
let deps_of_tags tags = List . fold_left begin fun acc ( xtags , xdeps ) -> if Tags . does_match tags xtags then cons xdeps acc else acc end [ ] ! all_deps_of_tags
let set_deps_of_tags tags deps = all_deps_of_tags := ( tags , deps ) :: ! all_deps_of_tags
let dep tags deps = set_deps_of_tags ( Tags . of_list tags ) deps
let pdep tags ptag deps = Param_tags . declare ptag ( fun param -> dep ( Param_tags . make ptag param :: tags ) ( deps param ) ) | S specs1 :: specs2 -> cmd_of_spec ( specs1 @ specs2 ) | ( T _ | Quote _ ) :: _ -> assert false in let rec cmd_of_cmds = function | Nop | Seq [ ] -> None | Cmd spec -> cmd_of_spec [ spec ] |...
type dbg_instruction = { instr_name : string ; instr_prio : bool ; instr_action : formatter -> lexbuf -> unit ; instr_repeat : bool ; instr_help : string }
let instruction_list = ref ( [ ] : dbg_instruction list )
type dbg_variable = { var_name : string ; var_action : ( lexbuf -> unit ) * ( formatter -> unit ) ; var_help : string }
let variable_list = ref ( [ ] : dbg_variable list )
type dbg_info = { info_name : string ; info_action : lexbuf -> unit ; info_help : string }
let info_list = ref ( [ ] : dbg_info list )
let error text = eprintf " % s . " @ text ; raise Toplevel
let check_not_windows feature = match Sys . os_type with | " Win32 " -> error ( " ' " \^ feature " ' ^\ feature not supported on Windows " ) | _ -> ( )
let eol = end_of_line Lexer . lexeme
let matching_elements list name instr = List . filter ( function a -> isprefix instr ( name a ) ) ! list
let all_matching_instructions = matching_elements instruction_list ( fun i -> i . instr_name )
let matching_instructions instr = let all = all_matching_instructions instr in let prio = List . filter ( fun i -> i . instr_prio ) all in if prio = [ ] then all else prio
let matching_variables = matching_elements variable_list ( fun v -> v . var_name )
let matching_infos = matching_elements info_list ( fun i -> i . info_name )
let find_ident name matcher action alternative ppf lexbuf = match identifier_or_eol Lexer . lexeme lexbuf with | None -> alternative ppf | Some ident -> match matcher ident with | [ ] -> error ( " Unknown " ^ name ^ " . " ) | [ a ] -> action a ppf lexbuf | _ -> error ( " Ambiguous " ^ name ^ " . " )
let find_variable action alternative ppf lexbuf = find_ident " variable name " matching_variables action alternative ppf lexbuf
let find_info action alternative ppf lexbuf = find_ident " info command " matching_infos action alternative ppf lexbuf
let add_breakpoint_at_pc pc = try new_breakpoint ( any_event_at_pc pc ) with | Not_found -> eprintf " Can ' \ t add breakpoint at pc % i :% i : no event there . . " @ pc . frag pc . pos ; raise Toplevel
let add_breakpoint_after_pc pc = let rec try_add n = if n < 3 then begin try new_breakpoint ( any_event_at_pc { pc with pos = pc . pos + n * 4 } ) with | Not_found -> try_add ( n + 1 ) end else begin error " Can ' \ t add breakpoint at beginning of function : no event there " end in try_add 0
let module_of_longident id = match id with | Some x -> Some ( String . concat " . " ( Longident . flatten x ) ) | None -> None
let convert_module mdle = match mdle with | Some m -> String . capitalize_ascii ( if Filename . check_suffix m " . ml " then Filename . chop_suffix m " . ml " else m ) | None -> try ( get_current_event ( ) ) . ev_ev . ev_module with Not_found -> error " Not in a module . "
let current_line = ref " "
let interprete_line ppf line = current_line := line ; let lexbuf = Lexing . from_string line in try match identifier_or_eol Lexer . lexeme lexbuf with | Some x -> begin match matching_instructions x with | [ ] -> error " Unknown command . " | [ i ] -> i . instr_action ppf lexbuf ; resume_user_input ( ) ; i . instr_repe...
let line_loop ppf line_buffer = resume_user_input ( ) ; let previous_line = ref " " in try while true do if ! loaded then History . add_current_time ( ) ; let new_line = string_trim ( line line_buffer ) in let line = if new_line <> " " then new_line else ! previous_line in previous_line := " " ; if interprete_line ppf ...
let instr_cd _ppf lexbuf = let dir = argument_eol argument lexbuf in if ask_kill_program ( ) then try Sys . chdir ( expand_path dir ) with | Sys_error s -> error s
let instr_shell _ppf lexbuf = let cmdarg = argument_list_eol argument lexbuf in let cmd = String . concat " " cmdarg in let err = Sys . command cmd in if ( err != 0 ) then eprintf " Shell command % S failed with exit code % d \ n " %! cmd err
let instr_env _ppf lexbuf = let cmdarg = argument_list_eol argument lexbuf in let cmdarg = string_trim ( String . concat " " cmdarg ) in if cmdarg <> " " then if ask_kill_program ( ) then begin try let eqpos = String . index cmdarg ' ' = in if eqpos = 0 then raise Not_found ; let name = String . sub cmdarg 0 eqpos in l...
let instr_pwd ppf lexbuf = eol lexbuf ; fprintf ppf " % s . " @ ( Sys . getcwd ( ) )
let instr_dir ppf lexbuf = let new_directory = argument_list_eol argument lexbuf in if new_directory = [ ] then begin if yes_or_no " Reinitialize directory list " then begin Load_path . init ! default_load_path ; Envaux . reset_cache ~ preserve_persistent_env : false ; Hashtbl . clear Debugger_config . load_path_for ; ...
let instr_kill _ppf lexbuf = eol lexbuf ; if not ! loaded then error " The program is not being run . " ; if ( yes_or_no " Kill the program being debugged " ) then begin kill_program ( ) ; show_no_point ( ) end
let instr_pid ppf lexbuf = eol lexbuf ; if not ! loaded then error " The program is not being run . " ; fprintf ppf " [ @% d ] . " @@ ! current_checkpoint . c_pid
let instr_run ppf lexbuf = eol lexbuf ; ensure_loaded ( ) ; reset_named_values ( ) ; run ( ) ; show_current_event ppf
let instr_reverse ppf lexbuf = eol lexbuf ; check_not_windows " reverse " ; ensure_loaded ( ) ; reset_named_values ( ) ; back_run ( ) ; show_current_event ppf
let instr_step ppf lexbuf = let step_count = match opt_signed_int64_eol Lexer . lexeme lexbuf with | None -> _1 | Some x -> x in ensure_loaded ( ) ; reset_named_values ( ) ; step step_count ; show_current_event ppf
let instr_back ppf lexbuf = let step_count = match opt_signed_int64_eol Lexer . lexeme lexbuf with | None -> _1 | Some x -> x in check_not_windows " backstep " ; ensure_loaded ( ) ; reset_named_values ( ) ; step ( _0 -- step_count ) ; show_current_event ppf
let instr_finish ppf lexbuf = eol lexbuf ; ensure_loaded ( ) ; reset_named_values ( ) ; finish ( ) ; show_current_event ppf
let instr_next ppf lexbuf = let step_count = match opt_integer_eol Lexer . lexeme lexbuf with | None -> 1 | Some x -> x in ensure_loaded ( ) ; reset_named_values ( ) ; next step_count ; show_current_event ppf
let instr_start ppf lexbuf = eol lexbuf ; check_not_windows " start " ; ensure_loaded ( ) ; reset_named_values ( ) ; start ( ) ; show_current_event ppf
let instr_previous ppf lexbuf = let step_count = match opt_integer_eol Lexer . lexeme lexbuf with | None -> 1 | Some x -> x in check_not_windows " previous " ; ensure_loaded ( ) ; reset_named_values ( ) ; previous step_count ; show_current_event ppf
let instr_goto ppf lexbuf = let time = int64_eol Lexer . lexeme lexbuf in ensure_loaded ( ) ; reset_named_values ( ) ; go_to time ; show_current_event ppf
let instr_quit _ = raise Exit
let print_variable_list ppf = let pr_vars ppf = List . iter ( fun v -> fprintf ppf " % s @ " v . var_name ) in fprintf ppf " List of variables : % a . " @ pr_vars ! variable_list
let print_info_list ppf = let pr_infos ppf = List . iter ( fun i -> fprintf ppf " % s @ " i . info_name ) in fprintf ppf " List of info commands : % a . " @ pr_infos ! info_list
let instr_complete _ppf lexbuf = let ppf = Format . err_formatter in let rec print_list l = try eol lexbuf ; List . iter ( function i -> fprintf ppf " % s . " @ i ) l with _ -> remove_file ! user_channel and match_list lexbuf = match identifier_or_eol Lexer . lexeme lexbuf with | None -> List . map ( fun i -> i . instr...
let instr_help ppf lexbuf = let pr_instrs ppf = List . iter ( fun i -> fprintf ppf " % s @ " i . instr_name ) in match identifier_or_eol Lexer . lexeme lexbuf with | Some x -> let print_help nm hlp = eol lexbuf ; fprintf ppf " % s : % s . " @ nm hlp in begin match matching_instructions x with | [ ] -> eol lexbuf ; fpri...
let print_expr depth ev env ppf expr = try let ( v , ty ) = Eval . expression ev env expr in print_named_value depth expr env v ppf ty with | Eval . Error msg -> Eval . report_error ppf msg ; raise Toplevel
let env_of_event = function None -> Env . empty | Some ev -> Envaux . env_from_summary ev . ev_ev . ev_typenv ev . ev_ev . ev_typsubst
let print_command depth ppf lexbuf = let exprs = expression_list_eol Lexer . lexeme lexbuf in ensure_loaded ( ) ; let env = try env_of_event ! selected_event with | Envaux . Error msg -> Envaux . report_error ppf msg ; raise Toplevel in List . iter ( print_expr depth ! selected_event env ppf ) exprs
let instr_print ppf lexbuf = print_command ! max_printer_depth ppf lexbuf
let instr_display ppf lexbuf = print_command 1 ppf lexbuf
let instr_address ppf lexbuf = let exprs = expression_list_eol Lexer . lexeme lexbuf in ensure_loaded ( ) ; let env = try env_of_event ! selected_event with | Envaux . Error msg -> Envaux . report_error ppf msg ; raise Toplevel in let print_addr expr = let ( v , _ty ) = try Eval . expression ! selected_event env expr w...
let extract_filename arg = let l = String . length arg in let pos1 = if l > 0 && arg . [ 0 ] = ' " ' \ then 1 else 0 in let pos2 = if l > 0 && arg . [ l - 1 ] = ' " ' \ then l - 1 else l in String . sub arg pos1 ( pos2 - pos1 )
let instr_source ppf lexbuf = let file = extract_filename ( argument_eol argument lexbuf ) and old_state = ! interactif and old_channel = ! user_channel in let io_chan = try io_channel_of_descr ( openfile ( Load_path . find ( expand_path file ) ) [ O_RDONLY ] 0 ) with | Not_found -> error " Source file not found . " | ...
let instr_set = find_variable ( fun { var_action = ( funct , _ ) } _ppf lexbuf -> funct lexbuf ) ( function _ppf -> error " Argument required . " )
let instr_show = find_variable ( fun { var_action = ( _ , funct ) } ppf lexbuf -> eol lexbuf ; funct ppf ) ( function ppf -> List . iter ( function { var_name = nm ; var_action = ( _ , funct ) } -> fprintf ppf " % s : " nm ; funct ppf ) ! variable_list )
let instr_info = find_info ( fun i _ppf lexbuf -> i . info_action lexbuf ) ( function _ppf -> error " " \ info " \ must be followed by the name of an info command . " )
let instr_break ppf lexbuf = let argument = break_argument_eol Lexer . lexeme lexbuf in ensure_loaded ( ) ; match argument with | BA_none -> ( match ! selected_event with | Some ev -> new_breakpoint ev | None -> error " Can ' \ t add breakpoint at this point . " ) | BA_pc { frag ; pos } -> add_breakpoint_at_pc { frag ;...
let instr_delete _ppf lexbuf = match integer_list_eol Lexer . lexeme lexbuf with | [ ] -> if breakpoints_count ( ) <> 0 && yes_or_no " Delete all breakpoints " then remove_all_breakpoints ( ) | breakpoints -> List . iter ( function x -> try remove_breakpoint x with | Not_found -> ( ) ) breakpoints
let instr_frame ppf lexbuf = let frame_number = match opt_integer_eol Lexer . lexeme lexbuf with | None -> ! current_frame | Some x -> x in ensure_loaded ( ) ; try select_frame frame_number ; show_current_frame ppf true with | Not_found -> error ( " No frame number " ^ Int . to_string frame_number ^ " . " )
let instr_backtrace ppf lexbuf = let number = match opt_signed_integer_eol Lexer . lexeme lexbuf with | None -> 0 | Some x -> x in ensure_loaded ( ) ; match current_report ( ) with | None | Some { rep_type = Exited | Uncaught_exc | Code_loaded _ } -> ( ) | Some _ -> let frame_counter = ref 0 in let print_frame first_fr...
let instr_up ppf lexbuf = let offset = match opt_signed_integer_eol Lexer . lexeme lexbuf with | None -> 1 | Some x -> x in ensure_loaded ( ) ; try select_frame ( ! current_frame + offset ) ; show_current_frame ppf true with | Not_found -> error " No such frame . "
let instr_down ppf lexbuf = let offset = match opt_signed_integer_eol Lexer . lexeme lexbuf with | None -> 1 | Some x -> x in ensure_loaded ( ) ; try select_frame ( ! current_frame - offset ) ; show_current_frame ppf true with | Not_found -> error " No such frame . "
let instr_last ppf lexbuf = let count = match opt_signed_int64_eol Lexer . lexeme lexbuf with | None -> _1 | Some x -> x in check_not_windows " last " ; reset_named_values ( ) ; go_to ( History . previous_time count ) ; show_current_event ppf
let instr_list _ppf lexbuf = let ( mo , beg , e ) = list_arguments_eol Lexer . lexeme lexbuf in let ( curr_mod , line , column ) = try selected_point ( ) with | Not_found -> ( " " , - 1 , - 1 ) in let mdle = match mo with | None -> curr_mod | _ -> convert_module ( module_of_longident mo ) in let pos = Lexing . dummy_po...
let raw_variable kill name = ( function lexbuf -> let argument = argument_eol argument lexbuf in if ( not kill ) || ask_kill_program ( ) then name := argument ) , function ppf -> fprintf ppf " % s . " @ ! name
let raw_line_variable kill name = ( function lexbuf -> let argument = argument_eol line_argument lexbuf in if ( not kill ) || ask_kill_program ( ) then name := argument ) , function ppf -> fprintf ppf " % s . " @ ! name
let integer_variable kill min msg name = ( function lexbuf -> let argument = integer_eol Lexer . lexeme lexbuf in if argument < min then print_endline msg else if ( not kill ) || ask_kill_program ( ) then name := argument ) , function ppf -> fprintf ppf " % i . " @ ! name
let int64_variable kill min msg name = ( function lexbuf -> let argument = int64_eol Lexer . lexeme lexbuf in if argument < min then print_endline msg else if ( not kill ) || ask_kill_program ( ) then name := argument ) , function ppf -> fprintf ppf " % Li . " @ ! name
let boolean_variable kill name = ( function lexbuf -> let argument = match identifier_eol Lexer . lexeme lexbuf with | " on " -> true | " of " | " off " -> false | _ -> error " Syntax error . " in if ( not kill ) || ask_kill_program ( ) then name := argument ) , function ppf -> fprintf ppf " % s . " @ ( if ! name then ...
let path_variable kill name = ( function lexbuf -> let argument = argument_eol argument lexbuf in if ( not kill ) || ask_kill_program ( ) then name := make_absolute ( expand_path argument ) ) , function ppf -> fprintf ppf " % s . " @ ! name
let loading_mode_variable ppf = ( find_ident " loading mode " ( matching_elements ( ref loading_modes ) fst ) ( fun ( _ , mode ) _ppf lexbuf -> eol lexbuf ; set_launching_function mode ) ( function _ppf -> error " Syntax error . " ) ppf ) , function ppf -> let rec find = function | [ ] -> ( ) | ( name , funct ) :: l ->...
let follow_fork_variable = ( function lexbuf -> let mode = match identifier_eol Lexer . lexeme lexbuf with | " child " -> Fork_child | " parent " -> Fork_parent | _ -> error " Syntax error . " in fork_mode := mode ; if ! loaded then update_follow_fork_mode ( ) ) , function ppf -> fprintf ppf " % s . " @ ( match ! fork_...
let pr_modules ppf mods = let pr_mods ppf = List . iter ( function x -> fprintf ppf " % s @ " x ) in fprintf ppf " Used modules : . @% a " @? pr_mods mods
let info_modules ppf lexbuf = eol lexbuf ; ensure_loaded ( ) ; pr_modules ppf ! modules
let info_checkpoints ppf lexbuf = eol lexbuf ; if ! checkpoints = [ ] then fprintf ppf " No checkpoint . . " @ else ( if ! debug_breakpoints then ( prerr_endline " Time Pid Version " ; List . iter ( function { c_time = time ; c_pid = pid ; c_breakpoint_version = version } -> Printf . printf " % 19Ld % 5d % d \ n " time...
let info_one_breakpoint ppf ( num , ev ) = fprintf ppf " % 3d % d :% 10d % s . " @ num ev . ev_frag ev . ev_ev . ev_pos ( Pos . get_desc ev )
let info_breakpoints ppf lexbuf = eol lexbuf ; if ! breakpoints = [ ] then fprintf ppf " No breakpoints . . " @ else begin fprintf ppf " Num Address Where . " ; @ List . iter ( info_one_breakpoint ppf ) ( List . rev ! breakpoints ) ; end
let info_events _ppf lexbuf = ensure_loaded ( ) ; let mdle = convert_module ( module_of_longident ( opt_longident_eol Lexer . lexeme lexbuf ) ) in print_endline ( " Module : " ^ mdle ) ; print_endline " Address Characters Kind Repr . " ; let frag , events = events_in_module mdle in List . iter ( function ev -> let star...
let instr_load_printer ppf lexbuf = let filename = extract_filename ( argument_eol argument lexbuf ) in try Loadprinter . loadfile ppf filename with Loadprinter . Error e -> Loadprinter . report_error ppf e ; raise Toplevel
let instr_install_printer ppf lexbuf = let lid = longident_eol Lexer . lexeme lexbuf in try Loadprinter . install_printer ppf lid with Loadprinter . Error e -> Loadprinter . report_error ppf e ; raise Toplevel
let instr_remove_printer ppf lexbuf = let lid = longident_eol Lexer . lexeme lexbuf in try Loadprinter . remove_printer lid with Loadprinter . Error e -> Loadprinter . report_error ppf e ; raise Toplevel
let init ppf = instruction_list := [ { instr_name = " cd " ; instr_prio = false ; instr_action = instr_cd ; instr_repeat = true ; instr_help = { instr_name = " complete " ; instr_prio = false ; instr_action = instr_complete ; instr_repeat = false ; instr_help = { instr_name = " pwd " ; instr_prio = false ; instr_action...
let _ = init std_formatter
module Make ( Token : Sig . Camlp4Token ) = struct open Token ; type t = ( Stream . t ( string * Loc . t ) * Queue . t ( string * Loc . t ) ) ; value mk ( ) = let q = Queue . create ( ) in let f _ = debug comments " take . . . @\ n " in try Some ( Queue . take q ) with [ Queue . Empty -> None ] in ( Stream . from f , q...
let f x y = x + y
type my_record = { foo : int ; bar : string ; } object inherit cl val mutable tutu = " tutu " val toto = 1 val titi = " titi " method toto = tutu ^ " " ! method m ( f : float ) = 1 end object val mutable x : int method m : int -> int end