| author | wenzelm | 
| Sat, 19 Nov 2005 14:21:05 +0100 | |
| changeset 18208 | dbdcf366db53 | 
| parent 17824 | 36b2978d339a | 
| child 18384 | fa38cca42913 | 
| permissions | -rw-r--r-- | 
| 9254 | 1 | (* Title: Pure/ML-Systems/mosml.ML | 
| 2 | ID: $Id$ | |
| 3 | Author: Lawrence C Paulson, Cambridge University Computer Laboratory | |
| 4 | Copyright 1999 University of Cambridge | |
| 5 | ||
| 17491 | 6 | Compatibility file for Moscow ML 2.01 | 
| 9254 | 7 | |
| 17491 | 8 | NOTE: saving images does not work; may run it interactively as follows: | 
| 9254 | 9 | |
| 16469 | 10 | $ cd ~~/src/Pure | 
| 9254 | 11 | $ isabelle RAW_ML_SYSTEM | 
| 12 | > val ml_system = "mosml"; | |
| 13 | > use "ML-Systems/mosml.ML"; | |
| 14 | > use "ROOT.ML"; | |
| 16470 | 15 | > Session.finish (); | 
| 16 | > cd "../HOL"; | |
| 17 | > use "ROOT.ML"; | |
| 9254 | 18 | *) | 
| 19 | ||
| 20 | (** ML system related **) | |
| 21 | ||
| 16517 | 22 | load "Obj"; | 
| 9254 | 23 | load "Bool"; | 
| 24 | load "Int"; | |
| 25 | load "Real"; | |
| 26 | load "ListPair"; | |
| 27 | load "OS"; | |
| 28 | load "Process"; | |
| 29 | load "FileSys"; | |
| 30 | ||
| 16517 | 31 | (*low-level pointer equality*) | 
| 32 | local val cast : 'a -> int = Obj.magic | |
| 33 | in fun pointer_eq (x:'a, y:'a) = (cast x = cast y) end; | |
| 34 | ||
| 16469 | 35 | (*proper implementation available?*) | 
| 36 | structure IntInf = | |
| 37 | struct | |
| 38 | open Int; | |
| 39 | end; | |
| 40 | ||
| 41 | structure Real = | |
| 42 | struct | |
| 43 | open Real; | |
| 44 | val realFloor = real o floor; | |
| 45 | end; | |
| 46 | ||
| 17491 | 47 | structure String = | 
| 48 | struct | |
| 49 | fun isSuffix s1 s2 = | |
| 50 | let val n1 = size s1 and n2 = size s2 | |
| 51 | in if n1 = n2 then s1 = s2 else n1 <= n2 andalso String.substring (s2, n2 - n1, n1) = s1 end; | |
| 52 | open String; | |
| 53 | end; | |
| 54 | ||
| 16469 | 55 | structure Time = | 
| 56 | struct | |
| 57 | open Time; | |
| 58 | fun toString t = Time.toString t | |
| 59 | handle Overflow => Real.toString (Time.toReal t); (*workaround Y2004 bug*) | |
| 60 | end; | |
| 61 | ||
| 9254 | 62 | structure OS = | 
| 16469 | 63 | struct | 
| 9254 | 64 | open OS | 
| 65 | structure Process = Process | |
| 66 | structure FileSys = FileSys | |
| 16469 | 67 | end; | 
| 16993 | 68 | |
| 9254 | 69 | (*limit the printing depth*) | 
| 70 | fun print_depth n = | |
| 71 | (Meta.printDepth := n div 2; | |
| 72 | Meta.printLength := n); | |
| 73 | ||
| 74 | (*interface for toplevel pretty printers, see also Pure/install_pp.ML*) | |
| 75 | (*the documentation refers to an installPP but I couldn't fine it!*) | |
| 76 | fun make_pp path pprint = (); | |
| 77 | fun install_pp _ = (); | |
| 78 | ||
| 16681 | 79 | (*dummy implementation*) | 
| 80 | fun ml_prompts p1 p2 = (); | |
| 81 | ||
| 82 | (*dummy implementation*) | |
| 16660 | 83 | fun profile (n: int) f x = f x; | 
| 84 | ||
| 16681 | 85 | (*dummy impelemtation*) | 
| 86 | fun exception_trace f = f (); | |
| 9254 | 87 | |
| 88 | ||
| 89 | (** Compiler-independent timing functions **) | |
| 90 | ||
| 91 | load "Timer"; | |
| 92 | ||
| 14519 
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
 skalberg parents: 
12988diff
changeset | 93 | use "ML-Systems/cpu-timer-gc.ML"; | 
| 9254 | 94 | |
| 14851 
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
 webertj parents: 
14519diff
changeset | 95 | (* bounded time execution *) | 
| 
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
 webertj parents: 
14519diff
changeset | 96 | |
| 
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
 webertj parents: 
14519diff
changeset | 97 | (* FIXME proper implementation available? *) | 
| 
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
 webertj parents: 
14519diff
changeset | 98 | |
| 
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
 webertj parents: 
14519diff
changeset | 99 | structure TimeLimit : sig | 
| 
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
 webertj parents: 
14519diff
changeset | 100 | exception TimeOut | 
| 
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
 webertj parents: 
14519diff
changeset | 101 |    val timeLimit : Time.time -> ('a -> 'b) -> 'a -> 'b
 | 
| 
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
 webertj parents: 
14519diff
changeset | 102 | end = struct | 
| 
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
 webertj parents: 
14519diff
changeset | 103 | exception TimeOut | 
| 
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
 webertj parents: 
14519diff
changeset | 104 | fun timeLimit t f x = | 
| 
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
 webertj parents: 
14519diff
changeset | 105 | f x; | 
| 
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
 webertj parents: 
14519diff
changeset | 106 | end; | 
| 9254 | 107 | |
| 16517 | 108 | |
| 9254 | 109 | (* ML command execution *) | 
| 110 | ||
| 111 | (*Can one redirect 'use' directly to an instream?*) | |
| 112 | fun use_text _ _ txt = | |
| 113 | let | |
| 114 | val tmp_name = FileSys.tmpName (); | |
| 115 | val tmp_file = TextIO.openOut tmp_name; | |
| 116 | in | |
| 117 | TextIO.output (tmp_file, txt); | |
| 118 | TextIO.closeOut tmp_file; | |
| 119 | use tmp_name; | |
| 120 | FileSys.remove tmp_name | |
| 121 | end; | |
| 122 | ||
| 123 | ||
| 124 | ||
| 16993 | 125 | (** interrupts **) (*Note: may get into race conditions*) | 
| 9254 | 126 | |
| 127 | (* FIXME proper implementation available? *) | |
| 128 | ||
| 129 | exception Interrupt; | |
| 130 | ||
| 16993 | 131 | fun ignore_interrupt f x = f x; | 
| 12988 | 132 | fun raise_interrupt f x = f x; | 
| 9254 | 133 | |
| 134 | ||
| 135 | ||
| 136 | (** OS related **) | |
| 137 | ||
| 138 | (* system command execution *) | |
| 139 | ||
| 140 | (*execute Unix command which doesn't take any input from stdin and | |
| 141 | sends its output to stdout; could be done more easily by Unix.execute, | |
| 142 | but that function doesn't use the PATH*) | |
| 143 | fun execute command = | |
| 144 | let | |
| 145 | val tmp_name = FileSys.tmpName (); | |
| 16993 | 146 | val is = (Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name); | 
| 9254 | 147 | val result = TextIO.inputAll is; | 
| 148 | in | |
| 149 | TextIO.closeIn is; | |
| 150 | FileSys.remove tmp_name; | |
| 151 | result | |
| 152 | end; | |
| 153 | ||
| 154 | (*plain version; with return code*) | |
| 155 | fun system cmd = | |
| 156 | if Process.system cmd = Process.success then 0 else 1; | |
| 157 | ||
| 158 | ||
| 17824 | 159 | val string_of_pid = Int.toString; | 
| 160 | ||
| 161 | ||
| 9254 | 162 | (* getenv *) | 
| 163 | ||
| 164 | fun getenv var = | |
| 165 | (case Process.getEnv var of | |
| 166 | NONE => "" | |
| 167 | | SOME txt => txt); |