src/Pure/Isar/toplevel.ML
changeset 51323 1b37556a3644
parent 51322 fd67b7f219e4
child 51324 c17f5de0a915
equal deleted inserted replaced
51322:fd67b7f219e4 51323:1b37556a3644
    92   val add_hook: (transition -> state -> state -> unit) -> unit
    92   val add_hook: (transition -> state -> state -> unit) -> unit
    93   val approximative_id: transition -> {file: string, offset: int, name: string} option
    93   val approximative_id: transition -> {file: string, offset: int, name: string} option
    94   val get_timing: transition -> Time.time
    94   val get_timing: transition -> Time.time
    95   val put_timing: Time.time -> transition -> transition
    95   val put_timing: Time.time -> transition -> transition
    96   val transition: bool -> transition -> state -> (state * (exn * string) option) option
    96   val transition: bool -> transition -> state -> (state * (exn * string) option) option
       
    97   val command_errors: bool -> transition -> state -> Runtime.error list * state option
    97   val command_exception: bool -> transition -> state -> state
    98   val command_exception: bool -> transition -> state -> state
    98   val command_errors: bool -> transition -> state -> Runtime.error list * state option
       
    99   val element_result: transition Thy_Syntax.element -> state ->
    99   val element_result: transition Thy_Syntax.element -> state ->
   100     (transition * state) list future * state
   100     (transition * state) list future * state
   101 end;
   101 end;
   102 
   102 
   103 structure Toplevel: TOPLEVEL =
   103 structure Toplevel: TOPLEVEL =
   685 end;
   685 end;
   686 
   686 
   687 
   687 
   688 (* managed commands *)
   688 (* managed commands *)
   689 
   689 
       
   690 fun command_errors int tr st =
       
   691   (case transition int tr st of
       
   692     SOME (st', NONE) => ([], SOME st')
       
   693   | SOME (_, SOME (exn, _)) => (ML_Compiler.exn_messages_ids exn, NONE)
       
   694   | NONE => (ML_Compiler.exn_messages_ids Runtime.TERMINATE, NONE));
       
   695 
   690 fun command_exception int tr st =
   696 fun command_exception int tr st =
   691   (case transition int tr st of
   697   (case transition int tr st of
   692     SOME (st', NONE) => st'
   698     SOME (st', NONE) => st'
   693   | SOME (_, SOME (exn, info)) =>
   699   | SOME (_, SOME (exn, info)) =>
   694       if Exn.is_interrupt exn then reraise exn else raise Runtime.EXCURSION_FAIL (exn, info)
   700       if Exn.is_interrupt exn then reraise exn else raise Runtime.EXCURSION_FAIL (exn, info)
   695   | NONE => raise Runtime.EXCURSION_FAIL (Runtime.TERMINATE, at_command tr));
   701   | NONE => raise Runtime.EXCURSION_FAIL (Runtime.TERMINATE, at_command tr));
   696 
   702 
   697 fun command_errors int tr st =
   703 fun command tr = command_exception (! interact) tr;
   698   (case transition int tr st of
       
   699     SOME (st', NONE) => ([], SOME st')
       
   700   | SOME (_, SOME (exn, _)) => (ML_Compiler.exn_messages_ids exn, NONE)
       
   701   | NONE => (ML_Compiler.exn_messages_ids Runtime.TERMINATE, NONE));
       
   702 
   704 
   703 
   705 
   704 (* scheduled proof result *)
   706 (* scheduled proof result *)
       
   707 
       
   708 local
   705 
   709 
   706 structure Result = Proof_Data
   710 structure Result = Proof_Data
   707 (
   711 (
   708   type T = (transition * state) list future;
   712   type T = (transition * state) list future;
   709   val empty: T = Future.value [];
   713   val empty: T = Future.value [];
   716   in
   720   in
   717     if estimate = Time.zeroTime then ~1
   721     if estimate = Time.zeroTime then ~1
   718     else Int.min (Real.floor (Real.max (Math.log10 (Time.toReal estimate), ~3.0)) - 3, ~1)
   722     else Int.min (Real.floor (Real.max (Math.log10 (Time.toReal estimate), ~3.0)) - 3, ~1)
   719   end;
   723   end;
   720 
   724 
       
   725 fun atom_result tr st =
       
   726   let
       
   727     val st' =
       
   728       if Goal.future_enabled () andalso Keyword.is_diag (name_of tr) then
       
   729         setmp_thread_position tr (fn () =>
       
   730           (Goal.fork_name "Toplevel.diag" (priority (Thy_Syntax.atom tr))
       
   731             (fn () => command tr st); st)) ()
       
   732       else command tr st;
       
   733   in ((tr, st'), st') end;
       
   734 
       
   735 in
       
   736 
   721 fun element_result (Thy_Syntax.Element (head_tr, opt_proof)) st =
   737 fun element_result (Thy_Syntax.Element (head_tr, opt_proof)) st =
   722   let
   738   let
   723     val command = command_exception (! interact);
       
   724 
       
   725     fun atom_result tr st =
       
   726       let
       
   727         val st' =
       
   728           if Goal.future_enabled () andalso Keyword.is_diag (name_of tr) then
       
   729             setmp_thread_position tr (fn () =>
       
   730               (Goal.fork_name "Toplevel.diag" (priority (Thy_Syntax.atom tr))
       
   731                 (fn () => command tr st); st)) ()
       
   732           else command tr st;
       
   733       in ((tr, st'), st') end;
       
   734 
       
   735     val proof_trs =
   739     val proof_trs =
   736       (case opt_proof of
   740       (case opt_proof of
   737         NONE => []
   741         NONE => []
   738       | SOME (a, b) => maps Thy_Syntax.flat_element a @ [b]);
   742       | SOME (a, b) => maps Thy_Syntax.flat_element a @ [b]);
   739 
   743 
   770 
   774 
   771       in (result, st'') end
   775       in (result, st'') end
   772   end;
   776   end;
   773 
   777 
   774 end;
   778 end;
       
   779 
       
   780 end;