| author | wenzelm |
| Fri, 07 Oct 2016 17:41:19 +0200 | |
| changeset 64086 | ac7ae5067783 |
| parent 62923 | 3a122e1e352a |
| child 76403 | fb9c567a67cd |
| 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,
|
| 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 |
||
42 |
||
43 |
(* print_state *) |
|
44 |
||
45 |
val _ = |
|
|
61214
a00bee2dfbd1
tuned priority (like other query operations, e.g. "find_theorems");
wenzelm
parents:
61209
diff
changeset
|
46 |
register {name = "print_state", pri = Task_Queue.urgent_pri}
|
| 61208 | 47 |
(fn {state = st, output_result, ...} =>
|
48 |
if Toplevel.is_proof st |
|
| 61209 | 49 |
then output_result (Markup.markup Markup.state (Toplevel.string_of_state st)) |
| 61208 | 50 |
else ()); |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
51 |
|
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
52 |
end; |