author | nipkow |
Tue, 05 Nov 2019 14:57:41 +0100 | |
changeset 71033 | c1b63124245c |
parent 69854 | cc0b3e177b49 |
child 71383 | 8313dca6dee9 |
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 |
||
10 |
object ML_Console |
|
11 |
{ |
|
12 |
/* command line entry point */ |
|
13 |
||
14 |
def main(args: Array[String]) |
|
15 |
{ |
|
16 |
Command_Line.tool { |
|
17 |
var dirs: List[Path] = Nil |
|
68541 | 18 |
var include_sessions: List[String] = Nil |
62559 | 19 |
var logic = Isabelle_System.getenv("ISABELLE_LOGIC") |
20 |
var modes: List[String] = Nil |
|
21 |
var no_build = false |
|
22 |
var options = Options.init() |
|
62643 | 23 |
var raw_ml_system = false |
62559 | 24 |
|
25 |
val getopts = Getopts(""" |
|
26 |
Usage: isabelle console [OPTIONS] |
|
27 |
||
28 |
Options are: |
|
29 |
-d DIR include session directory |
|
68541 | 30 |
-i NAME include session in name-space of theories |
62559 | 31 |
-l NAME logic session name (default ISABELLE_LOGIC=""" + quote(logic) + """) |
32 |
-m MODE add print mode for output |
|
33 |
-n no build of session image on startup |
|
34 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
62643 | 35 |
-r bootstrap from raw Poly/ML |
62559 | 36 |
|
62588
cd266473b81b
isabelle_process is superseded by "isabelle process" tool;
wenzelm
parents:
62586
diff
changeset
|
37 |
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
|
38 |
in interactive mode, with line editor ISABELLE_LINE_EDITOR=""" + |
cd266473b81b
isabelle_process is superseded by "isabelle process" tool;
wenzelm
parents:
62586
diff
changeset
|
39 |
quote(Isabelle_System.getenv("ISABELLE_LINE_EDITOR")) + """. |
62559 | 40 |
""", |
41 |
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
|
68541 | 42 |
"i:" -> (arg => include_sessions = include_sessions ::: List(arg)), |
62559 | 43 |
"l:" -> (arg => logic = arg), |
44 |
"m:" -> (arg => modes = arg :: modes), |
|
45 |
"n" -> (arg => no_build = true), |
|
46 |
"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
|
47 |
"r" -> (_ => raw_ml_system = true)) |
62559 | 48 |
|
49 |
val more_args = getopts(args) |
|
50 |
if (!more_args.isEmpty) getopts.usage() |
|
51 |
||
52 |
||
68305 | 53 |
// build logic |
54 |
if (!no_build && !raw_ml_system) { |
|
64115 | 55 |
val progress = new Console_Progress() |
68305 | 56 |
val rc = |
68331 | 57 |
progress.interrupt_handler { |
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
68541
diff
changeset
|
58 |
Build.build_logic(options, logic, build_heap = true, progress = progress, dirs = dirs) |
68331 | 59 |
} |
68305 | 60 |
if (rc != 0) sys.exit(rc) |
62559 | 61 |
} |
62 |
||
63 |
// process loop |
|
64 |
val process = |
|
64598 | 65 |
ML_Process(options, logic = logic, args = List("-i"), dirs = dirs, redirect = true, |
62643 | 66 |
modes = if (raw_ml_system) Nil else modes ::: List("ASCII"), |
68209 | 67 |
raw_ml_system = raw_ml_system, |
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
68541
diff
changeset
|
68 |
store = Some(Sessions.store(options)), |
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
64598
diff
changeset
|
69 |
session_base = |
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
64598
diff
changeset
|
70 |
if (raw_ml_system) None |
68541 | 71 |
else Some(Sessions.base_info( |
72 |
options, logic, dirs = dirs, include_sessions = include_sessions).check_base)) |
|
67802 | 73 |
|
67808 | 74 |
val tty_loop = new TTY_Loop(process.stdin, process.stdout, Some(process.interrupt _)) |
62559 | 75 |
val process_result = Future.thread[Int]("process_result") { |
76 |
val rc = process.join |
|
67803 | 77 |
tty_loop.cancel // FIXME does not quite work, cannot interrupt blocking read on System.in |
62559 | 78 |
rc |
79 |
} |
|
67802 | 80 |
tty_loop.join |
62562
905a5db3932d
back to external line editor, due to problems of JLine with multithreading of in vs. out;
wenzelm
parents:
62561
diff
changeset
|
81 |
process_result.join |
62559 | 82 |
} |
83 |
} |
|
84 |
} |