author | wenzelm |
Sat, 10 Aug 2013 10:59:56 +0200 | |
changeset 52953 | 2c927b7501c5 |
parent 52931 | ac6648c0c0fb |
child 52982 | 8e78bd316a53 |
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 |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
5 |
document overlay. |
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 |
52879
1df5280f8713
support for query operations that consist of parallel segments;
wenzelm
parents:
52876
diff
changeset
|
10 |
val register_parallel: string -> (Toplevel.state -> string list -> (unit -> string) list) -> unit |
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
11 |
val register: string -> (Toplevel.state -> string list -> string) -> unit |
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 |
|
52879
1df5280f8713
support for query operations that consist of parallel segments;
wenzelm
parents:
52876
diff
changeset
|
17 |
fun register_parallel name f = |
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
18 |
Command.print_function name |
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, ...} => |
52953
2c927b7501c5
explicit "strict" flag for print functions (flipped internal meaning);
wenzelm
parents:
52931
diff
changeset
|
20 |
SOME {delay = NONE, pri = 0, persistent = false, strict = false, |
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52929
diff
changeset
|
21 |
print_fn = fn _ => uninterruptible (fn restore_attributes => fn state => |
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
22 |
let |
52876 | 23 |
fun result s = Output.result [(Markup.instanceN, instance)] s; |
24 |
fun status m = result (Markup.markup_only m); |
|
52929
52d21bddcb8a
clarified toplevel_error: absorb and print interrupts;
wenzelm
parents:
52879
diff
changeset
|
25 |
fun toplevel_error exn = |
52d21bddcb8a
clarified toplevel_error: absorb and print interrupts;
wenzelm
parents:
52879
diff
changeset
|
26 |
result (Markup.markup (Markup.errorN, []) (ML_Compiler.exn_message exn)); |
52876 | 27 |
|
28 |
val _ = status Markup.running; |
|
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52929
diff
changeset
|
29 |
val outputs = |
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52929
diff
changeset
|
30 |
Multithreading.interruptible (fn () => f state args) () |
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52929
diff
changeset
|
31 |
handle exn (*sic!*) => (toplevel_error exn; []); |
52879
1df5280f8713
support for query operations that consist of parallel segments;
wenzelm
parents:
52876
diff
changeset
|
32 |
val _ = outputs |> Par_List.map (fn out => |
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52929
diff
changeset
|
33 |
(case Exn.capture (restore_attributes out) () (*sic!*) of |
52929
52d21bddcb8a
clarified toplevel_error: absorb and print interrupts;
wenzelm
parents:
52879
diff
changeset
|
34 |
Exn.Res s => result (Markup.markup (Markup.writelnN, []) s) |
52d21bddcb8a
clarified toplevel_error: absorb and print interrupts;
wenzelm
parents:
52879
diff
changeset
|
35 |
| Exn.Exn exn => toplevel_error exn)); |
52876 | 36 |
val _ = status Markup.finished; |
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52929
diff
changeset
|
37 |
in () end)} |
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
38 |
| _ => NONE); |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
39 |
|
52879
1df5280f8713
support for query operations that consist of parallel segments;
wenzelm
parents:
52876
diff
changeset
|
40 |
fun register name f = |
1df5280f8713
support for query operations that consist of parallel segments;
wenzelm
parents:
52876
diff
changeset
|
41 |
register_parallel name (fn st => fn args => [fn () => f st args]); |
1df5280f8713
support for query operations that consist of parallel segments;
wenzelm
parents:
52876
diff
changeset
|
42 |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
43 |
end; |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
44 |