1signature ERRORMSG = 2sig 3 val anyErrors : bool ref 4 val fileName : string ref 5 val lineNum : int ref 6 val linePos : int list ref 7 val sourceStream : TextIO.instream ref 8 val error : int -> string -> unit 9 exception Error 10 val impossible : string -> 'a (* raises Error *) 11 val reset : unit -> unit 12end 13 14structure ErrorMsg : ERRORMSG = 15struct 16 17 val anyErrors = ref false 18 val fileName = ref "" 19 val lineNum = ref 1 20 val linePos = ref [1] 21 val sourceStream = ref TextIO.stdIn 22 23 fun reset() = (anyErrors:=false; 24 fileName:=""; 25 lineNum:=1; 26 linePos:=[1]; 27 sourceStream:=TextIO.stdIn) 28 29 exception Error 30 31 fun error pos (msg:string) = 32 let fun look(a::rest,n) = 33 if a<pos then app print [":", 34 Int.toString n, 35 ".", 36 Int.toString (pos-a)] 37 else look(rest,n-1) 38 | look _ = print "0.0" 39 in anyErrors := true; 40 print (!fileName); 41 look(!linePos,!lineNum); 42 print ":"; 43 print msg; 44 print "\n" 45 end 46 47 fun impossible msg = 48 (app print ["Error: Compiler bug: ",msg,"\n"]; 49 TextIO.flushOut TextIO.stdOut; 50 raise Error) 51 52end (* structure ErrorMsg *) 53 54