author | wenzelm |
Thu, 15 Aug 2024 12:43:17 +0200 | |
changeset 80712 | 05b16602a683 |
parent 78757 | a094bf81a496 |
child 80826 | 7feaa04d332b |
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:
57872
diff
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:
57872
diff
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:
60610
diff
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, |
78716 | 22 |
print_fn = fn _ => Thread_Attributes.uninterruptible (fn run => 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; |
78716 | 31 |
fun main () = |
61223 | 32 |
f {state = state, args = args, output_result = output_result, |
33 |
writeln_result = writeln_result}; |
|
61208 | 34 |
val _ = |
78757 | 35 |
(case Exn.capture_body (*sic!*) (run main) of |
61208 | 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 ()); |