]> gitweb.factorcode.org Git - factor.git/blob - native/error.c
CHAR: notation for literal chars, native parser work
[factor.git] / native / error.c
1 #include "factor.h"
2
3 void fatal_error(char* msg, CELL tagged)
4 {
5         printf("Fatal error: %s %d\n",msg,tagged);
6         exit(1);
7 }
8
9 void critical_error(char* msg, CELL tagged)
10 {
11         printf("Critical error: %s %d\n",msg,tagged);
12         save_image("factor.crash.image");
13         exit(1);
14 }
15
16 void fix_stacks(void)
17 {
18         if(env.ds < env.ds_bot + sizeof(ARRAY))
19                 reset_datastack();
20         if(env.cs <= env.cs_bot + sizeof(ARRAY))
21                 reset_callstack();
22 }
23
24 void throw_error(CELL error)
25 {
26         fix_stacks();
27
28         dpush(env.dt);
29         env.dt = error;
30         /* Execute the 'throw' word */
31         cpush(env.cf);
32         env.cf = env.user[BREAK_ENV];
33         /* Return to run() method */
34         longjmp(toplevel,1);
35 }
36
37 void general_error(CELL error, CELL tagged)
38 {
39         CONS* c = cons(error,tag_cons(cons(tagged,F)));
40         throw_error(tag_cons(c));
41 }
42
43 void type_error(CELL type, CELL tagged)
44 {
45         CONS* c = cons(tag_fixnum(type),tag_cons(cons(tagged,F)));
46         general_error(ERROR_TYPE,tag_cons(c));
47 }
48
49 void range_error(CELL tagged, CELL index, CELL max)
50 {
51         CONS* c = cons(tagged,tag_cons(cons(tag_fixnum(index),
52                 tag_cons(cons(tag_fixnum(max),F)))));
53         general_error(ERROR_RANGE,c);
54 }