1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
2001-12-07 05:41:02 -08:00
|
|
|
(* under the terms of the GNU Library General Public License, with *)
|
|
|
|
(* the special exception on linking described in file ../LICENSE. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1997-06-06 07:54:09 -07:00
|
|
|
open Printf;;
|
|
|
|
|
|
|
|
let locfmt =
|
|
|
|
match Sys.os_type with
|
2002-10-31 02:00:02 -08:00
|
|
|
| "MacOS" ->
|
|
|
|
format_of_string "File \"%s\"; line %d; characters %d to %d ### %s"
|
|
|
|
| _ ->
|
|
|
|
format_of_string "File \"%s\", line %d, characters %d-%d: %s"
|
1997-06-06 07:54:09 -07:00
|
|
|
;;
|
1997-05-13 11:27:27 -07:00
|
|
|
|
1997-06-12 08:29:01 -07:00
|
|
|
let field x i =
|
|
|
|
let f = Obj.field x i in
|
|
|
|
if not (Obj.is_block f) then
|
|
|
|
sprintf "%d" (Obj.magic f : int) (* can also be a char *)
|
1998-10-01 05:34:32 -07:00
|
|
|
else if Obj.tag f = Obj.string_tag then
|
2002-06-27 02:27:14 -07:00
|
|
|
sprintf "%S" (Obj.magic f : string)
|
1998-10-01 05:34:32 -07:00
|
|
|
else if Obj.tag f = Obj.double_tag then
|
1997-06-12 08:29:01 -07:00
|
|
|
string_of_float (Obj.magic f : float)
|
|
|
|
else
|
|
|
|
"_"
|
|
|
|
;;
|
|
|
|
let rec other_fields x i =
|
|
|
|
if i >= Obj.size x then ""
|
|
|
|
else sprintf ", %s%s" (field x i) (other_fields x (i+1))
|
|
|
|
;;
|
|
|
|
let fields x =
|
|
|
|
match Obj.size x with
|
|
|
|
| 0 -> ""
|
|
|
|
| 1 -> ""
|
|
|
|
| 2 -> sprintf "(%s)" (field x 1)
|
|
|
|
| n -> sprintf "(%s%s)" (field x 1) (other_fields x 2)
|
|
|
|
;;
|
|
|
|
|
|
|
|
let to_string = function
|
|
|
|
| Out_of_memory -> "Out of memory";
|
|
|
|
| Stack_overflow -> "Stack overflow";
|
2002-11-01 09:06:47 -08:00
|
|
|
| Match_failure(file, line, char) ->
|
|
|
|
sprintf locfmt file line char (char+5) "Pattern matching failed";
|
|
|
|
| Assert_failure(file, line, char) ->
|
|
|
|
sprintf locfmt file line char (char+6) "Assertion failed";
|
1995-05-04 03:15:53 -07:00
|
|
|
| x ->
|
1997-06-12 08:29:01 -07:00
|
|
|
let x = Obj.repr x in
|
|
|
|
let constructor = (Obj.magic(Obj.field (Obj.field x 0) 0) : string) in
|
|
|
|
constructor ^ (fields x)
|
|
|
|
;;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
let print fct arg =
|
|
|
|
try
|
|
|
|
fct arg
|
|
|
|
with x ->
|
1997-06-12 08:29:01 -07:00
|
|
|
eprintf "Uncaught exception: %s\n" (to_string x);
|
1995-11-15 01:33:15 -08:00
|
|
|
flush stderr;
|
1995-05-04 03:15:53 -07:00
|
|
|
raise x
|
|
|
|
|
|
|
|
let catch fct arg =
|
|
|
|
try
|
|
|
|
fct arg
|
|
|
|
with x ->
|
|
|
|
flush stdout;
|
1997-06-12 08:29:01 -07:00
|
|
|
eprintf "Uncaught exception: %s\n" (to_string x);
|
1995-05-04 03:15:53 -07:00
|
|
|
exit 2
|