| author | wenzelm | 
| Thu, 27 Mar 2008 15:32:19 +0100 | |
| changeset 26436 | dfd6947ab5c2 | 
| parent 26385 | ae7564661e76 | 
| child 26474 | 94735cff132c | 
| permissions | -rw-r--r-- | 
| 22563 | 1 | (* Title: Pure/ML-Systems/alice.ML | 
| 2 | ID: $Id$ | |
| 3 | ||
| 22837 | 4 | Compatibility file for Alice 1.4. | 
| 23826 
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
 wenzelm parents: 
23139diff
changeset | 5 | |
| 
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
 wenzelm parents: 
23139diff
changeset | 6 | NOTE: there is no wrapper script; may run it interactively as follows: | 
| 
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
 wenzelm parents: 
23139diff
changeset | 7 | |
| 
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
 wenzelm parents: 
23139diff
changeset | 8 | $ cd Isabelle/src/Pure | 
| 
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
 wenzelm parents: 
23139diff
changeset | 9 | $ env ALICE_JIT_MODE=0 alice | 
| 23835 | 10 | - val ml_system = "alice"; | 
| 24807 | 11 | - use "ML-Systems/exn.ML"; | 
| 26226 | 12 | - use "ML-Systems/universal.ML"; | 
| 24807 | 13 | - use "ML-Systems/multithreading.ML"; | 
| 14 | - use "ML-Systems/time_limit.ML"; | |
| 23826 
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
 wenzelm parents: 
23139diff
changeset | 15 | - use "ML-Systems/alice.ML"; | 
| 
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
 wenzelm parents: 
23139diff
changeset | 16 | - use "ROOT.ML"; | 
| 
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
 wenzelm parents: 
23139diff
changeset | 17 | - Session.finish (); | 
| 22563 | 18 | *) | 
| 19 | ||
| 24597 | 20 | val ml_system_fix_ints = false; | 
| 21 | ||
| 22563 | 22 | fun exit 0 = (OS.Process.exit OS.Process.success): unit | 
| 23 | | exit _ = OS.Process.exit OS.Process.failure; | |
| 24 | ||
| 25 | ||
| 26 | (** ML system related **) | |
| 27 | ||
| 28 | (*low-level pointer equality*) | |
| 29 | fun pointer_eq (_: 'a, _: 'a) = false; | |
| 30 | ||
| 24809 
41a21f59f74d
integer compatibility: added wrapper for structure Time;
 wenzelm parents: 
24807diff
changeset | 31 | |
| 
41a21f59f74d
integer compatibility: added wrapper for structure Time;
 wenzelm parents: 
24807diff
changeset | 32 | (* integer compatibility -- downgraded IntInf *) | 
| 
41a21f59f74d
integer compatibility: added wrapper for structure Time;
 wenzelm parents: 
24807diff
changeset | 33 | |
| 
41a21f59f74d
integer compatibility: added wrapper for structure Time;
 wenzelm parents: 
24807diff
changeset | 34 | structure Time = | 
| 
41a21f59f74d
integer compatibility: added wrapper for structure Time;
 wenzelm parents: 
24807diff
changeset | 35 | struct | 
| 
41a21f59f74d
integer compatibility: added wrapper for structure Time;
 wenzelm parents: 
24807diff
changeset | 36 | open Time; | 
| 
41a21f59f74d
integer compatibility: added wrapper for structure Time;
 wenzelm parents: 
24807diff
changeset | 37 | val fromMilliseconds = Time.fromMilliseconds o IntInf.fromInt; | 
| 
41a21f59f74d
integer compatibility: added wrapper for structure Time;
 wenzelm parents: 
24807diff
changeset | 38 | val fromSeconds = Time.fromSeconds o IntInf.fromInt; | 
| 
41a21f59f74d
integer compatibility: added wrapper for structure Time;
 wenzelm parents: 
24807diff
changeset | 39 | end; | 
| 
41a21f59f74d
integer compatibility: added wrapper for structure Time;
 wenzelm parents: 
24807diff
changeset | 40 | |
| 24807 | 41 | structure IntInf = | 
| 42 | struct | |
| 43 | fun divMod (x, y) = (x div y, x mod y); | |
| 44 | open Int; | |
| 45 | end; | |
| 46 | ||
| 22563 | 47 | |
| 48 | (* restore old-style character / string functions *) | |
| 49 | ||
| 50 | exception Ord; | |
| 51 | fun ord "" = raise Ord | |
| 52 | | ord s = Char.ord (String.sub (s, 0)); | |
| 53 | ||
| 22575 | 54 | val chr = String.str o chr; | 
| 55 | val explode = map String.str o String.explode; | |
| 22563 | 56 | val implode = String.concat; | 
| 57 | ||
| 58 | ||
| 59 | (* Poly/ML emulation *) | |
| 60 | ||
| 61 | fun quit () = exit 0; | |
| 62 | ||
| 24329 | 63 | fun get_print_depth () = ! Print.depth; | 
| 22563 | 64 | fun print_depth n = Print.depth := n; | 
| 65 | ||
| 66 | ||
| 67 | (* compiler-independent timing functions *) | |
| 68 | ||
| 69 | structure Timer = | |
| 70 | struct | |
| 71 | open Timer; | |
| 72 | type cpu_timer = unit; | |
| 73 | fun startCPUTimer () = (); | |
| 74 |   fun checkCPUTimer () = {sys = Time.zeroTime, usr = Time.zeroTime};
 | |
| 75 | fun checkGCTime () = Time.zeroTime; | |
| 76 | end; | |
| 77 | ||
| 78 | fun start_timing () = | |
| 79 | let val CPUtimer = Timer.startCPUTimer(); | |
| 80 | val time = Timer.checkCPUTimer(CPUtimer) | |
| 81 | in (CPUtimer,time) end; | |
| 82 | ||
| 83 | fun end_timing (CPUtimer, {sys,usr}) =
 | |
| 84 | let open Time (*...for Time.toString, Time.+ and Time.- *) | |
| 85 |       val {sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer)
 | |
| 86 | in "User " ^ toString (usr2-usr) ^ | |
| 87 | " All "^ toString (sys2-sys + usr2-usr) ^ | |
| 88 | " secs" | |
| 89 | handle Time => "" | |
| 90 | end; | |
| 91 | ||
| 92 | fun check_timer timer = | |
| 93 | let | |
| 94 |     val {sys, usr} = Timer.checkCPUTimer timer;
 | |
| 95 | val gc = Timer.checkGCTime timer; (* FIXME already included in usr? *) | |
| 96 | in (sys, usr, gc) end; | |
| 97 | ||
| 98 | ||
| 99 | (*prompts*) | |
| 100 | fun ml_prompts p1 p2 = (); | |
| 101 | ||
| 102 | (*dummy implementation*) | |
| 103 | fun profile (n: int) f x = f x; | |
| 104 | ||
| 105 | (*dummy implementation*) | |
| 106 | fun exception_trace f = f (); | |
| 107 | ||
| 108 | (*dummy implementation*) | |
| 109 | fun print x = x; | |
| 110 | ||
| 111 | ||
| 24290 | 112 | (* toplevel pretty printing (see also Pure/pure_setup.ML) *) | 
| 22563 | 113 | |
| 114 | fun make_pp path pprint = (path, pprint); | |
| 115 | fun install_pp (path, pp) = (); | |
| 116 | ||
| 117 | ||
| 118 | (* ML command execution *) | |
| 119 | ||
| 26385 
ae7564661e76
ML runtime compilation: pass position, tuned signature;
 wenzelm parents: 
26227diff
changeset | 120 | fun use_text _ _ _ _ txt = (Compiler.eval txt; ()); | 
| 
ae7564661e76
ML runtime compilation: pass position, tuned signature;
 wenzelm parents: 
26227diff
changeset | 121 | fun use_file _ _ _ name = use name; | 
| 22563 | 122 | |
| 123 | ||
| 124 | ||
| 125 | (** interrupts **) | |
| 126 | ||
| 127 | exception Interrupt; | |
| 128 | ||
| 26084 
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
 wenzelm parents: 
24809diff
changeset | 129 | fun interruptible f x = f x; | 
| 
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
 wenzelm parents: 
24809diff
changeset | 130 | fun uninterruptible f x = f (fn (g: 'c -> 'd) => g) x; | 
| 22563 | 131 | |
| 132 | ||
| 133 | (* basis library fixes *) | |
| 134 | ||
| 135 | structure TextIO = | |
| 136 | struct | |
| 137 | open TextIO; | |
| 23139 
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
 wenzelm parents: 
22837diff
changeset | 138 | fun inputLine is = TextIO.inputLine is | 
| 22563 | 139 | handle IO.Io _ => raise Interrupt; | 
| 140 | end; | |
| 141 | ||
| 142 | ||
| 143 | ||
| 144 | (** OS related **) | |
| 145 | ||
| 23826 
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
 wenzelm parents: 
23139diff
changeset | 146 | val cd = OS.FileSys.chDir; | 
| 
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
 wenzelm parents: 
23139diff
changeset | 147 | val pwd = OS.FileSys.getDir; | 
| 
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
 wenzelm parents: 
23139diff
changeset | 148 | |
| 26226 | 149 | local | 
| 150 | ||
| 151 | fun read_file name = | |
| 152 | let val is = TextIO.openIn name | |
| 153 | in TextIO.inputAll is before TextIO.closeIn is end; | |
| 154 | ||
| 155 | fun write_file name txt = | |
| 156 | let val os = TextIO.openOut name | |
| 157 | in TextIO.output (os, txt) before TextIO.closeOut os end; | |
| 158 | ||
| 159 | in | |
| 160 | ||
| 161 | fun system_out script = | |
| 162 | let | |
| 163 | val script_name = OS.FileSys.tmpName (); | |
| 164 | val _ = write_file script_name script; | |
| 165 | ||
| 166 | val output_name = OS.FileSys.tmpName (); | |
| 167 | ||
| 168 | val status = | |
| 169 |       OS.Process.system ("perl -w \"$ISABELLE_HOME/lib/scripts/system.pl\" nogroup " ^
 | |
| 170 | script_name ^ " /dev/null " ^ output_name); | |
| 171 | val rc = if OS.Process.isSuccess status then 0 else 1; | |
| 172 | ||
| 173 | val output = read_file output_name handle IO.Io _ => ""; | |
| 174 | val _ = OS.FileSys.remove script_name handle OS.SysErr _ => (); | |
| 175 | val _ = OS.FileSys.remove output_name handle OS.SysErr _ => (); | |
| 176 | in (output, rc) end; | |
| 177 | ||
| 178 | end; | |
| 22563 | 179 | |
| 180 | structure OS = | |
| 181 | struct | |
| 182 | open OS; | |
| 183 | structure FileSys = | |
| 184 | struct | |
| 185 | fun fileId name = | |
| 26226 | 186 |       (case system_out ("perl -e '@_ = stat(q:" ^ name ^ ":); print $_[1]'") of
 | 
| 187 |         ("", _) => raise Fail "OS.FileSys.fileId"   (* FIXME IO.Io!? *)
 | |
| 188 | | (s, _) => (case Int.fromString s of NONE => raise Fail "OS.FileSys.fileId" | SOME i => i)); | |
| 22563 | 189 | val compare = Int.compare; | 
| 190 | open FileSys; | |
| 191 | end; | |
| 192 | end; | |
| 193 | ||
| 26227 | 194 | fun string_of_pid _ = raise Fail "string_of_pid undefined"; | 
| 195 | ||
| 22563 | 196 | fun getenv var = | 
| 197 | (case OS.Process.getEnv var of | |
| 198 | NONE => "" | |
| 199 | | SOME txt => txt); |