-
Notifications
You must be signed in to change notification settings - Fork 1
/
errormsg.sml
48 lines (40 loc) · 1.09 KB
/
errormsg.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
signature ERRORMSG =
sig
val anyErrors : bool ref
val fileName : string ref
val lineNum : int ref
val linePos : int ref
val sourceStream : TextIO.instream ref
val error : (int*int)*(int*int) -> string -> unit
exception Error
val impossible : string -> 'a (* raises Error *)
val reset : unit -> unit
end
structure ErrorMsg : ERRORMSG =
struct
val anyErrors = ref false
val fileName = ref ""
val lineNum = ref 1
val linePos = ref 1
val sourceStream = ref TextIO.stdIn
fun reset() = (anyErrors:=false;
fileName:="";
lineNum:=1;
linePos:=1;
sourceStream:=TextIO.stdIn)
exception Error
fun error ((l1,c1),(l2,c2)) (msg:string) =
(anyErrors := true;
print (!fileName);
print " ";
print ((Int.toString l1) ^ "." ^ (Int.toString c1));
print " - ";
print ((Int.toString l2) ^ "." ^ (Int.toString c2));
print ":";
print msg;
print "\n")
fun impossible msg =
(app print ["Error: Compiler bug: ",msg,"\n"];
TextIO.flushOut TextIO.stdOut;
raise Error)
end (* structure ErrorMsg *)