src/Pure/PIDE/query_operation.ML
author wenzelm
Tue, 08 Apr 2014 20:03:00 +0200
changeset 56473 5b5c750e9763
parent 56333 38f1422ef473
child 57872 28e17057b545
permissions -rw-r--r--
simplified Text.Chunk -- eliminated ooddities; afford strict symbol_index, which is usually empty anyway;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
52982
8e78bd316a53 clarified Query_Operation.register: avoid hard-wired parallel policy;
wenzelm
parents: 52953
diff changeset
    10
  val register: string ->
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
52982
8e78bd316a53 clarified Query_Operation.register: avoid hard-wired parallel policy;
wenzelm
parents: 52953
diff changeset
    17
fun register 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
56333
38f1422ef473 support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
wenzelm
parents: 56303
diff changeset
    23
              fun result s = Output.result [(Markup.instanceN, instance)] [s];
52876
78989972d5b8 more explicit status for query operation;
wenzelm
parents: 52865
diff changeset
    24
              fun status m = result (Markup.markup_only m);
52982
8e78bd316a53 clarified Query_Operation.register: avoid hard-wired parallel policy;
wenzelm
parents: 52953
diff changeset
    25
              fun output_result s = result (Markup.markup (Markup.writelnN, []) s);
52929
52d21bddcb8a clarified toplevel_error: absorb and print interrupts;
wenzelm
parents: 52879
diff changeset
    26
              fun toplevel_error exn =
56303
4cc3f4db3447 clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
wenzelm
parents: 52982
diff changeset
    27
                result (Markup.markup (Markup.errorN, []) (Runtime.exn_message exn));
52876
78989972d5b8 more explicit status for query operation;
wenzelm
parents: 52865
diff changeset
    28
78989972d5b8 more explicit status for query operation;
wenzelm
parents: 52865
diff changeset
    29
              val _ = status Markup.running;
52982
8e78bd316a53 clarified Query_Operation.register: avoid hard-wired parallel policy;
wenzelm
parents: 52953
diff changeset
    30
              fun run () = f {state = state, args = args, output_result = output_result};
8e78bd316a53 clarified Query_Operation.register: avoid hard-wired parallel policy;
wenzelm
parents: 52953
diff changeset
    31
              val _ =
8e78bd316a53 clarified Query_Operation.register: avoid hard-wired parallel policy;
wenzelm
parents: 52953
diff changeset
    32
                (case Exn.capture (*sic!*) (restore_attributes run) () of
8e78bd316a53 clarified Query_Operation.register: avoid hard-wired parallel policy;
wenzelm
parents: 52953
diff changeset
    33
                  Exn.Res () => ()
8e78bd316a53 clarified Query_Operation.register: avoid hard-wired parallel policy;
wenzelm
parents: 52953
diff changeset
    34
                | Exn.Exn exn => toplevel_error exn);
52876
78989972d5b8 more explicit status for query operation;
wenzelm
parents: 52865
diff changeset
    35
              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
    36
            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
    37
      | _ => NONE);
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff changeset
    38
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff changeset
    39
end;
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff changeset
    40