2004-07-16 02:26:21 -04:00
|
|
|
#include "factor.h"
|
|
|
|
|
|
|
|
void fatal_error(char* msg, CELL tagged)
|
|
|
|
{
|
2004-08-15 21:50:44 -04:00
|
|
|
fprintf(stderr,"Fatal error: %s %ld\n",msg,tagged);
|
2004-07-16 02:26:21 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2004-07-20 02:59:32 -04:00
|
|
|
void critical_error(char* msg, CELL tagged)
|
|
|
|
{
|
2004-08-15 21:50:44 -04:00
|
|
|
fprintf(stderr,"Critical error: %s %ld\n",msg,tagged);
|
2004-07-20 02:59:32 -04:00
|
|
|
save_image("factor.crash.image");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2004-07-16 02:26:21 -04:00
|
|
|
void throw_error(CELL error)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
dpush(error);
|
2004-07-16 02:26:21 -04:00
|
|
|
/* Execute the 'throw' word */
|
2004-08-23 01:13:09 -04:00
|
|
|
call(userenv[BREAK_ENV]);
|
2004-08-12 17:36:36 -04:00
|
|
|
|
2004-07-16 02:26:21 -04:00
|
|
|
/* Return to run() method */
|
2004-08-16 21:25:01 -04:00
|
|
|
siglongjmp(toplevel,1);
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
2004-10-03 16:07:48 -04:00
|
|
|
void primitive_throw(void)
|
|
|
|
{
|
|
|
|
throw_error(dpop());
|
|
|
|
}
|
|
|
|
|
2004-07-16 02:26:21 -04:00
|
|
|
void general_error(CELL error, CELL tagged)
|
|
|
|
{
|
2004-09-04 01:05:50 -04:00
|
|
|
CELL c = cons(error,cons(tagged,F));
|
2004-10-31 14:36:42 -05:00
|
|
|
if(userenv[BREAK_ENV] == F)
|
2004-08-23 02:15:10 -04:00
|
|
|
{
|
|
|
|
/* Crash at startup */
|
|
|
|
fprintf(stderr,"Error thrown before BREAK_ENV set\n");
|
2004-08-27 23:20:10 -04:00
|
|
|
fprintf(stderr,"Error #%ld\n",to_fixnum(error));
|
2004-08-23 02:15:10 -04:00
|
|
|
if(error == ERROR_TYPE)
|
|
|
|
{
|
2004-09-18 18:15:01 -04:00
|
|
|
CELL obj = untag_cons(untag_cons(tagged)->cdr)->car;
|
|
|
|
|
2004-08-27 23:20:10 -04:00
|
|
|
fprintf(stderr,"Type #%ld\n",to_fixnum(
|
2004-08-23 02:15:10 -04:00
|
|
|
untag_cons(tagged)->car));
|
2004-09-18 18:15:01 -04:00
|
|
|
fprintf(stderr,"Object %ld\n",obj);
|
|
|
|
fprintf(stderr,"Got type #%ld\n",type_of(obj));
|
2004-08-23 02:15:10 -04:00
|
|
|
}
|
2004-09-06 22:39:12 -04:00
|
|
|
fflush(stderr);
|
2004-08-23 02:15:10 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
2004-09-03 18:49:04 -04:00
|
|
|
throw_error(c);
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void type_error(CELL type, CELL tagged)
|
|
|
|
{
|
2004-09-04 01:05:50 -04:00
|
|
|
CELL c = cons(tag_fixnum(type),cons(tagged,F));
|
2004-09-03 18:49:04 -04:00
|
|
|
general_error(ERROR_TYPE,c);
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
2004-10-12 23:49:43 -04:00
|
|
|
void range_error(CELL tagged, FIXNUM index, CELL max)
|
2004-07-16 02:26:21 -04:00
|
|
|
{
|
2004-10-12 23:49:43 -04:00
|
|
|
CELL c = cons(tagged,cons(tag_integer(index),cons(tag_cell(max),F)));
|
2004-09-03 18:49:04 -04:00
|
|
|
general_error(ERROR_RANGE,c);
|
2004-07-24 17:37:42 -04:00
|
|
|
}
|