-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
error.c
766 lines (743 loc) · 24.3 KB
/
error.c
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include "eisl.h"
#include "fmt.h"
#include "except.h"
#include "str.h"
#include "mem.h"
static int outc(int c)
{
return fputc(c, stderr);
}
static inline void ESCERRFRED()
{
tputs(tparm(set_a_foreground, COLOR_RED), 1, outc);
}
static inline void ESCERRFORG()
{
tputs(exit_attribute_mode, 1, outc);
}
// -------error------
// for compiler
int ILOSerror(int fun, int arg)
{
error(NOT_EXIST_METHOD, GET_NAME(fun), arg, 0);
return (NIL);
}
void error(int errnum, const char *fun, int arg, int th)
{
int initargs, i;
char fun1[SYMSIZE];
#ifndef WITHOUT_CURSES
// restore repl_flag
repl_flag = org_repl_flag;
#endif
// fold to upper letter.
for (i = 0; i < (int) strlen(fun); i++) {
fun1[i] = toupper(fun[i]);
}
fun1[i] = '\0';
// clear generic-function data.
generic_func = NIL;
generic_vars = NIL;
switch (errnum) {
case DIV_ZERO:
initargs =
list6(make_sym("format-string"),
make_str("division by zero at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cdivision_by_zero, initargs), NIL,
th);
break;
case UNDEF_VAR:
initargs =
list10(make_sym("format-string"),
make_str("Unbound variable at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("name"), make_sym("UNDEF-VAR"),
make_sym("namespace"), make_sym("VARIABLE"));
signal_condition(make_instance(cunbound_variable, initargs), NIL,
th);
break;
case UNDEF_FUN:
initargs =
list10(make_sym("format-string"),
make_str("Unbound function at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("name"),
make_sym("UNDEF-FUNC"), make_sym("namespace"),
make_sym("FUNCTION"));
signal_condition(make_instance(cundefined_function, initargs),
NIL, th);
break;
case UNDEF_DYN:
initargs =
list10(make_sym("format-string"),
make_str("Unbound dynamic variable at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("name"),
make_sym("UNDEF-DYNAMIC-VAR"), make_sym("namespace"),
make_sym("DYNAMIC-VARIABLE"));
signal_condition(make_instance(cunbound_variable, initargs), NIL,
th);
break;
case UNDEF_CLASS:
initargs =
list10(make_sym("format-string"),
make_str("Unbound class at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("name"), arg,
make_sym("namespace"), make_sym(fun1));
signal_condition(make_instance(cundefined_entity, initargs), NIL,
th);
break;
case UNDEF_TAG:
initargs =
list6(make_sym("format-string"), make_str("Unbound tag at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(ccontrol_error, initargs), NIL, th);
break;
case WRONG_ARGS:
initargs =
list6(make_sym("format-string"),
make_str("Wrong arguments at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case NOT_EXIST_ARG:
initargs =
list6(make_sym("format-string"),
make_str("Not exist argument at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case NOT_NUM:
initargs =
list10(make_sym("format-string"), make_str("Not a number at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cnumber);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_POSITIVE:
initargs =
list10(make_sym("format-string"),
make_str("Not a positive number at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cnumber);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case FLT_OVERF:
initargs =
list10(make_sym("format-string"),
make_str("Floating number overflow at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cfloat);
signal_condition(make_instance(cfloating_point_overflow, initargs),
make_str
("Continuing ignores floating point overflow and the calculation returns infinity"),
th);
break;
case FLT_UNDERF:
initargs =
list10(make_sym("format-string"),
make_str("Floating number underflow at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cfloat);
signal_condition(make_instance
(cfloating_point_underflow, initargs),
make_str
("Continuing ignores floating point underflow and the calculation returns zero"),
th);
break;
case FLT_OUT_OF_DOMAIN:
initargs =
list10(make_sym("format-string"),
make_str("Floating number out of domain at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cfloat);
signal_condition(make_instance(cerror, initargs), NIL, th);
break;
case OUT_OF_REAL:
initargs =
list10(make_sym("format-string"),
make_str("Number out of real at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cfloat);
signal_condition(make_instance(cerror, initargs), NIL, th);
break;
case NOT_INT:
initargs =
list10(make_sym("format-string"),
make_str("Not an integer at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cinteger);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_FLT:
initargs =
list10(make_sym("format-string"),
make_str("Not a float number at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cfloat);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_STR:
initargs =
list10(make_sym("format-string"), make_str("Not a string at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cstring);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_CHAR:
initargs =
list10(make_sym("format-string"),
make_str("Not a character at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), ccharacter);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_LIST:
initargs =
list10(make_sym("format-string"), make_str("Not a list at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), clist);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_CONS:
initargs =
list10(make_sym("format-string"), make_str("Not a cons at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), ccons);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_VEC:
initargs =
list10(make_sym("format-string"), make_str("Not a vector at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cbasic_vector);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_ARR:
initargs =
list10(make_sym("format-string"), make_str("Not an array at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cbasic_array);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_SYM:
initargs =
list10(make_sym("format-string"), make_str("Not a symbol at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), csymbol);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_FUNC:
initargs =
list10(make_sym("format-string"),
make_str("Not a function at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cfunction);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_STREAM:
initargs =
list10(make_sym("format-string"), make_str("Not a stream at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cstream);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_STREAM_ERROR:
initargs =
list10(make_sym("format-string"), make_str("Not a stream at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cstream_error);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_IN_STREAM:
initargs =
list10(make_sym("format-string"),
make_str("Not an input stream at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cstream);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_OUT_STREAM:
initargs =
list10(make_sym("format-string"),
make_str("Not an output stream at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cstream);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_INSTANCE:
initargs =
list10(make_sym("format-string"),
make_str("Not an instance at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cobject);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_CLASS:
initargs =
list10(make_sym("format-string"), make_str("Not a class at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cobject);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_BASIC_ARRAY:
initargs =
list10(make_sym("format-string"), make_str("Not domain at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cbasic_array);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_VECARR:
initargs =
list10(make_sym("format-string"),
make_str("Not a vector or an array at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cgeneral_array_star);
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case ILLEGAL_RPAREN:
initargs =
list6(make_sym("format-string"),
make_str("Illegal right parenthesis at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case ILLEGAL_INPUT:
initargs =
list6(make_sym("format-string"), make_str("Illegal input at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case ILLEGAL_FORM:
initargs =
list6(make_sym("format-string"), make_str("Illegal form at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cerror, initargs), NIL, th);
break;
case IMPROPER_FORM:
initargs =
list6(make_sym("format-string"), make_str("Illegal form at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case ILLEGAL_ARGS:
initargs =
list6(make_sym("format-string"),
make_str("Illegal argument at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case IMPROPER_ARGS:
initargs =
list6(make_sym("format-string"),
make_str("Improper arguments at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cerror, initargs), NIL, th);
break;
case OUT_OF_RANGE:
initargs =
list6(make_sym("format-string"), make_str("Out of range at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case OUT_OF_DOMAIN:
initargs =
list6(make_sym("format-string"), make_str("Out of domain at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case NOT_COMPUTABLE:
initargs =
list6(make_sym("format-string"),
make_str("Not computable at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case CANT_MODIFY:
initargs =
list6(make_sym("format-string"), make_str("Can't modify at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case CANT_OPEN:
initargs =
list6(make_sym("format-string"),
make_str("Can't open a file at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cstream_error, initargs), NIL, th);
break;
case CANT_CREATE:
initargs =
list6(make_sym("format-string"),
make_str
("Can't create instance for system defined or abstract class at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cerror, initargs), NIL, th);
break;
case CANT_PARSE:
initargs =
list10(make_sym("format-string"),
make_str("Can't parse number at "),
make_sym("format-arguments"), arg, make_sym("object"),
arg, make_sym("string"), arg,
make_sym("expected-class"), cnumber);
signal_condition(make_instance(cparse_error, initargs), NIL, th);
break;
case CANT_ASSURE:
initargs =
list6(make_sym("format-string"), make_str("Can't assure at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case CTRL_OVERF:
initargs =
list6(make_sym("format-string"),
make_str("Control stack over flow at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(ccontrol_error, initargs), NIL, th);
break;
case END_STREAM:
initargs =
list8(make_sym("format-string"), make_str("End of stream at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("stream"), arg);
signal_condition(make_instance(cend_of_stream, initargs), NIL, th);
break;
case MALLOC_OVERF:
initargs =
list6(make_sym("format-string"),
make_str("Memory allocate over flow at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cstorage_exhausted, initargs), NIL,
th);
break;
case NOT_EXIST_METHOD:
initargs =
list6(make_sym("format-string"),
make_str("Not exist matched method at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cerror, initargs), NIL, th);
break;
case HAS_COMMON_CLASS:
initargs =
list6(make_sym("format-string"),
make_str("Super class has common parents at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cerror, initargs), NIL, th);
break;
case ILLEGAL_CLASS:
initargs =
list6(make_sym("format-string"),
make_str
("Next method allows only primary and :around method at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cclass_error, initargs), NIL, th);
break;
case NOT_TOP_LEVEL:
initargs =
list6(make_sym("format-string"),
make_str("Definition must be on top level at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cerror, initargs), NIL, th);
break;
case CANT_REDEFINE:
initargs =
list6(make_sym("format-string"),
make_str("Can't modify system defined class at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cerror, initargs), NIL, th);
break;
case STACK_OVERF:
initargs =
list6(make_sym("format-string"), make_str("Stack over flow "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case SHELTER_OVERF:
initargs =
list6(make_sym("format-string"),
make_str("Shelter over flow "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case VARIABLE_OVERF:
initargs =
list6(make_sym("format-string"),
make_str("Shelter over flow "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case STACK_UNDERF:
initargs =
list6(make_sym("format-string"), make_str("Stack under flow "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case SHELTER_UNDERF:
initargs =
list6(make_sym("format-string"),
make_str("Shelter under flow "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case SYSTEM_ERR:
initargs =
list6(make_sym("format-string"), make_str("system error "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case RESOURCE_ERR:
gbc();
initargs =
list6(make_sym("format-string"), make_str("resource error "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cprogram_error, initargs), NIL, th);
break;
case SERIOUS_ERR:
initargs =
list10(make_sym("format-string"),
make_str("Serious condition at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cserious_condition);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case ARITHMETIC_ERR:
initargs =
list10(make_sym("format-string"),
make_str("Arithmetic error at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), carithmetic_error);
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case DOMAIN_ERR:
initargs =
list10(make_sym("format-string"), make_str("Domain error at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), car(arg),
make_sym("expected-class"), cdr(arg));
signal_condition(make_instance(cdomain_error, initargs), NIL, th);
break;
case UNDEF_ENTITY:
initargs =
list10(make_sym("format-string"),
make_str("Undefined entity error at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), cundefined_entity);
signal_condition(make_instance(cundefined_entity, initargs), NIL,
th);
break;
case SIMPLE_ERR:
initargs =
list10(make_sym("format-string"), make_str("Simple error at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1), make_sym("object"), arg,
make_sym("expected-class"), csimple_error);
signal_condition(make_instance(csimple_error, initargs), NIL, th);
break;
case EXHAUSTED_ERR:
initargs =
list6(make_sym("format-string"),
make_str("Exhausted error at "),
make_sym("format-arguments"), arg, make_sym("function"),
make_sym(fun1));
signal_condition(make_instance(cstorage_exhausted, initargs), NIL,
th);
break;
}
}
/*
* x = class y = continuable string/NIL
*/
int signal_condition(int x, int y, int th)
{
int str, args, fun, ret;
error_flag = true;
if (y == NIL)
SET_OPT(x, NOTCONT);
else {
SET_OPT(x, CONTINUABLE);
TRY heap[x].name = Str_dup(GET_NAME(y), 1, 0, 1);
EXCEPT(Mem_Failed) error(MALLOC_OVERF, "signal-condition", NIL,
th);
END_TRY;
}
if (ignore_flag) {
block_pt = 0;
handling_resource_err = false;
RAISE(Ignored_Error);
}
if (parallel_flag) {
handling_resource_err = false;
signal_condition_x = x;
signal_condition_y = y;
RAISE(Exit_Thread);
}
if (process_flag) {
handling_resource_err = false;
signal_condition_x = x;
signal_condition_y = y;
Fmt_print("\x15");
fflush(stdout);
RAISE(Exit_Process);
}
if (network_flag) {
handling_resource_err = false;
signal_condition_x = x;
signal_condition_y = y;
printf("catch error\n");
send_to_parent(make_sym("\x15"));
RAISE(Exit_Network);
}
if (open_flag && error_handler == NIL) {
fclose(GET_PORT(input_stream));
open_flag = false;
Fmt_print("around here line=%d column=%d\n", line, column);
}
if (error_handler != NIL) {
int handler;
handler = car(error_handler);
/* if error is continuable, hold error_handler */
if (y == NIL) {
error_handler1 = error_handler;
error_handler = cdr(error_handler);
}
ret = setjmp(cont_buf);
if (ret == 0) {
return (apply(handler, list1(x), 0));
} else if (ret == 1) {
return (cont_arg);
}
}
/* resolve unwind-protect */
if (unwind_pt > 0) {
unwind_pt--;
while (unwind_pt >= 0) {
apply(unwind_buf[unwind_pt], NIL, 0);
unwind_pt--;
}
unwind_pt = 0;
unwind_nest = 0;
}
// initialize block-pointer after unwind resolve
block_pt = 0;
str = cdr(assoc(make_sym("a"), GET_CDR(x)));
args = cdr(assoc(make_sym("b"), GET_CDR(x)));
fun = cdr(assoc(make_sym("c"), GET_CDR(x)));
output_stream = error_stream;
if (repl_flag)
ESCERRFRED();
fputs(GET_NAME(str), stderr);
print(fun);
fputc(' ', stderr);
print(args);
fputc('\n', stderr);
if (repl_flag)
ESCERRFORG();
input_stream = standard_input;
output_stream = standard_output;
handling_resource_err = false;
if (!option_flag)
debugger(th);
else {
puts("Error occurred while executing command line options.");
option_flag = false;
}
RAISE(Restart_Repl);
return 0;
}
int makeusercond(int cl, int str, int arg)
{
int initarg;
initarg = list6(make_sym("format-string"), str,
make_sym("format-arguments"), arg,
make_sym("function"), make_sym(""));
return (make_instance(cl, initarg));
}
int get_error_handler(void)
{
return (error_handler);
}
int set_error_handler(int x)
{
error_handler = x;
return (x);
}
int get_error_flag(void)
{
return (error_flag);
}
int set_error_flag(int x)
{
error_flag = x;
return (x);
}
int restore_error_handler(void)
{
error_handler = error_handler1;
return (error_handler);
}