|
|
1.1 ! root 1: (* Copyright 1989 by AT&T Bell Laboratories *) ! 2: signature Startup = ! 3: sig ! 4: val core : System.Unsafe.object ! 5: val initial : System.Unsafe.object ! 6: val math : System.Unsafe.object ! 7: val name : string ! 8: end ! 9: ! 10: functor Loader ( S : Startup ) : sig end = ! 11: struct ! 12: ! 13: open Ref List String IO General System System.Unsafe ! 14: val boot : string -> ! 15: unit -> ! 16: ((object list -> (object * ByteArray.bytearray array)) * string list) ! 17: = System.Unsafe.boot ! 18: ! 19: val dict : (string*object) list ref = ! 20: ref [("Initial",S.initial),("Core",S.core),("Math",S.math)] ! 21: ! 22: val _ = pstruct := {core=S.core,math=S.math,initial=S.initial} ! 23: ! 24: exception Notfound_Loader ! 25: ! 26: fun lookup s = ! 27: let fun f ((s1,stru)::r) = if s=s1 then stru else f r ! 28: | f nil = raise Notfound_Loader ! 29: in f (!dict) ! 30: end ! 31: ! 32: fun enter pair = dict := pair::(!dict) ! 33: ! 34: fun readfile s = ! 35: let val stream = open_in s ! 36: val file = input stream (can_input stream) ! 37: in close_in stream; ! 38: file ! 39: end ! 40: ! 41: fun getmo s = ! 42: let fun f DATANIL = readfile s ! 43: | f (DATACONS(s',t,x)) = if s=s' then t else f x ! 44: in f System.Unsafe.datalist ! 45: end ! 46: ! 47: val say = output std_out ! 48: ! 49: fun getstruct s = ! 50: lookup s handle Notfound_Loader => ! 51: let val _ = (say "[Loading "; say s; say "]\n") ! 52: val g = getmo ("mo/" ^ s ^ ".mo"); ! 53: val (exec,sl) = boot g () ! 54: val saver = ref exec (* save a pointer for the garbage ! 55: collector *) ! 56: val structs = map getstruct sl ! 57: val _ = (say "[Executing "; say s; say "]\n") ! 58: val (str,profile) = exec structs ! 59: in enter (s,str); ! 60: System.Control.ProfileInternals.add profile; ! 61: saver := !saver; (* trickery for the g.c. *) ! 62: str ! 63: end ! 64: ! 65: val _ = (getstruct S.name; System.cleanup()) ! 66: (* this is the global exception handler of the sml system *) ! 67: handle Io s => ! 68: (say "uncaught Io exception (Loader): "; ! 69: say s; ! 70: say "\n"; ! 71: System.cleanup()) ! 72: | exn => ! 73: (say "uncaught exception (Loader): "; ! 74: say (exn_name exn); ! 75: say "\n"; ! 76: System.cleanup()) ! 77: ! 78: end (* functor Loader *)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.