src/Pure/System/isabelle_process.scala
author wenzelm
Tue, 12 Aug 2014 17:28:07 +0200
changeset 57915 448325de6e4f
parent 56831 e3ccf0809d51
child 57916 2c2c24dbf0a4
permissions -rw-r--r--
more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43283
446e6621762d updated headers;
wenzelm
parents: 40848
diff changeset
     1
/*  Title:      Pure/System/isabelle_process.scala
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
27963
c9ea82444189 YXML.parse_failsafe;
wenzelm
parents: 27955
diff changeset
     3
    Options:    :folding=explicit:collapseFolds=1:
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
     4
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
     5
Isabelle process management -- always reactive due to multi-threaded I/O.
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
     6
*/
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
     7
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
     8
package isabelle
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
     9
55618
995162143ef4 tuned imports;
wenzelm
parents: 54443
diff changeset
    10
56703
2d0ca179e749 tuned imports;
wenzelm
parents: 56700
diff changeset
    11
import java.io.{InputStream, OutputStream, BufferedOutputStream, IOException}
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
    12
27973
18d02c0b90b6 moved class Result into static object, removed dynamic tree method;
wenzelm
parents: 27963
diff changeset
    13
45055
55274f7e306b explicit option for socket vs. fifo communication;
wenzelm
parents: 45027
diff changeset
    14
class Isabelle_Process(
56831
e3ccf0809d51 prefer scala.Console with its support for thread-local redirection;
wenzelm
parents: 56794
diff changeset
    15
  receiver: Prover.Message => Unit = Console.println(_),
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
    16
  prover_args: List[String] = Nil)
29192
082ee2a01a6d explicit EventBus for results;
wenzelm
parents: 29178
diff changeset
    17
{
57915
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    18
  /* system process -- default implementation */
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    19
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    20
  protected val system_process: Prover.System_Process =
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    21
  {
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    22
    val system_channel = System_Channel()
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    23
    try {
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    24
      val cmdline =
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    25
        Isabelle_System.getenv_strict("ISABELLE_PROCESS") ::
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    26
          (system_channel.prover_args ::: prover_args)
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    27
      val process =
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    28
        new Isabelle_System.Managed_Process(null, null, false, cmdline: _*) with
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    29
          Prover.System_Process { def channel = system_channel }
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    30
      process.stdin.close
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    31
      process
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    32
    }
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    33
    catch { case exn @ ERROR(_) => system_channel.accepted(); throw(exn) }
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    34
  }
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    35
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    36
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
    37
  /* text and tree data */
48705
dd32321d6eef tuned signature -- slightly more abstract text representation of prover process;
wenzelm
parents: 48355
diff changeset
    38
dd32321d6eef tuned signature -- slightly more abstract text representation of prover process;
wenzelm
parents: 48355
diff changeset
    39
  def encode(s: String): String = Symbol.encode(s)
dd32321d6eef tuned signature -- slightly more abstract text representation of prover process;
wenzelm
parents: 48355
diff changeset
    40
  def decode(s: String): String = Symbol.decode(s)
dd32321d6eef tuned signature -- slightly more abstract text representation of prover process;
wenzelm
parents: 48355
diff changeset
    41
57915
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    42
  val xml_cache: XML.Cache = new XML.Cache()
48705
dd32321d6eef tuned signature -- slightly more abstract text representation of prover process;
wenzelm
parents: 48355
diff changeset
    43
dd32321d6eef tuned signature -- slightly more abstract text representation of prover process;
wenzelm
parents: 48355
diff changeset
    44
46772
be21f050eda4 tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents: 46769
diff changeset
    45
  /* output */
39573
wenzelm
parents: 39572
diff changeset
    46
46772
be21f050eda4 tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents: 46769
diff changeset
    47
  private def system_output(text: String)
39573
wenzelm
parents: 39572
diff changeset
    48
  {
56385
76acce58aeab more general prover operations;
wenzelm
parents: 55618
diff changeset
    49
    receiver(new Prover.Output(XML.Elem(Markup(Markup.SYSTEM, Nil), List(XML.Text(text)))))
39573
wenzelm
parents: 39572
diff changeset
    50
  }
wenzelm
parents: 39572
diff changeset
    51
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
    52
  private def protocol_output(props: Properties.T, bytes: Bytes)
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
    53
  {
56385
76acce58aeab more general prover operations;
wenzelm
parents: 55618
diff changeset
    54
    receiver(new Prover.Protocol_Output(props, bytes))
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
    55
  }
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
    56
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
    57
  private def output(kind: String, props: Properties.T, body: XML.Body)
39573
wenzelm
parents: 39572
diff changeset
    58
  {
57915
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    59
    if (kind == Markup.INIT) system_process.channel.accepted()
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
    60
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
    61
    val main = XML.Elem(Markup(kind, props), Protocol.clean_message(body))
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
    62
    val reports = Protocol.message_reports(props, body)
56385
76acce58aeab more general prover operations;
wenzelm
parents: 55618
diff changeset
    63
    for (msg <- main :: reports) receiver(new Prover.Output(xml_cache.elem(msg)))
39573
wenzelm
parents: 39572
diff changeset
    64
  }
wenzelm
parents: 39572
diff changeset
    65
48016
edbc8e8accd9 more explicit treatment of return code vs. session phase;
wenzelm
parents: 46774
diff changeset
    66
  private def exit_message(rc: Int)
39573
wenzelm
parents: 39572
diff changeset
    67
  {
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
    68
    output(Markup.EXIT, Markup.Return_Code(rc), List(XML.Text("Return code: " + rc.toString)))
39573
wenzelm
parents: 39572
diff changeset
    69
  }
wenzelm
parents: 39572
diff changeset
    70
wenzelm
parents: 39572
diff changeset
    71
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
    72
39585
00be8711082f main Isabelle_Process via Isabelle_System.Managed_Process;
wenzelm
parents: 39575
diff changeset
    73
  /** process manager **/
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
    74
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
    75
  private val (_, process_result) =
57915
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    76
    Simple_Thread.future("process_result") { system_process.join }
39587
f84b70e3bb9c more reactive handling of Isabelle_Process startup errors;
wenzelm
parents: 39585
diff changeset
    77
39585
00be8711082f main Isabelle_Process via Isabelle_System.Managed_Process;
wenzelm
parents: 39575
diff changeset
    78
  private def terminate_process()
00be8711082f main Isabelle_Process via Isabelle_System.Managed_Process;
wenzelm
parents: 39575
diff changeset
    79
  {
57915
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    80
    try { system_process.terminate }
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    81
    catch {
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    82
      case exn @ ERROR(_) => system_output("Failed to terminate prover process: " + exn.getMessage)
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    83
    }
39585
00be8711082f main Isabelle_Process via Isabelle_System.Managed_Process;
wenzelm
parents: 39575
diff changeset
    84
  }
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
    85
39585
00be8711082f main Isabelle_Process via Isabelle_System.Managed_Process;
wenzelm
parents: 39575
diff changeset
    86
  private val process_manager = Simple_Thread.fork("process_manager")
39572
bb3469024b6a added Isabelle_Process.syslog;
wenzelm
parents: 39530
diff changeset
    87
  {
46548
c54a4a22501c clarified initial process startup errors: recover image load failure message (cf. 2cb7e34f6096) and suppress accidental output from raw ML toplevel;
wenzelm
parents: 46121
diff changeset
    88
    val (startup_failed, startup_errors) =
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
    89
    {
48020
a4f9957878ab clarified prover startup: no timeout, read stderr more carefully;
wenzelm
parents: 48019
diff changeset
    90
      var finished: Option[Boolean] = None
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
    91
      val result = new StringBuilder(100)
57915
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    92
      while (finished.isEmpty && (system_process.stderr.ready || !process_result.is_finished)) {
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    93
        while (finished.isEmpty && system_process.stderr.ready) {
48020
a4f9957878ab clarified prover startup: no timeout, read stderr more carefully;
wenzelm
parents: 48019
diff changeset
    94
          try {
57915
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
    95
            val c = system_process.stderr.read
48020
a4f9957878ab clarified prover startup: no timeout, read stderr more carefully;
wenzelm
parents: 48019
diff changeset
    96
            if (c == 2) finished = Some(true)
a4f9957878ab clarified prover startup: no timeout, read stderr more carefully;
wenzelm
parents: 48019
diff changeset
    97
            else result += c.toChar
a4f9957878ab clarified prover startup: no timeout, read stderr more carefully;
wenzelm
parents: 48019
diff changeset
    98
          }
a4f9957878ab clarified prover startup: no timeout, read stderr more carefully;
wenzelm
parents: 48019
diff changeset
    99
          catch { case _: IOException => finished = Some(false) }
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
   100
        }
48020
a4f9957878ab clarified prover startup: no timeout, read stderr more carefully;
wenzelm
parents: 48019
diff changeset
   101
        Thread.sleep(10)
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
   102
      }
39623
6aae022fde9b tuned message;
wenzelm
parents: 39618
diff changeset
   103
      (finished.isEmpty || !finished.get, result.toString.trim)
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
   104
    }
46772
be21f050eda4 tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents: 46769
diff changeset
   105
    if (startup_errors != "") system_output(startup_errors)
39572
bb3469024b6a added Isabelle_Process.syslog;
wenzelm
parents: 39530
diff changeset
   106
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
   107
    if (startup_failed) {
39585
00be8711082f main Isabelle_Process via Isabelle_System.Managed_Process;
wenzelm
parents: 39575
diff changeset
   108
      terminate_process()
39587
f84b70e3bb9c more reactive handling of Isabelle_Process startup errors;
wenzelm
parents: 39585
diff changeset
   109
      process_result.join
56794
a7c5c35b7125 clarified exit sequence: prover is reset afterwards, no more output messages;
wenzelm
parents: 56784
diff changeset
   110
      exit_message(127)
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
   111
    }
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
   112
    else {
57915
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
   113
      val (command_stream, message_stream) = system_process.channel.rendezvous()
39530
16adc476348f Isabelle_Process: more robust rendezvous, even without proper blocking on open (Cygwin);
wenzelm
parents: 39528
diff changeset
   114
56700
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   115
      command_input_init(command_stream)
56697
76b38be47feb eliminated pointless output actors;
wenzelm
parents: 56617
diff changeset
   116
      val stdout = physical_output(false)
76b38be47feb eliminated pointless output actors;
wenzelm
parents: 56617
diff changeset
   117
      val stderr = physical_output(true)
76b38be47feb eliminated pointless output actors;
wenzelm
parents: 56617
diff changeset
   118
      val message = message_output(message_stream)
76b38be47feb eliminated pointless output actors;
wenzelm
parents: 56617
diff changeset
   119
39587
f84b70e3bb9c more reactive handling of Isabelle_Process startup errors;
wenzelm
parents: 39585
diff changeset
   120
      val rc = process_result.join
46772
be21f050eda4 tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents: 46769
diff changeset
   121
      system_output("process terminated")
56700
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   122
      command_input_close()
56697
76b38be47feb eliminated pointless output actors;
wenzelm
parents: 56617
diff changeset
   123
      for (thread <- List(stdout, stderr, message)) thread.join
46772
be21f050eda4 tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents: 46769
diff changeset
   124
      system_output("process_manager terminated")
48016
edbc8e8accd9 more explicit treatment of return code vs. session phase;
wenzelm
parents: 46774
diff changeset
   125
      exit_message(rc)
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
   126
    }
57915
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
   127
    system_process.channel.accepted()
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
   128
  }
27973
18d02c0b90b6 moved class Result into static object, removed dynamic tree method;
wenzelm
parents: 27963
diff changeset
   129
39572
bb3469024b6a added Isabelle_Process.syslog;
wenzelm
parents: 39530
diff changeset
   130
39585
00be8711082f main Isabelle_Process via Isabelle_System.Managed_Process;
wenzelm
parents: 39575
diff changeset
   131
  /* management methods */
27973
18d02c0b90b6 moved class Result into static object, removed dynamic tree method;
wenzelm
parents: 27963
diff changeset
   132
39585
00be8711082f main Isabelle_Process via Isabelle_System.Managed_Process;
wenzelm
parents: 39575
diff changeset
   133
  def join() { process_manager.join() }
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
   134
39585
00be8711082f main Isabelle_Process via Isabelle_System.Managed_Process;
wenzelm
parents: 39575
diff changeset
   135
  def terminate()
38270
71bb3c273dd1 native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents: 38262
diff changeset
   136
  {
56700
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   137
    command_input_close()
57915
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
   138
    system_output("Terminating prover process")
39585
00be8711082f main Isabelle_Process via Isabelle_System.Managed_Process;
wenzelm
parents: 39575
diff changeset
   139
    terminate_process()
27973
18d02c0b90b6 moved class Result into static object, removed dynamic tree method;
wenzelm
parents: 27963
diff changeset
   140
  }
18d02c0b90b6 moved class Result into static object, removed dynamic tree method;
wenzelm
parents: 27963
diff changeset
   141
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
   142
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
   143
56714
061f83259922 tuned comments;
wenzelm
parents: 56703
diff changeset
   144
  /** process streams **/
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
   145
56700
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   146
  /* command input */
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   147
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   148
  private var command_input: Option[Consumer_Thread[List[Bytes]]] = None
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   149
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   150
  private def command_input_close(): Unit = command_input.foreach(_.shutdown)
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   151
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   152
  private def command_input_init(raw_stream: OutputStream)
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   153
  {
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   154
    val name = "command_input"
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   155
    val stream = new BufferedOutputStream(raw_stream)
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   156
    command_input =
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   157
      Some(
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   158
        Consumer_Thread.fork(name)(
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   159
          consume =
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   160
            {
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   161
              case chunks =>
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   162
                try {
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   163
                  Bytes(chunks.map(_.length).mkString("", ",", "\n")).write(stream)
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   164
                  chunks.foreach(_.write(stream))
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   165
                  stream.flush
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   166
                  true
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   167
                }
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   168
                catch { case e: IOException => system_output(name + ": " + e.getMessage); false }
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   169
            },
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   170
          finish = { case () => stream.close; system_output(name + " terminated") }
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   171
        )
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   172
      )
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   173
  }
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   174
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   175
46773
wenzelm
parents: 46772
diff changeset
   176
  /* physical output */
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
   177
56697
76b38be47feb eliminated pointless output actors;
wenzelm
parents: 56617
diff changeset
   178
  private def physical_output(err: Boolean): Thread =
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
   179
  {
45633
2cb7e34f6096 retain stderr and include it in syslog, which is buffered and thus increases the chance that users see remains from crashes etc.;
wenzelm
parents: 45158
diff changeset
   180
    val (name, reader, markup) =
57915
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
   181
      if (err) ("standard_error", system_process.stderr, Markup.STDERR)
448325de6e4f more abstract Prover.System_Process, which allows to bypass Isabelle_System.Managed_Process;
wenzelm
parents: 56831
diff changeset
   182
      else ("standard_output", system_process.stdout, Markup.STDOUT)
45633
2cb7e34f6096 retain stderr and include it in syslog, which is buffered and thus increases the chance that users see remains from crashes etc.;
wenzelm
parents: 45158
diff changeset
   183
56697
76b38be47feb eliminated pointless output actors;
wenzelm
parents: 56617
diff changeset
   184
    Simple_Thread.fork(name) {
46769
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   185
      try {
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   186
        var result = new StringBuilder(100)
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   187
        var finished = false
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   188
        while (!finished) {
28045
1a6f273108ae join stdout/stderr, eliminated Kind.STDERR;
wenzelm
parents: 27999
diff changeset
   189
          //{{{
1a6f273108ae join stdout/stderr, eliminated Kind.STDERR;
wenzelm
parents: 27999
diff changeset
   190
          var c = -1
1a6f273108ae join stdout/stderr, eliminated Kind.STDERR;
wenzelm
parents: 27999
diff changeset
   191
          var done = false
45633
2cb7e34f6096 retain stderr and include it in syslog, which is buffered and thus increases the chance that users see remains from crashes etc.;
wenzelm
parents: 45158
diff changeset
   192
          while (!done && (result.length == 0 || reader.ready)) {
2cb7e34f6096 retain stderr and include it in syslog, which is buffered and thus increases the chance that users see remains from crashes etc.;
wenzelm
parents: 45158
diff changeset
   193
            c = reader.read
28045
1a6f273108ae join stdout/stderr, eliminated Kind.STDERR;
wenzelm
parents: 27999
diff changeset
   194
            if (c >= 0) result.append(c.asInstanceOf[Char])
1a6f273108ae join stdout/stderr, eliminated Kind.STDERR;
wenzelm
parents: 27999
diff changeset
   195
            else done = true
1a6f273108ae join stdout/stderr, eliminated Kind.STDERR;
wenzelm
parents: 27999
diff changeset
   196
          }
1a6f273108ae join stdout/stderr, eliminated Kind.STDERR;
wenzelm
parents: 27999
diff changeset
   197
          if (result.length > 0) {
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   198
            output(markup, Nil, List(XML.Text(decode(result.toString))))
28045
1a6f273108ae join stdout/stderr, eliminated Kind.STDERR;
wenzelm
parents: 27999
diff changeset
   199
            result.length = 0
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
   200
          }
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
   201
          else {
45633
2cb7e34f6096 retain stderr and include it in syslog, which is buffered and thus increases the chance that users see remains from crashes etc.;
wenzelm
parents: 45158
diff changeset
   202
            reader.close
28045
1a6f273108ae join stdout/stderr, eliminated Kind.STDERR;
wenzelm
parents: 27999
diff changeset
   203
            finished = true
38270
71bb3c273dd1 native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents: 38262
diff changeset
   204
          }
71bb3c273dd1 native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents: 38262
diff changeset
   205
          //}}}
71bb3c273dd1 native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents: 38262
diff changeset
   206
        }
71bb3c273dd1 native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents: 38262
diff changeset
   207
      }
46772
be21f050eda4 tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents: 46769
diff changeset
   208
      catch { case e: IOException => system_output(name + ": " + e.getMessage) }
be21f050eda4 tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents: 46769
diff changeset
   209
      system_output(name + " terminated")
38270
71bb3c273dd1 native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents: 38262
diff changeset
   210
    }
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
   211
  }
38270
71bb3c273dd1 native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents: 38262
diff changeset
   212
71bb3c273dd1 native Isabelle_Process commands, based on efficient byte channel protocol for string lists;
wenzelm
parents: 38262
diff changeset
   213
38259
2b61c5e27399 distinguish proper Isabelle_Process INPUT vs. raw STDIN, tuned corresponding method names;
wenzelm
parents: 38253
diff changeset
   214
  /* message output */
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
   215
56697
76b38be47feb eliminated pointless output actors;
wenzelm
parents: 56617
diff changeset
   216
  private def message_output(stream: InputStream): Thread =
39526
f1296795a8dc message_actor: more robust treatment of EOF;
wenzelm
parents: 39525
diff changeset
   217
  {
f1296795a8dc message_actor: more robust treatment of EOF;
wenzelm
parents: 39525
diff changeset
   218
    class EOF extends Exception
f1296795a8dc message_actor: more robust treatment of EOF;
wenzelm
parents: 39525
diff changeset
   219
    class Protocol_Error(msg: String) extends Exception(msg)
38259
2b61c5e27399 distinguish proper Isabelle_Process INPUT vs. raw STDIN, tuned corresponding method names;
wenzelm
parents: 38253
diff changeset
   220
39528
c01d89d18ff0 refined Isabelle_Process startup: emit \002 before rendezvous on fifos, more robust treatment of startup failure with timeout, do not quit() after main loop;
wenzelm
parents: 39526
diff changeset
   221
    val name = "message_output"
56697
76b38be47feb eliminated pointless output actors;
wenzelm
parents: 56617
diff changeset
   222
    Simple_Thread.fork(name) {
34100
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   223
      val default_buffer = new Array[Byte](65536)
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   224
      var c = -1
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
   225
52799
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   226
      def read_int(): Int =
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   227
      //{{{
34100
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   228
      {
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   229
        var n = 0
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   230
        c = stream.read
39526
f1296795a8dc message_actor: more robust treatment of EOF;
wenzelm
parents: 39525
diff changeset
   231
        if (c == -1) throw new EOF
34100
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   232
        while (48 <= c && c <= 57) {
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   233
          n = 10 * n + (c - 48)
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   234
          c = stream.read
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   235
        }
52799
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   236
        if (c != 10)
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   237
          throw new Protocol_Error("malformed header: expected integer followed by newline")
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   238
        else n
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   239
      }
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   240
      //}}}
34100
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   241
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   242
      def read_chunk_bytes(): (Array[Byte], Int) =
52799
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   243
      //{{{
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   244
      {
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   245
        val n = read_int()
34100
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   246
        val buf =
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   247
          if (n <= default_buffer.size) default_buffer
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   248
          else new Array[Byte](n)
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   249
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   250
        var i = 0
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   251
        var m = 0
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   252
        do {
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   253
          m = stream.read(buf, i, n - i)
39731
5cb0d7b0d601 bulk read: observe EOF protocol more carefully -- 0 counts as successful read;
wenzelm
parents: 39632
diff changeset
   254
          if (m != -1) i += m
52799
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   255
        }
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   256
        while (m != -1 && n > i)
34100
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   257
52799
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   258
        if (i != n)
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   259
          throw new Protocol_Error("bad chunk (unexpected EOF after " + i + " of " + n + " bytes)")
34100
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   260
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   261
        (buf, n)
34100
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   262
      }
52799
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   263
      //}}}
34100
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   264
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   265
      def read_chunk(): XML.Body =
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   266
      {
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   267
        val (buf, n) = read_chunk_bytes()
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   268
        YXML.parse_body_failsafe(UTF8.decode_chars(decode, buf, 0, n))
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   269
      }
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   270
46769
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   271
      try {
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   272
        do {
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   273
          try {
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   274
            val header = read_chunk()
46769
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   275
            header match {
49677
c4e2762a265c more direct message header: eliminated historic encoding via single letter;
wenzelm
parents: 49445
diff changeset
   276
              case List(XML.Elem(Markup(name, props), Nil)) =>
c4e2762a265c more direct message header: eliminated historic encoding via single letter;
wenzelm
parents: 49445
diff changeset
   277
                val kind = name.intern
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   278
                if (kind == Markup.PROTOCOL) {
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   279
                  val (buf, n) = read_chunk_bytes()
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   280
                  protocol_output(props, Bytes(buf, 0, n))
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   281
                }
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   282
                else {
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   283
                  val body = read_chunk()
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   284
                  output(kind, props, body)
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   285
                }
46769
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   286
              case _ =>
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 54440
diff changeset
   287
                read_chunk()
46769
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   288
                throw new Protocol_Error("bad header: " + header.toString)
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   289
            }
28063
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28056
diff changeset
   290
          }
46769
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   291
          catch { case _: EOF => }
52799
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   292
        }
6a4498b048b7 tuned -- more uniform ML vs. Scala;
wenzelm
parents: 52582
diff changeset
   293
        while (c != -1)
46769
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   294
      }
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   295
      catch {
46772
be21f050eda4 tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents: 46769
diff changeset
   296
        case e: IOException => system_output("Cannot read message:\n" + e.getMessage)
be21f050eda4 tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents: 46769
diff changeset
   297
        case e: Protocol_Error => system_output("Malformed message:\n" + e.getMessage)
46769
0038386efd81 clarified scope of exception handlers;
wenzelm
parents: 46762
diff changeset
   298
      }
34100
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   299
      stream.close
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 32474
diff changeset
   300
46772
be21f050eda4 tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents: 46769
diff changeset
   301
      system_output(name + " terminated")
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
   302
    }
39526
f1296795a8dc message_actor: more robust treatment of EOF;
wenzelm
parents: 39525
diff changeset
   303
  }
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
   304
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
   305
38259
2b61c5e27399 distinguish proper Isabelle_Process INPUT vs. raw STDIN, tuned corresponding method names;
wenzelm
parents: 38253
diff changeset
   306
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
   307
  /** protocol commands **/
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
   308
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
   309
  def protocol_command_bytes(name: String, args: Bytes*): Unit =
56700
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   310
    command_input match {
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   311
      case Some(thread) => thread.send(Bytes(name) :: args.toList)
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   312
      case None => error("Uninitialized command input thread")
c84bf6f63dfe clarified command_input: Consumer_Thread;
wenzelm
parents: 56697
diff changeset
   313
    }
38372
e753f71b6b34 added Isabelle_Process.input_bytes, which avoids the somewhat slow Standard_System.string_bytes (just in case someone wants to stream raw data at 250MB/s);
wenzelm
parents: 38270
diff changeset
   314
52582
31467a4b1466 tuned signature;
wenzelm
parents: 52581
diff changeset
   315
  def protocol_command(name: String, args: String*)
43721
fad8634cee62 echo prover input via raw_messages, for improved protocol tracing;
wenzelm
parents: 43695
diff changeset
   316
  {
56385
76acce58aeab more general prover operations;
wenzelm
parents: 55618
diff changeset
   317
    receiver(new Prover.Input(name, args.toList))
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
   318
    protocol_command_bytes(name, args.map(Bytes(_)): _*)
43721
fad8634cee62 echo prover input via raw_messages, for improved protocol tracing;
wenzelm
parents: 43695
diff changeset
   319
  }
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
   320
}