* this file.
*)
+(* don't the code below, use the Dumper module in ocamlextra instead.
(* start of dumper.ml *)
(* Dump an OCaml value into a printable string.
let dump v = dump (repr v)
(* end of dumper.ml *)
+*)
(*
let (dump : 'a -> string) = fun x ->
(* ---------------------------------------------------------------------- *)
-let pr2_gen x = pr2 (dump x)
+let pr2_gen x = pr2 (Dumper.dump x)
let assert_equal a b =
if not (a = b)
then failwith ("assert_equal: those 2 values are not equal:\n\t" ^
- (dump a) ^ "\n\t" ^ (dump b) ^ "\n")
+ (Dumper.dump a) ^ "\n\t" ^ (Dumper.dump b) ^ "\n")
let (example2: string -> bool -> unit) = fun s b ->
try assert b with x -> failwith s
let c = open_out "/tmp/ttttt.ml" in
begin
output_string c s; close_out c;
- command2 ("ocamlc -c -pp 'camlp4o pa_extend.cmo q_MLast.cmo -impl' " ^
- "-I +camlp4 -impl macro.ml4");
- command2 "camlp4o ./macro.cmo pr_o.cmo /tmp/ttttt.ml";
- command2 "rm -f /tmp/ttttt.ml";
+ command2 (Commands.ocamlc_cmd ^ " -c -pp '" ^ Commands.camlp4o_cmd ^" pa_extend.cmo q_MLast.cmo -impl' " ^
+ "-I +" ^ Commands.camlp4_cmd ^ " -impl macro.ml4");
+ command2 (Commands.camlp4o_cmd ^" ./macro.cmo pr_o.cmo /tmp/ttttt.ml");
+ Unix.unlink "/tmp/ttttt.ml";
end
(*
(*****************************************************************************)
exception Todo
-exception Impossible
+exception Impossible of int
exception Here
exception ReturnExn
(* old: let _TODO () = failwith "TODO", now via fix_caml with raise Todo *)
let internal_error s = failwith ("internal error: "^s)
-let error_cant_have x = internal_error ("cant have this case: " ^(dump x))
+let error_cant_have x = internal_error ("cant have this case: " ^(Dumper.dump x))
let myassert cond = if cond then () else failwith "assert error"
* In fact dont have to name it, use +> (fun v -> ...) so when want
* erase debug just have to erase one line.
*)
-let warning s v = (pr2 ("Warning: " ^ s ^ "; value = " ^ (dump v)); v)
+let warning s v = (pr2 ("Warning: " ^ s ^ "; value = " ^ (Dumper.dump v)); v)
short_usage_fun();
raise (UnixExit (2))
| Arg.Help msg -> (* printf "%s" msg; exit 0; *)
- raise Impossible (* -help is specified in speclist *)
+ raise (Impossible 1) (* -help is specified in speclist *)
)
| 11 -> "November"
| 12 -> "December"
*)
- | _ -> raise Impossible
+ | _ -> raise (Impossible 2)
let month_info = [
if Sys.file_exists dependencies_cache &&
get_value dependencies_cache =*= dependencies
- then get_value file_cache
+ then
+ (*begin
+ pr2 ("cache computation reuse " ^ file);*)
+ get_value file_cache
+ (*end*)
else begin
- pr2 ("cache computation recompute " ^ file);
+ (*pr2 ("cache computation recompute " ^ file);*)
let res = f () in
write_value dependencies dependencies_cache;
write_value res file_cache;
with Timeout ->
begin
log "timeout (we abort)";
+ (*pr2 (List.hd(cmd_to_list "free -m | grep Mem"));*)
raise Timeout;
end
| e ->
| Some x -> timeout_function x f
+(* removes only if the file does not exists *)
+let remove_file path =
+ if Sys.file_exists path
+ then Sys.remove path
+ else ()
(* creation of tmp files, a la gcc *)
if not !save_tmp_files then begin
!_temp_files_created +> List.iter (fun s ->
(* pr2 ("erasing: " ^ s); *)
- command2 ("rm -f " ^ s)
+ remove_file s
);
_temp_files_created := []
end
if not !save_tmp_files then begin
_temp_files_created :=
List.filter (function x -> not (x =$= f)) !_temp_files_created;
- command2 ("rm -f " ^ f)
+ remove_file f
end
let assoc_with_err_msg k l =
try List.assoc k l
with Not_found ->
- pr2 (spf "pb assoc_with_err_msg: %s" (dump k));
+ pr2 (spf "pb assoc_with_err_msg: %s" (Dumper.dump k));
raise Not_found
(*****************************************************************************)
| ("|" | "/" | "\\" ) ->
f !a !b BnotinA; f !a !b AnotinB; incr a; incr b;
| "<" -> f !a !b AnotinB; incr a;
- | _ -> raise Impossible
+ | _ -> raise (Impossible 3)
)
(*
let _ =
| ">" -> f !a !b BnotinA; incr b;
| "|" -> f !a !b BnotinA; f !a !b AnotinB; incr a; incr b;
| "<" -> f !a !b AnotinB; incr a;
- | _ -> raise Impossible
+ | _ -> raise (Impossible 4)
)
profile_code "Common.full_charpos_to_pos" (fun () -> full_charpos_to_pos2 a)
let test_charpos file =
- full_charpos_to_pos file +> dump +> pr2
+ full_charpos_to_pos file +> Dumper.dump +> pr2
let empty_score () = (Hashtbl.create 101 : score)
+let save_score score path =
+ write_value score path
+let load_score path () =
+ read_value path
let regression_testing_vs newscore bestscore =
optionise (fun () -> Hashtbl.find newscore res),
optionise (fun () -> Hashtbl.find bestscore res)
with
- | None, None -> raise Impossible
+ | None, None -> raise (Impossible 5)
| Some x, None ->
Printf.printf "new test file appeared: %s\n" res;
Hashtbl.add newbestscore res x;