| author | wenzelm | 
| Tue, 28 Aug 2018 11:40:11 +0200 | |
| changeset 68829 | 1a4fa494a4a8 | 
| parent 68541 | 12b4b3bc585d | 
| child 69854 | cc0b3e177b49 | 
| 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 | ||
| 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 | var system_mode = false | 
| 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 | -s system build mode for session image | 
| 38 | ||
| 62588 
cd266473b81b
isabelle_process is superseded by "isabelle process" tool;
 wenzelm parents: 
62586diff
changeset | 39 | 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 | 40 | in interactive mode, with line editor ISABELLE_LINE_EDITOR=""" + | 
| 
cd266473b81b
isabelle_process is superseded by "isabelle process" tool;
 wenzelm parents: 
62586diff
changeset | 41 |   quote(Isabelle_System.getenv("ISABELLE_LINE_EDITOR")) + """.
 | 
| 62559 | 42 | """, | 
| 43 | "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), | |
| 68541 | 44 | "i:" -> (arg => include_sessions = include_sessions ::: List(arg)), | 
| 62559 | 45 | "l:" -> (arg => logic = arg), | 
| 46 | "m:" -> (arg => modes = arg :: modes), | |
| 47 | "n" -> (arg => no_build = true), | |
| 48 | "o:" -> (arg => options = options + arg), | |
| 62643 | 49 | "r" -> (_ => raw_ml_system = true), | 
| 62559 | 50 | "s" -> (_ => system_mode = true)) | 
| 51 | ||
| 52 | val more_args = getopts(args) | |
| 53 | if (!more_args.isEmpty) getopts.usage() | |
| 54 | ||
| 55 | ||
| 68305 | 56 | // build logic | 
| 57 |       if (!no_build && !raw_ml_system) {
 | |
| 64115 | 58 | val progress = new Console_Progress() | 
| 68305 | 59 | val rc = | 
| 68331 | 60 |           progress.interrupt_handler {
 | 
| 61 | Build.build_logic(options, logic, build_heap = true, progress = progress, | |
| 62 | dirs = dirs, system_mode = system_mode) | |
| 63 | } | |
| 68305 | 64 | if (rc != 0) sys.exit(rc) | 
| 62559 | 65 | } | 
| 66 | ||
| 67 | // process loop | |
| 68 | val process = | |
| 64598 | 69 |         ML_Process(options, logic = logic, args = List("-i"), dirs = dirs, redirect = true,
 | 
| 62643 | 70 |           modes = if (raw_ml_system) Nil else modes ::: List("ASCII"),
 | 
| 68209 | 71 | raw_ml_system = raw_ml_system, | 
| 72 | store = Some(Sessions.store(options, system_mode)), | |
| 65431 
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
 wenzelm parents: 
64598diff
changeset | 73 | session_base = | 
| 
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
 wenzelm parents: 
64598diff
changeset | 74 | if (raw_ml_system) None | 
| 68541 | 75 | else Some(Sessions.base_info( | 
| 76 | options, logic, dirs = dirs, include_sessions = include_sessions).check_base)) | |
| 67802 | 77 | |
| 67808 | 78 | val tty_loop = new TTY_Loop(process.stdin, process.stdout, Some(process.interrupt _)) | 
| 62559 | 79 |       val process_result = Future.thread[Int]("process_result") {
 | 
| 80 | val rc = process.join | |
| 67803 | 81 | tty_loop.cancel // FIXME does not quite work, cannot interrupt blocking read on System.in | 
| 62559 | 82 | rc | 
| 83 | } | |
| 67802 | 84 | tty_loop.join | 
| 62562 
905a5db3932d
back to external line editor, due to problems of JLine with multithreading of in vs. out;
 wenzelm parents: 
62561diff
changeset | 85 | process_result.join | 
| 62559 | 86 | } | 
| 87 | } | |
| 88 | } |