-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrormsg.sml
59 lines (49 loc) · 1.45 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
49
50
51
52
53
54
55
56
57
58
59
signature ERRORMSG =
sig
val anyErrors : bool ref
val fileName : string ref
val lineNum : int ref
val linePos : int list ref
val sourceStream : TextIO.instream ref
val error : int -> string -> unit
exception Error
val impossible : string -> 'a (* raises Error *)
exception Unimplemented
val unimplemented : unit -> 'a (* raises Unimplemented *)
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 eprint s = TextIO.output(TextIO.stdErr, s)
fun error pos (msg:string) = let
fun look (a::rest, n) =
if a < pos then
app eprint [":", Int.toString n, ".", Int.toString (pos-a)]
else look(rest, n-1)
| look _ = eprint "0.0"
in
anyErrors := true;
eprint(!fileName);
look(!linePos, !lineNum);
eprint ": ";
eprint msg;
eprint "\n"
end
fun impossible msg =
(app print ["Error: Compiler bug: ",msg,"\n"];
TextIO.flushOut TextIO.stdOut;
raise Error)
exception Unimplemented
fun unimplemented() = raise Unimplemented
end (* structure ErrorMsg *)