| author | wenzelm |
| Sun, 09 Nov 2025 13:01:30 +0100 | |
| changeset 83536 | 45f5af2eec9c |
| parent 83435 | 0f9bae334ac6 |
| permissions | -rw-r--r-- |
| 65477 | 1 |
/* Title: Pure/ML/ml_console.scala |
| 62559 | 2 |
Author: Makarius |
3 |
||
|
62588
cd266473b81b
isabelle_process is superseded by "isabelle process" tool;
wenzelm
parents:
62586
diff
changeset
|
4 |
The raw ML process in interactive mode. |
| 62559 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
| 83536 | 10 |
import scala.collection.mutable |
11 |
||
12 |
||
| 75393 | 13 |
object ML_Console {
|
| 62559 | 14 |
/* command line entry point */ |
15 |
||
| 75393 | 16 |
def main(args: Array[String]): Unit = {
|
| 62559 | 17 |
Command_Line.tool {
|
| 83536 | 18 |
val dir_args = new mutable.ListBuffer[Path] |
19 |
val include_sessions = new mutable.ListBuffer[String] |
|
|
83435
0f9bae334ac6
more uniform Isabelle_System.default_logic, with subtle change of semantics due to getenv_strict;
wenzelm
parents:
82972
diff
changeset
|
20 |
var logic = Isabelle_System.default_logic() |
| 62559 | 21 |
var modes: List[String] = Nil |
22 |
var no_build = false |
|
23 |
var options = Options.init() |
|
| 62643 | 24 |
var raw_ml_system = false |
| 62559 | 25 |
|
26 |
val getopts = Getopts("""
|
|
27 |
Usage: isabelle console [OPTIONS] |
|
28 |
||
29 |
Options are: |
|
30 |
-d DIR include session directory |
|
| 68541 | 31 |
-i NAME include session in name-space of theories |
| 62559 | 32 |
-l NAME logic session name (default ISABELLE_LOGIC=""" + quote(logic) + """) |
33 |
-m MODE add print mode for output |
|
34 |
-n no build of session image on startup |
|
35 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
| 62643 | 36 |
-r bootstrap from raw Poly/ML |
| 62559 | 37 |
|
|
62588
cd266473b81b
isabelle_process is superseded by "isabelle process" tool;
wenzelm
parents:
62586
diff
changeset
|
38 |
Build a logic session image and run the raw Isabelle ML process |
|
cd266473b81b
isabelle_process is superseded by "isabelle process" tool;
wenzelm
parents:
62586
diff
changeset
|
39 |
in interactive mode, with line editor ISABELLE_LINE_EDITOR=""" + |
|
cd266473b81b
isabelle_process is superseded by "isabelle process" tool;
wenzelm
parents:
62586
diff
changeset
|
40 |
quote(Isabelle_System.getenv("ISABELLE_LINE_EDITOR")) + """.
|
| 62559 | 41 |
""", |
| 83536 | 42 |
"d:" -> (arg => dir_args += Path.explode(arg)), |
43 |
"i:" -> (arg => include_sessions += arg), |
|
| 62559 | 44 |
"l:" -> (arg => logic = arg), |
45 |
"m:" -> (arg => modes = arg :: modes), |
|
| 72570 | 46 |
"n" -> (_ => no_build = true), |
| 62559 | 47 |
"o:" -> (arg => options = options + arg), |
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
68541
diff
changeset
|
48 |
"r" -> (_ => raw_ml_system = true)) |
| 62559 | 49 |
|
50 |
val more_args = getopts(args) |
|
| 71383 | 51 |
if (more_args.nonEmpty) getopts.usage() |
| 62559 | 52 |
|
| 83536 | 53 |
val dirs = dir_args.toList |
| 62559 | 54 |
|
| 78178 | 55 |
val store = Store(options) |
| 71594 | 56 |
|
| 68305 | 57 |
// build logic |
58 |
if (!no_build && !raw_ml_system) {
|
|
| 64115 | 59 |
val progress = new Console_Progress() |
| 82972 | 60 |
val results = |
| 68331 | 61 |
progress.interrupt_handler {
|
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
68541
diff
changeset
|
62 |
Build.build_logic(options, logic, build_heap = true, progress = progress, dirs = dirs) |
| 68331 | 63 |
} |
| 82972 | 64 |
if (!results.ok) sys.exit(results.rc) |
| 62559 | 65 |
} |
66 |
||
| 76729 | 67 |
val session_background = |
| 76655 | 68 |
if (raw_ml_system) {
|
| 76656 | 69 |
Sessions.Background( |
| 76655 | 70 |
base = Sessions.Base.bootstrap, |
71 |
sessions_structure = Sessions.load_structure(options, dirs = dirs)) |
|
72 |
} |
|
73 |
else {
|
|
| 76656 | 74 |
Sessions.background( |
| 83536 | 75 |
options, logic, dirs = dirs, include_sessions = include_sessions.toList).check_errors |
| 76655 | 76 |
} |
77 |
||
|
77414
0d5994eef9e6
clarified signature: allow to provide session_heaps by different means, e.g. from tmp directory or alternative session structure;
wenzelm
parents:
76729
diff
changeset
|
78 |
val session_heaps = |
|
0d5994eef9e6
clarified signature: allow to provide session_heaps by different means, e.g. from tmp directory or alternative session structure;
wenzelm
parents:
76729
diff
changeset
|
79 |
if (raw_ml_system) Nil |
| 82752 | 80 |
else store.session_heaps(session_background, logic = logic) |
|
77414
0d5994eef9e6
clarified signature: allow to provide session_heaps by different means, e.g. from tmp directory or alternative session structure;
wenzelm
parents:
76729
diff
changeset
|
81 |
|
| 62559 | 82 |
// process loop |
83 |
val process = |
|
|
77414
0d5994eef9e6
clarified signature: allow to provide session_heaps by different means, e.g. from tmp directory or alternative session structure;
wenzelm
parents:
76729
diff
changeset
|
84 |
ML_Process(options, session_background, session_heaps, args = List("-i"), redirect = true,
|
|
0d5994eef9e6
clarified signature: allow to provide session_heaps by different means, e.g. from tmp directory or alternative session structure;
wenzelm
parents:
76729
diff
changeset
|
85 |
modes = if (raw_ml_system) Nil else modes ::: List("ASCII"))
|
| 67802 | 86 |
|
| 73367 | 87 |
POSIX_Interrupt.handler { process.interrupt() } {
|
| 74141 | 88 |
new TTY_Loop(process.stdin, process.stdout).join() |
89 |
val rc = process.join() |
|
| 74306 | 90 |
if (rc != Process_Result.RC.ok) sys.exit(rc) |
| 62559 | 91 |
} |
92 |
} |
|
93 |
} |
|
94 |
} |