author | wenzelm |
Mon, 07 Mar 2016 22:40:43 +0100 | |
changeset 62554 | 56449c2d20db |
parent 62548 | f8ebb715e06d |
child 62555 | fd6e64133684 |
permissions | -rw-r--r-- |
43283 | 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 | 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 | 9 |
|
57917 | 10 |
object Isabelle_Process |
11 |
{ |
|
12 |
def apply( |
|
13 |
receiver: Prover.Message => Unit = Console.println(_), |
|
62545
8ebffdaf2ce2
Bash.process always uses a closed script instead of an open argument list, for extra robustness on Windows, where quoting is not well-defined;
wenzelm
parents:
62309
diff
changeset
|
14 |
prover_args: List[String] = Nil): Isabelle_Process = |
57917 | 15 |
{ |
16 |
val system_channel = System_Channel() |
|
17 |
val system_process = |
|
57916 | 18 |
try { |
62545
8ebffdaf2ce2
Bash.process always uses a closed script instead of an open argument list, for extra robustness on Windows, where quoting is not well-defined;
wenzelm
parents:
62309
diff
changeset
|
19 |
val process = |
62548 | 20 |
Bash.process("\"$ISABELLE_PROCESS\" -P " + File.bash_string(system_channel.server_name) + |
21 |
" " + File.bash_args(prover_args)) |
|
57916 | 22 |
process.stdin.close |
23 |
process |
|
24 |
} |
|
60215 | 25 |
catch { case exn @ ERROR(_) => system_channel.accepted(); throw exn } |
57917 | 26 |
|
27 |
new Isabelle_Process(receiver, system_channel, system_process) |
|
28 |
} |
|
62554
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
29 |
|
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
30 |
|
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
31 |
/* command line entry point */ |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
32 |
|
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
33 |
def main(args: Array[String]) |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
34 |
{ |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
35 |
Command_Line.tool { |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
36 |
var secure = false |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
37 |
var ml_args: List[String] = Nil |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
38 |
var modes: List[String] = Nil |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
39 |
var options = Options.init() |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
40 |
|
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
41 |
val getopts = Getopts(""" |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
42 |
Usage: isabelle_process [OPTIONS] [HEAP] |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
43 |
|
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
44 |
Options are: |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
45 |
-S secure mode -- disallow critical operations |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
46 |
-e ML_EXPR evaluate ML expression on startup |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
47 |
-f ML_FILE evaluate ML file on startup |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
48 |
-m MODE add print mode for output |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
49 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
50 |
|
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
51 |
If HEAP is a plain name (default $ISABELLE_LOGIC), it is searched in |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
52 |
$ISABELLE_PATH; if it contains a slash, it is taken as literal file; |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
53 |
if it is RAW_ML_SYSTEM, the initial ML heap is used. |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
54 |
""", |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
55 |
"S" -> (_ => secure = true), |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
56 |
"e:" -> (arg => ml_args = ml_args ::: List("--eval", arg)), |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
57 |
"f:" -> (arg => ml_args = ml_args ::: List("--use", arg)), |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
58 |
"m:" -> (arg => modes = arg :: modes), |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
59 |
"o:" -> (arg => options = options + arg)) |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
60 |
|
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
61 |
val heap = |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
62 |
getopts(args) match { |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
63 |
case Nil => "" |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
64 |
case List(heap) => heap |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
65 |
case _ => getopts.usage() |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
66 |
} |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
67 |
|
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
68 |
ML_Process(options, heap = heap, args = ml_args, secure = secure, modes = modes). |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
69 |
result().print_stdout.rc |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
70 |
} |
56449c2d20db
prospective command line entry point for simplified isabelle_process;
wenzelm
parents:
62548
diff
changeset
|
71 |
} |
57916 | 72 |
} |
27949
6eb0327c0b9b
Isabelle process management -- always reactive due to multi-threaded I/O.
wenzelm
parents:
diff
changeset
|
73 |
|
57917 | 74 |
class Isabelle_Process private( |
75 |
receiver: Prover.Message => Unit, |
|
76 |
system_channel: System_Channel, |
|
77 |
system_process: Prover.System_Process) |
|
78 |
extends Prover(receiver, system_channel, system_process) |
|
62309 | 79 |
{ |
80 |
def encode(s: String): String = Symbol.encode(s) |
|
81 |
def decode(s: String): String = Symbol.decode(s) |
|
82 |
} |