-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls9-error.nw
101 lines (83 loc) · 1.52 KB
/
ls9-error.nw
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
Error reporting and handling
<<ls9 globals>>=
full Trace[NTRACE];
full Tp = 0;
size_t Plimit = 0;
full Line = 1;
full Files = NIL;
full Symbols;
jmp_buf Restart;
jmp_buf Errtag;
full Handler = NIL;
full Glob;
full S_errtag, S_errval;
@
<<ls9 impl>>=
void clrtrace(void) {
int i;
for (i=0; i<NTRACE; i++) Trace[i] = NIL;
}
int gottrace(void) {
int i;
for (i=0; i<NTRACE; i++)
if (Trace[i] != NIL) return 1;
return 0;
}
void report(char *s, full x) {
full i, j, o;
o = set_outport(2);
prints("*** error: ");
prints(s);
if (x != UNDEF) {
prints(": ");
Plimit = 100;
prin(x);
Plimit = 0;
}
nl();
if (Files != NIL) {
prints("*** file: ");
printb(string(car(Files)));
prints(", line: ");
prints(ntoa((ifull)Line, 10));
nl();
}
if (gottrace()) {
prints("*** trace:");
i = Tp;
for (j=0; j<NTRACE; j++) {
if (i >= NTRACE) i = 0;
if (Trace[i] != NIL) {
prints(" ");
printb(symname(vector(Symbols)[Trace[i]]));
}
i++;
}
nl();
}
set_outport(o);
}
void error(char *s, full x) {
full n;
n = assq(S_errtag, Glob);
Handler = (NIL == n)? NIL: cadr(n);
if (Handler != NIL) {
n = assq(S_errval, Glob);
if (n != NIL && cadr(n) == Handler)
bindset(S_errval, mkstr(s, strlen(s)));
longjmp(Errtag, 1);
}
report(s, x);
longjmp(Restart, 1);
}
void expect(char *who, char *what, full got) {
char b[100];
sprintf(b, "%s: expected %s", who, what);
error(b, got);
}
void fatal(char *s) {
fprintf(stderr, "*** fatal error: ");
fprintf(stderr, "%s\n", s);
exit(EXIT_FAILURE);
}
@