| author | wenzelm | 
| Tue, 16 May 2023 15:15:56 +0200 | |
| changeset 78063 | 7c9f290dff55 | 
| parent 76403 | fb9c567a67cd | 
| child 78716 | 97dfba4405e3 | 
| permissions | -rw-r--r-- | 
| 52865 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 1 | (* Title: Pure/PIDE/query_operation.ML | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 2 | Author: Makarius | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 3 | |
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 4 | One-shot query operations via asynchronous print functions and temporary | 
| 57872 | 5 | document overlays. | 
| 52865 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 6 | *) | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 7 | |
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 8 | signature QUERY_OPERATION = | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 9 | sig | 
| 60610 
f52b4b0c10c4
improved scheduling for urgent tasks, using farm of replacement threads (may lead to factor 2 overloading, but CPUs are usually hyperthreaded);
 wenzelm parents: 
57872diff
changeset | 10 |   val register: {name: string, pri: int} ->
 | 
| 61223 | 11 |     ({state: Toplevel.state, args: string list,
 | 
| 12 | output_result: string -> unit, writeln_result: string -> unit} -> unit) -> unit | |
| 52865 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 13 | end; | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 14 | |
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 15 | structure Query_Operation: QUERY_OPERATION = | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 16 | struct | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 17 | |
| 60610 
f52b4b0c10c4
improved scheduling for urgent tasks, using farm of replacement threads (may lead to factor 2 overloading, but CPUs are usually hyperthreaded);
 wenzelm parents: 
57872diff
changeset | 18 | fun register {name, pri} f =
 | 
| 61206 
d5aeb401111a
more specific name to reduce danger of clash with direct uses of plain Command.print_function;
 wenzelm parents: 
60610diff
changeset | 19 | Command.print_function (name ^ "_query") | 
| 52865 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 20 |     (fn {args = instance :: args, ...} =>
 | 
| 61208 | 21 |       SOME {delay = NONE, pri = pri, persistent = false, strict = false,
 | 
| 62923 | 22 | print_fn = fn _ => Thread_Attributes.uninterruptible (fn restore_attributes => fn state => | 
| 61208 | 23 | let | 
| 61223 | 24 | fun output_result s = Output.result [(Markup.instanceN, instance)] [s]; | 
| 25 | fun status m = output_result (Markup.markup_only m); | |
| 26 | fun writeln_result s = output_result (Markup.markup Markup.writeln s); | |
| 27 | fun toplevel_error exn = | |
| 28 | output_result (Markup.markup Markup.error (Runtime.exn_message exn)); | |
| 52876 | 29 | |
| 61208 | 30 | val _ = status Markup.running; | 
| 61223 | 31 | fun run () = | 
| 32 |               f {state = state, args = args, output_result = output_result,
 | |
| 33 | writeln_result = writeln_result}; | |
| 61208 | 34 | val _ = | 
| 35 | (case Exn.capture (*sic!*) (restore_attributes run) () of | |
| 36 | Exn.Res () => () | |
| 37 | | Exn.Exn exn => toplevel_error exn); | |
| 38 | val _ = status Markup.finished; | |
| 39 | in () end)} | |
| 40 | | _ => NONE); | |
| 41 | ||
| 76403 | 42 | end; | 
| 61208 | 43 | |
| 44 | (* print_state *) | |
| 45 | ||
| 46 | val _ = | |
| 76403 | 47 |   Query_Operation.register {name = "print_state", pri = Task_Queue.urgent_pri}
 | 
| 61208 | 48 |     (fn {state = st, output_result, ...} =>
 | 
| 49 | if Toplevel.is_proof st | |
| 61209 | 50 | then output_result (Markup.markup Markup.state (Toplevel.string_of_state st)) | 
| 61208 | 51 | else ()); |