src/Pure/Isar/runtime.ML
changeset 62516 5732f1c31566
parent 62505 9e2a65912111
child 62519 a564458f94db
equal deleted inserted replaced
62515:e73644de5db8 62516:5732f1c31566
     7 signature RUNTIME =
     7 signature RUNTIME =
     8 sig
     8 sig
     9   exception UNDEF
     9   exception UNDEF
    10   exception EXCURSION_FAIL of exn * string
    10   exception EXCURSION_FAIL of exn * string
    11   exception TOPLEVEL_ERROR
    11   exception TOPLEVEL_ERROR
       
    12   val pretty_exn: exn -> Pretty.T
    12   val exn_context: Proof.context option -> exn -> exn
    13   val exn_context: Proof.context option -> exn -> exn
    13   val thread_context: exn -> exn
    14   val thread_context: exn -> exn
    14   type error = ((serial * string) * string option)
    15   type error = ((serial * string) * string option)
    15   val exn_messages_ids: exn -> error list
    16   val exn_messages_ids: exn -> error list
    16   val exn_messages: exn -> (serial * string) list
    17   val exn_messages: exn -> (serial * string) list
    35 exception UNDEF;
    36 exception UNDEF;
    36 exception EXCURSION_FAIL of exn * string;
    37 exception EXCURSION_FAIL of exn * string;
    37 exception TOPLEVEL_ERROR;
    38 exception TOPLEVEL_ERROR;
    38 
    39 
    39 
    40 
       
    41 (* pretty *)
       
    42 
       
    43 fun pretty_exn (exn: exn) =
       
    44   Pretty.from_ML
       
    45     (ML_Pretty.from_polyml
       
    46       (PolyML.prettyRepresentation (exn, FixedInt.fromInt (ML_Options.get_print_depth ()))));
       
    47 
       
    48 
    40 (* exn_context *)
    49 (* exn_context *)
    41 
    50 
    42 exception CONTEXT of Proof.context * exn;
    51 exception CONTEXT of Proof.context * exn;
    43 
    52 
    44 fun exn_context NONE exn = exn
    53 fun exn_context NONE exn = exn
    83 in
    92 in
    84 
    93 
    85 fun exn_messages_ids e =
    94 fun exn_messages_ids e =
    86   let
    95   let
    87     fun raised exn name msgs =
    96     fun raised exn name msgs =
    88       let val pos = Position.here (Exn_Output.position exn) in
    97       let val pos = Position.here (Exn_Properties.position exn) in
    89         (case msgs of
    98         (case msgs of
    90           [] => "exception " ^ name ^ " raised" ^ pos
    99           [] => "exception " ^ name ^ " raised" ^ pos
    91         | [msg] => "exception " ^ name ^ " raised" ^ pos ^ ": " ^ msg
   100         | [msg] => "exception " ^ name ^ " raised" ^ pos ^ ": " ^ msg
    92         | _ =>
   101         | _ =>
    93             cat_lines (("exception " ^ name ^ " raised" ^ pos ^ ":") ::
   102             cat_lines (("exception " ^ name ^ " raised" ^ pos ^ ":") ::
   121                 raised exn "CTERM"
   130                 raised exn "CTERM"
   122                   (msg :: robust_context context Syntax.string_of_term (map Thm.term_of cts))
   131                   (msg :: robust_context context Syntax.string_of_term (map Thm.term_of cts))
   123             | THM (msg, i, thms) =>
   132             | THM (msg, i, thms) =>
   124                 raised exn ("THM " ^ string_of_int i)
   133                 raised exn ("THM " ^ string_of_int i)
   125                   (msg :: robust_context context Thm.string_of_thm thms)
   134                   (msg :: robust_context context Thm.string_of_thm thms)
   126             | _ => raised exn (robust (Pretty.string_of o Exn_Output.pretty) exn) []);
   135             | _ => raised exn (robust (Pretty.string_of o pretty_exn) exn) []);
   127         in [((i, msg), id)] end)
   136         in [((i, msg), id)] end)
   128       and sorted_msgs context exn =
   137       and sorted_msgs context exn =
   129         sort_distinct (int_ord o apply2 (fst o fst)) (maps exn_msgs (flatten context exn));
   138         sort_distinct (int_ord o apply2 (fst o fst)) (maps exn_msgs (flatten context exn));
   130 
   139 
   131   in sorted_msgs NONE e end;
   140   in sorted_msgs NONE e end;
   148 (* exception debugger *)
   157 (* exception debugger *)
   149 
   158 
   150 local
   159 local
   151 
   160 
   152 fun print_entry (name, loc) =
   161 fun print_entry (name, loc) =
   153   Markup.markup Markup.item (name ^ Position.here (Exn_Properties.position_of loc));
   162   Markup.markup Markup.item (name ^ Position.here (Exn_Properties.position_of_location loc));
   154 
   163 
   155 fun exception_debugger output e =
   164 fun exception_debugger output e =
   156   let
   165   let
   157     val (trace, result) = Exn_Debugger.capture_exception_trace e;
   166     val (trace, result) = Exn_Debugger.capture_exception_trace e;
   158     val _ =
   167     val _ =