| author | haftmann | 
| Wed, 10 Aug 2022 18:26:22 +0000 | |
| changeset 75800 | a21debbc7074 | 
| parent 75393 | 87ebf5a50283 | 
| child 75920 | 27bf2533f4a4 | 
| 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: 
62586diff
changeset | 4 | The raw ML process in interactive mode. | 
| 62559 | 5 | */ | 
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 9 | ||
| 75393 | 10 | object ML_Console {
 | 
| 62559 | 11 | /* command line entry point */ | 
| 12 | ||
| 75393 | 13 |   def main(args: Array[String]): Unit = {
 | 
| 62559 | 14 |     Command_Line.tool {
 | 
| 15 | var dirs: List[Path] = Nil | |
| 68541 | 16 | var include_sessions: List[String] = Nil | 
| 62559 | 17 |       var logic = Isabelle_System.getenv("ISABELLE_LOGIC")
 | 
| 18 | var modes: List[String] = Nil | |
| 19 | var no_build = false | |
| 20 | var options = Options.init() | |
| 62643 | 21 | var raw_ml_system = false | 
| 62559 | 22 | |
| 23 |       val getopts = Getopts("""
 | |
| 24 | Usage: isabelle console [OPTIONS] | |
| 25 | ||
| 26 | Options are: | |
| 27 | -d DIR include session directory | |
| 68541 | 28 | -i NAME include session in name-space of theories | 
| 62559 | 29 | -l NAME logic session name (default ISABELLE_LOGIC=""" + quote(logic) + """) | 
| 30 | -m MODE add print mode for output | |
| 31 | -n no build of session image on startup | |
| 32 | -o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) | |
| 62643 | 33 | -r bootstrap from raw Poly/ML | 
| 62559 | 34 | |
| 62588 
cd266473b81b
isabelle_process is superseded by "isabelle process" tool;
 wenzelm parents: 
62586diff
changeset | 35 | Build a logic session image and run the raw Isabelle ML process | 
| 
cd266473b81b
isabelle_process is superseded by "isabelle process" tool;
 wenzelm parents: 
62586diff
changeset | 36 | in interactive mode, with line editor ISABELLE_LINE_EDITOR=""" + | 
| 
cd266473b81b
isabelle_process is superseded by "isabelle process" tool;
 wenzelm parents: 
62586diff
changeset | 37 |   quote(Isabelle_System.getenv("ISABELLE_LINE_EDITOR")) + """.
 | 
| 62559 | 38 | """, | 
| 39 | "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), | |
| 68541 | 40 | "i:" -> (arg => include_sessions = include_sessions ::: List(arg)), | 
| 62559 | 41 | "l:" -> (arg => logic = arg), | 
| 42 | "m:" -> (arg => modes = arg :: modes), | |
| 72570 | 43 | "n" -> (_ => no_build = true), | 
| 62559 | 44 | "o:" -> (arg => options = options + arg), | 
| 69854 
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
 wenzelm parents: 
68541diff
changeset | 45 | "r" -> (_ => raw_ml_system = true)) | 
| 62559 | 46 | |
| 47 | val more_args = getopts(args) | |
| 71383 | 48 | if (more_args.nonEmpty) getopts.usage() | 
| 62559 | 49 | |
| 50 | ||
| 71594 | 51 | val sessions_structure = Sessions.load_structure(options, dirs = dirs) | 
| 71598 | 52 | val store = Sessions.store(options) | 
| 71594 | 53 | |
| 68305 | 54 | // build logic | 
| 55 |       if (!no_build && !raw_ml_system) {
 | |
| 64115 | 56 | val progress = new Console_Progress() | 
| 68305 | 57 | val rc = | 
| 68331 | 58 |           progress.interrupt_handler {
 | 
| 69854 
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
 wenzelm parents: 
68541diff
changeset | 59 | Build.build_logic(options, logic, build_heap = true, progress = progress, dirs = dirs) | 
| 68331 | 60 | } | 
| 74306 | 61 | if (rc != Process_Result.RC.ok) sys.exit(rc) | 
| 62559 | 62 | } | 
| 63 | ||
| 64 | // process loop | |
| 65 | val process = | |
| 71598 | 66 | ML_Process(options, sessions_structure, store, | 
| 67 |           logic = logic, args = List("-i"), redirect = true,
 | |
| 62643 | 68 |           modes = if (raw_ml_system) Nil else modes ::: List("ASCII"),
 | 
| 68209 | 69 | raw_ml_system = raw_ml_system, | 
| 65431 
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
 wenzelm parents: 
64598diff
changeset | 70 | session_base = | 
| 
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
 wenzelm parents: 
64598diff
changeset | 71 | if (raw_ml_system) None | 
| 68541 | 72 | else Some(Sessions.base_info( | 
| 72627 | 73 | options, logic, dirs = dirs, include_sessions = include_sessions).check.base)) | 
| 67802 | 74 | |
| 73367 | 75 |       POSIX_Interrupt.handler { process.interrupt() } {
 | 
| 74141 | 76 | new TTY_Loop(process.stdin, process.stdout).join() | 
| 77 | val rc = process.join() | |
| 74306 | 78 | if (rc != Process_Result.RC.ok) sys.exit(rc) | 
| 62559 | 79 | } | 
| 80 | } | |
| 81 | } | |
| 82 | } |