text
stringlengths
12
786k
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 ( " Ambigu...
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 tr...
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 ; resum...
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...
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...
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_c...
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 -> ...
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...
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 ) ...
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 . express...
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 -> erro...
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...
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 -> ( )...
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_...
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_counte...
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 ( mod...
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 p...
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 = ...
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 -...
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 } ->...
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 mdl...
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 ...
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 . ...
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
module Foo = struct let x = 42 end
module type MY_MODULE_TYPE = sig val x : int end
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
module Foo = struct let x = 42 end
module type MY_MODULE_TYPE = sig val x : int end
let number num = Sexp ( Number num ) ; ;
let symbol sym = Sexp ( Symbol sym ) ; ;
let string_ str = Sexp ( String str ) ; ;
let bool_ bl = Sexp ( Bool bl ) ; ;
let list_ lst = Sexp ( List lst ) ; ;
let dotted_list lst last = Sexp ( DottedList ( lst , last ) ) ; ;
let prim_func name func = Func ( PrimFunc ( name , func ) ) ; ;
let user_func func = Func ( UserFunc func ) ; ;
let input_port name lb channel = Port ( InputPort ( name , lb , channel ) ) ; ;
let output_port name channel = Port ( OutputPort ( name , channel ) ) ; ;
let lisp_error error = raise ( Lisp_error error ) ; ;
let arg_count_mismatch expected got = lisp_error ( ArgCountMismatch { arg_count_expected = expected ; arg_count_got = got } ) ; ;
let arg_type_mismatch expected got = lisp_error ( ArgTypeMismatch { arg_type_expected = expected ; arg_type_got = got } ) ; ;
let not_applicable value = lisp_error ( NotApplicable value ) ; ;
let unbound_var var = lisp_error ( UnboundVar var ) ; ;
let closed_chan chan = lisp_error ( ClosedChan chan ) ; ;
let unpack_sexp value = match value with | Sexp sexp -> sexp | _ -> arg_type_mismatch " sexp " value ; ;
let unpack_num value = match unpack_sexp value with | Number num -> num | _ -> arg_type_mismatch " number " value ; ;
let unpack_sym value = match unpack_sexp value with | Symbol sym -> sym | _ -> arg_type_mismatch " symbol " value ; ;
let unpack_str value = match unpack_sexp value with | String str -> str | _ -> arg_type_mismatch " string " value ; ;