factor/native/error.c

65 lines
1.3 KiB
C
Raw Normal View History

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)
{
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-07-16 02:26:21 -04:00
/* Return to run() method */
siglongjmp(toplevel,1);
2004-07-16 02:26:21 -04:00
}
void primitive_throw(void)
{
throw_error(dpop());
}
2004-07-16 02:26:21 -04:00
void general_error(CELL error, CELL tagged)
{
CELL c = cons(error,cons(tagged,F));
if(userenv[BREAK_ENV] == F)
{
/* 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));
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(
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));
}
fflush(stderr);
exit(1);
}
throw_error(c);
2004-07-16 02:26:21 -04:00
}
void type_error(CELL type, CELL tagged)
{
CELL c = cons(tag_fixnum(type),cons(tagged,F));
general_error(ERROR_TYPE,c);
2004-07-16 02:26:21 -04:00
}
void range_error(CELL tagged, FIXNUM index, CELL max)
2004-07-16 02:26:21 -04:00
{
CELL c = cons(tagged,cons(tag_integer(index),cons(tag_cell(max),F)));
general_error(ERROR_RANGE,c);
2004-07-24 17:37:42 -04:00
}