1: #include "0x.h"
2: #include "opcode.h"
3: #include "E.h"
4:
5: extern int errno;
6:
7: /*
8: * Routine error is called from onemt when a runtime error occurs.
9: * Its argument is the internal number of the error which occurred.
10: * See Edata, Emake etc.
11: */
12: error(perrno)
13: int perrno;
14: {
15: register int *ap, i;
16: register char *cp;
17: char *sep;
18: int disp[20], *mydp;
19: extern long stcnt;
20:
21: i = errno;
22: pmflush();
23: pmessage();
24: errno = i;
25: switch (perrno) {
26: case EINTR:
27: break;
28: case ECHR:
29: puts("Argument to chr out of range\n");
30: break;
31: case EDIVCHK:
32: puts("Div by zero\n");
33: break;
34: case EFDIVCHK:
35: puts("Floating divide by zero\n");
36: break;
37: case EFPOVFLO:
38: puts("Floating point overflow\n");
39: break;
40: case EHALT:
41: /*
42: nodump = 0;
43: */
44: puts("Call to procedure halt\n");
45: break;
46: case ENILPTR:
47: puts("Reference through a nil pointer\n");
48: break;
49: case EPASTEOF:
50: ferror("Tried to read past eof");
51: break;
52: case EREADIT:
53: ferror("Attempt to read, but open for writing");
54: break;
55: case EWRITEIT:
56: ferror("Attempt to write, but open for reading");
57: break;
58: case ETOODIGITS:
59: puts("Too many digits in number\n");
60: break;
61: case ESQRT:
62: puts("Negative argument to sqrt\n");
63: break;
64: case ESTKNEMP:
65: puts("Panic: stack not empty between statements\n");
66: break;
67: case ESUBSCR:
68: puts("Subscript out of range\n");
69: break;
70: case EREFINAF:
71: puts("Reference to an inactive file\n");
72: break;
73: case EWRITE:
74: case EOPEN:
75: case ECREATE:
76: case EREMOVE:
77: case ESEEK:
78: perror(file);
79: break;
80: case ELN:
81: puts("Non-positive argument to ln\n");
82: break;
83: case EBADOP:
84: puts("Panic: bad op code\n");
85: break;
86: case EBADINUM:
87: puts("Bad data found on integer read\n");
88: break;
89: case EBADFNUM:
90: puts("Bad data found on real read\n");
91: break;
92: case EGOTO:
93: puts("Panic: active frame not found in goto\n");
94: break;
95: case ECASE:
96: puts("Label not found in case\n");
97: break;
98: case EOUTOFMEM:
99: puts("Ran out of memory\n");
100: break;
101: case EALLOC:
102: puts("Panic: bad arg to alloc\n");
103: break;
104: case ECTTOT:
105: puts("Constructed set argument exceeds set bounds\n");
106: break;
107: case EMODCHK:
108: puts("Mod by zero\n");
109: break;
110: case ECLOSE:
111: ferror("Close failed?");
112: break;
113: case EARGV:
114: puts("Argument to argv out of range\n");
115: break;
116: case EPACK:
117: puts("Bad i to pack(a,i,z)\n");
118: break;
119: case EUNPACK:
120: puts("Bad i to unpack(z,a,i)\n");
121: break;
122: case ERANGE:
123: puts("Value out of range\n");
124: break;
125: case EASRT:
126: puts("Assertion failed\n");
127: break;
128: case EBIGGIE:
129: ferror("Integer number too large");
130: break;
131: case ESTLIM:
132: puts("Statement count limit exceeded\n");
133: break;
134: case ESTKOVFLO:
135: puts("Runtime stack overflow\n");
136: break;
137: default:
138: puts("Panic: unknown error\n");
139: }
140: if (nodump == 0) {
141: for (i = 0; i < 20; i++)
142: disp[i] = display[i];
143: mydp = dp;
144: sep = perrno == EINTR ? "\n\tInterrupted at " : "\n\tError at ";
145: if (lino <= 0)
146: exit(perrno);
147: for(;;) {
148: puts(sep);
149: sep = "\tCalled by ";
150: pputch('"');
151: ap = *mydp;
152: ap =+ 3;
153: cp = *ap++;
154: i = 8;
155: do
156: pputch(*cp++);
157: while (--i && *cp != ' ');
158: cp =+ i;
159: puts("\"+");
160: pwrite(O_WRIT2, 2, lino-cp->pint, 0);
161: puts(" near line ");
162: pwrite(O_WRIT2, 2, lino, 0);
163: pputch('\n');
164: *mydp = *ap++;
165: if (mydp <= &display[1]) {
166: for (i = 0; i < 20; i++)
167: display[i] = disp[i];
168: pmflush();
169: puts("\n");
170: if (discard)
171: puts("Execution terminated abnormally\n");
172: stmts();
173: exit(perrno);
174: }
175: mydp = *ap++;
176: ap++;
177: lino = *ap++;
178: if (lino <= 0)
179: break;
180: }
181: }
182: exit(perrno);
183: }
184:
185: stmts()
186: {
187: extern long stcnt;
188:
189: pwrite(O_WRIT4, 2, stcnt, 0);
190: puts(" statement");
191: if (stcnt != 1)
192: puts("s");
193: puts(" executed in");
194: stmttime();
195: }
196:
197: stmttime()
198: {
199: struct {
200: long utime, stime;
201: long cutime, cstime;
202: } tbuf;
203: long l;
204:
205: times(&tbuf);
206: l = tbuf.utime;
207: pwrite(O_WRIT82, (2 << 3) | 2, l / HZ + 0.005, 0, 2);
208: puts(" seconds cpu time\n");
209: }
210:
211: psexit()
212: {
213:
214: if (nodump == 1)
215: exit(0);
216: pmessage();
217: if (discard)
218: puts("Execution terminated\n");
219: stmts();
220: exit(0);
221: }
Defined functions
error
defined in line
12; used 5 times