author | wenzelm |
Mon, 21 Sep 2015 16:55:37 +0200 | |
changeset 61214 | a00bee2dfbd1 |
parent 61209 | 7a421e7ef97c |
child 61223 | dfccf6c06201 |
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} -> |
52982
8e78bd316a53
clarified Query_Operation.register: avoid hard-wired parallel policy;
wenzelm
parents:
52953
diff
changeset
|
11 |
({state: Toplevel.state, args: string list, output_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
|
12 |
end; |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
13 |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
14 |
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
|
15 |
struct |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
16 |
|
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
|
17 |
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
|
18 |
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
|
19 |
(fn {args = instance :: args, ...} => |
61208 | 20 |
SOME {delay = NONE, pri = pri, persistent = false, strict = false, |
21 |
print_fn = fn _ => uninterruptible (fn restore_attributes => fn state => |
|
22 |
let |
|
23 |
fun result s = Output.result [(Markup.instanceN, instance)] [s]; |
|
24 |
fun status m = result (Markup.markup_only m); |
|
61209 | 25 |
fun output_result s = result (Markup.markup Markup.writeln s); |
26 |
fun toplevel_error exn = result (Markup.markup Markup.error (Runtime.exn_message exn)); |
|
52876 | 27 |
|
61208 | 28 |
val _ = status Markup.running; |
29 |
fun run () = f {state = state, args = args, output_result = output_result}; |
|
30 |
val _ = |
|
31 |
(case Exn.capture (*sic!*) (restore_attributes run) () of |
|
32 |
Exn.Res () => () |
|
33 |
| Exn.Exn exn => toplevel_error exn); |
|
34 |
val _ = status Markup.finished; |
|
35 |
in () end)} |
|
36 |
| _ => NONE); |
|
37 |
||
38 |
||
39 |
(* print_state *) |
|
40 |
||
41 |
val _ = |
|
61214
a00bee2dfbd1
tuned priority (like other query operations, e.g. "find_theorems");
wenzelm
parents:
61209
diff
changeset
|
42 |
register {name = "print_state", pri = Task_Queue.urgent_pri} |
61208 | 43 |
(fn {state = st, output_result, ...} => |
44 |
if Toplevel.is_proof st |
|
61209 | 45 |
then output_result (Markup.markup Markup.state (Toplevel.string_of_state st)) |
61208 | 46 |
else ()); |
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
47 |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
48 |
end; |