author | haftmann |
Thu, 19 Jun 2025 17:15:40 +0200 | |
changeset 82734 | 89347c0cc6a3 |
parent 82583 | abd3885a3fcf |
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, |
82583 | 12 |
output_result: string list -> unit, |
13 |
writelns_result: string list -> unit, |
|
14 |
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
|
15 |
end; |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
16 |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
17 |
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
|
18 |
struct |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
19 |
|
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
|
20 |
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
|
21 |
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
|
22 |
(fn {args = instance :: args, ...} => |
61208 | 23 |
SOME {delay = NONE, pri = pri, persistent = false, strict = false, |
78716 | 24 |
print_fn = fn _ => Thread_Attributes.uninterruptible (fn run => fn state => |
61208 | 25 |
let |
82583 | 26 |
fun output_result ss = Output.result [(Markup.instanceN, instance)] ss; |
27 |
fun status m = output_result [YXML.output_markup_only m]; |
|
28 |
fun writelns_result ss = output_result (Markup.markup_strings Markup.writeln ss); |
|
29 |
val writeln_result = writelns_result o single; |
|
61223 | 30 |
fun toplevel_error exn = |
82583 | 31 |
output_result [Markup.markup Markup.error (Runtime.exn_message exn)]; |
52876 | 32 |
|
61208 | 33 |
val _ = status Markup.running; |
78716 | 34 |
fun main () = |
61223 | 35 |
f {state = state, args = args, output_result = output_result, |
82583 | 36 |
writelns_result = writelns_result, writeln_result = writeln_result}; |
61208 | 37 |
val _ = |
78757 | 38 |
(case Exn.capture_body (*sic!*) (run main) of |
61208 | 39 |
Exn.Res () => () |
40 |
| Exn.Exn exn => toplevel_error exn); |
|
41 |
val _ = status Markup.finished; |
|
42 |
in () end)} |
|
43 |
| _ => NONE); |
|
44 |
||
76403 | 45 |
end; |
61208 | 46 |
|
47 |
(* print_state *) |
|
48 |
||
49 |
val _ = |
|
76403 | 50 |
Query_Operation.register {name = "print_state", pri = Task_Queue.urgent_pri} |
61208 | 51 |
(fn {state = st, output_result, ...} => |
52 |
if Toplevel.is_proof st |
|
82583 | 53 |
then |
54 |
Toplevel.pretty_state st |
|
55 |
|> Pretty.chunks |
|
56 |
|> Pretty.strings_of |
|
57 |
|> Markup.markup_strings Markup.state |
|
58 |
|> output_result |
|
61208 | 59 |
else ()); |