src/Pure/System/isabelle_process.scala
author wenzelm
Sat, 18 Mar 2017 20:24:12 +0100
changeset 65310 da9f1ef8ef7c
parent 65225 ec9ec04546fc
child 65316 c0fb8405416c
permissions -rw-r--r--
more process arguments;
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
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
     3
57916
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57915
diff changeset
     4
Isabelle process wrapper.
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
     5
*/
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
package isabelle
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
     8
55618
995162143ef4 tuned imports;
wenzelm
parents: 54443
diff changeset
     9
65310
da9f1ef8ef7c more process arguments;
wenzelm
parents: 65225
diff changeset
    10
import java.io.{File => JFile}
da9f1ef8ef7c more process arguments;
wenzelm
parents: 65225
diff changeset
    11
da9f1ef8ef7c more process arguments;
wenzelm
parents: 65225
diff changeset
    12
57917
8ce97e5d545f tuned signature;
wenzelm
parents: 57916
diff changeset
    13
object Isabelle_Process
8ce97e5d545f tuned signature;
wenzelm
parents: 57916
diff changeset
    14
{
65216
060a8a1f2dec tuned signature;
wenzelm
parents: 62754
diff changeset
    15
  def start(session: Session,
060a8a1f2dec tuned signature;
wenzelm
parents: 62754
diff changeset
    16
    options: Options,
060a8a1f2dec tuned signature;
wenzelm
parents: 62754
diff changeset
    17
    logic: String = "",
060a8a1f2dec tuned signature;
wenzelm
parents: 62754
diff changeset
    18
    args: List[String] = Nil,
060a8a1f2dec tuned signature;
wenzelm
parents: 62754
diff changeset
    19
    dirs: List[Path] = Nil,
060a8a1f2dec tuned signature;
wenzelm
parents: 62754
diff changeset
    20
    modes: List[String] = Nil,
65310
da9f1ef8ef7c more process arguments;
wenzelm
parents: 65225
diff changeset
    21
    cwd: JFile = null,
da9f1ef8ef7c more process arguments;
wenzelm
parents: 65225
diff changeset
    22
    env: Map[String, String] = Isabelle_System.settings(),
da9f1ef8ef7c more process arguments;
wenzelm
parents: 65225
diff changeset
    23
    tree: Option[Sessions.Tree] = None,
65225
ec9ec04546fc support for permanent phase_changed watcher;
wenzelm
parents: 65218
diff changeset
    24
    store: Sessions.Store = Sessions.store(),
ec9ec04546fc support for permanent phase_changed watcher;
wenzelm
parents: 65218
diff changeset
    25
    phase_changed: Session.Phase => Unit = null)
65216
060a8a1f2dec tuned signature;
wenzelm
parents: 62754
diff changeset
    26
  {
65225
ec9ec04546fc support for permanent phase_changed watcher;
wenzelm
parents: 65218
diff changeset
    27
    if (phase_changed != null)
ec9ec04546fc support for permanent phase_changed watcher;
wenzelm
parents: 65218
diff changeset
    28
      session.phase_changed += Session.Consumer("Isabelle_Process")(phase_changed)
ec9ec04546fc support for permanent phase_changed watcher;
wenzelm
parents: 65218
diff changeset
    29
65216
060a8a1f2dec tuned signature;
wenzelm
parents: 62754
diff changeset
    30
    session.start(receiver =>
060a8a1f2dec tuned signature;
wenzelm
parents: 62754
diff changeset
    31
      Isabelle_Process(options, logic = logic, args = args, dirs = dirs, modes = modes,
65310
da9f1ef8ef7c more process arguments;
wenzelm
parents: 65225
diff changeset
    32
        cwd = cwd, env = env, receiver = receiver, xml_cache = session.xml_cache,
da9f1ef8ef7c more process arguments;
wenzelm
parents: 65225
diff changeset
    33
        tree = tree, store = store))
65216
060a8a1f2dec tuned signature;
wenzelm
parents: 62754
diff changeset
    34
  }
060a8a1f2dec tuned signature;
wenzelm
parents: 62754
diff changeset
    35
57917
8ce97e5d545f tuned signature;
wenzelm
parents: 57916
diff changeset
    36
  def apply(
62556
c115e69f457f more abstract Session.start, without prover command-line;
wenzelm
parents: 62555
diff changeset
    37
    options: Options,
62634
aa3b47b32100 less physical "logic" argument, with option -l like "isabelle console" etc.;
wenzelm
parents: 62633
diff changeset
    38
    logic: String = "",
62556
c115e69f457f more abstract Session.start, without prover command-line;
wenzelm
parents: 62555
diff changeset
    39
    args: List[String] = Nil,
62754
c35012b86e6f proper session dirs for "isabelle jedit" and "isabelle console" with options -d and -l;
wenzelm
parents: 62668
diff changeset
    40
    dirs: List[Path] = Nil,
62556
c115e69f457f more abstract Session.start, without prover command-line;
wenzelm
parents: 62555
diff changeset
    41
    modes: List[String] = Nil,
65310
da9f1ef8ef7c more process arguments;
wenzelm
parents: 65225
diff changeset
    42
    cwd: JFile = null,
da9f1ef8ef7c more process arguments;
wenzelm
parents: 65225
diff changeset
    43
    env: Map[String, String] = Isabelle_System.settings(),
62633
e57416b649d5 find heaps uniformly via Sessions.Store;
wenzelm
parents: 62586
diff changeset
    44
    receiver: Prover.Receiver = Console.println(_),
65218
102b8e092860 more explicit Session.xml_cache;
wenzelm
parents: 65216
diff changeset
    45
    xml_cache: XML.Cache = new XML.Cache(),
65310
da9f1ef8ef7c more process arguments;
wenzelm
parents: 65225
diff changeset
    46
    tree: Option[Sessions.Tree] = None,
62633
e57416b649d5 find heaps uniformly via Sessions.Store;
wenzelm
parents: 62586
diff changeset
    47
    store: Sessions.Store = Sessions.store()): Isabelle_Process =
57917
8ce97e5d545f tuned signature;
wenzelm
parents: 57916
diff changeset
    48
  {
62556
c115e69f457f more abstract Session.start, without prover command-line;
wenzelm
parents: 62555
diff changeset
    49
    val channel = System_Channel()
c115e69f457f more abstract Session.start, without prover command-line;
wenzelm
parents: 62555
diff changeset
    50
    val process =
57916
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57915
diff changeset
    51
      try {
65310
da9f1ef8ef7c more process arguments;
wenzelm
parents: 65225
diff changeset
    52
        ML_Process(options, logic = logic, args = args, dirs = dirs, modes = modes,
da9f1ef8ef7c more process arguments;
wenzelm
parents: 65225
diff changeset
    53
          cwd = cwd, env = env, tree = tree, store = store, channel = Some(channel))
57916
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57915
diff changeset
    54
      }
62556
c115e69f457f more abstract Session.start, without prover command-line;
wenzelm
parents: 62555
diff changeset
    55
      catch { case exn @ ERROR(_) => channel.accepted(); throw exn }
c115e69f457f more abstract Session.start, without prover command-line;
wenzelm
parents: 62555
diff changeset
    56
    process.stdin.close
57917
8ce97e5d545f tuned signature;
wenzelm
parents: 57916
diff changeset
    57
65218
102b8e092860 more explicit Session.xml_cache;
wenzelm
parents: 65216
diff changeset
    58
    new Isabelle_Process(receiver, xml_cache, channel, process)
57917
8ce97e5d545f tuned signature;
wenzelm
parents: 57916
diff changeset
    59
  }
57916
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57915
diff changeset
    60
}
27949
6eb0327c0b9b Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff changeset
    61
57917
8ce97e5d545f tuned signature;
wenzelm
parents: 57916
diff changeset
    62
class Isabelle_Process private(
65218
102b8e092860 more explicit Session.xml_cache;
wenzelm
parents: 65216
diff changeset
    63
    receiver: Prover.Receiver,
102b8e092860 more explicit Session.xml_cache;
wenzelm
parents: 65216
diff changeset
    64
    xml_cache: XML.Cache,
102b8e092860 more explicit Session.xml_cache;
wenzelm
parents: 65216
diff changeset
    65
    channel: System_Channel,
102b8e092860 more explicit Session.xml_cache;
wenzelm
parents: 65216
diff changeset
    66
    process: Prover.System_Process)
102b8e092860 more explicit Session.xml_cache;
wenzelm
parents: 65216
diff changeset
    67
  extends Prover(receiver, xml_cache, channel, process)
62309
96c9a259d275 tuned whitespace;
wenzelm
parents: 62308
diff changeset
    68
{
96c9a259d275 tuned whitespace;
wenzelm
parents: 62308
diff changeset
    69
  def encode(s: String): String = Symbol.encode(s)
96c9a259d275 tuned whitespace;
wenzelm
parents: 62308
diff changeset
    70
  def decode(s: String): String = Symbol.decode(s)
96c9a259d275 tuned whitespace;
wenzelm
parents: 62308
diff changeset
    71
}