factor/native/error.c

62 lines
1.2 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-20 18:48:08 -04:00
cpush(callframe);
callframe = userenv[BREAK_ENV];
if(callframe == 0)
{
/* Crash at startup */
fatal_error("Error thrown before BREAK_ENV set",error);
}
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)));
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));
}