1structure MLSYSPortable = 2struct 3 4exception Interrupt = SML90.Interrupt 5 6fun listDir s = 7 let 8 val ds = FileSys.openDir s 9 fun recurse acc = 10 case FileSys.readDir ds of 11 NONE => acc 12 | SOME f => recurse (f :: acc) 13 in 14 recurse [] before FileSys.closeDir ds 15 end 16 17fun pointer_eq (x: 'a, y: 'a) = PolyML.pointerEq (x, y) 18fun ref_to_int (x: 'a ref) = 0 (* needs fixing *) 19 20fun catch_SIGINT () = () 21 22fun md5sum s = 23 let 24 val mstate = MD5.update (MD5.init, Byte.stringToBytes s) 25 val hash = MD5.final mstate 26 in 27 MD5.toBase64String hash 28 end 29 30fun time f x = 31 let 32 fun p t = 33 let 34 val s = Time.fmt 3 t 35 in 36 case size (List.last (String.fields (fn x => x = #".") s)) of 37 3 => s 38 | 2 => s ^ "0" 39 | 1 => s ^ "00" 40 | _ => raise Fail "mlibPortable.time" 41 end 42 val c = Timer.startCPUTimer () 43 val r = Timer.startRealTimer () 44 fun pt () = 45 let 46 val {usr, sys} = Timer.checkCPUTimer c 47 val gc = Timer.checkGCTime c 48 val real = Timer.checkRealTimer r 49 in 50 print ("User: " ^ p usr ^ " System: " ^ p sys ^ 51 " GC: " ^ p gc ^ " Real: " ^ p real ^ "\n") 52 end 53 val y = f x handle e => (pt (); raise e) 54 val () = pt () 55 in 56 y 57 end 58 59structure HOLSusp = Susp 60 61fun reraise e = PolyML.Exception.reraise e 62 63fun make_counter {inc,init} = 64 let 65 val counter = Synchronized.var "counter" init 66 fun next () = Synchronized.change_result counter (fn i => (i, i + inc)) 67 in 68 next 69 end 70 71fun syncref init = 72 let 73 val v = Synchronized.var "Portable.syncref" init 74 in 75 {get = fn () => Synchronized.value v, 76 upd = fn f => Synchronized.change_result v f} 77 end 78 79end 80