factor/native/error.c

70 lines
1.4 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);
}
void fix_stacks(void)
{
2004-08-20 18:48:08 -04:00
if(STACK_UNDERFLOW(ds,ds_bot)
|| STACK_OVERFLOW(ds,ds_bot))
2004-07-20 02:59:32 -04:00
reset_datastack();
2004-08-20 18:48:08 -04:00
if(STACK_UNDERFLOW(cs,cs_bot)
|| STACK_OVERFLOW(cs,cs_bot))
2004-07-20 02:59:32 -04:00
reset_callstack();
}
2004-07-16 02:26:21 -04:00
void throw_error(CELL error)
{
2004-07-20 02:59:32 -04:00
fix_stacks();
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 general_error(CELL error, CELL tagged)
{
2004-07-20 02:59:32 -04:00
CONS* c = cons(error,tag_cons(cons(tagged,F)));
if(userenv[BREAK_ENV] == 0)
{
/* 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-08-27 23:20:10 -04:00
fprintf(stderr,"Type #%ld\n",to_fixnum(
untag_cons(tagged)->car));
2004-08-27 23:20:10 -04:00
fprintf(stderr,"Got type #%ld\n",type_of(
untag_cons(tagged)->cdr));
}
exit(1);
}
2004-07-16 02:26:21 -04:00
throw_error(tag_cons(c));
}
void type_error(CELL type, CELL tagged)
{
2004-07-20 02:59:32 -04:00
CONS* c = cons(tag_fixnum(type),tag_cons(cons(tagged,F)));
2004-07-16 02:26:21 -04:00
general_error(ERROR_TYPE,tag_cons(c));
}
void range_error(CELL tagged, CELL index, CELL max)
{
CONS* c = cons(tagged,tag_cons(cons(tag_fixnum(index),
tag_cons(cons(tag_fixnum(max),F)))));
2004-07-24 17:37:42 -04:00
general_error(ERROR_RANGE,tag_cons(c));
}