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)
{
if(STACK_UNDERFLOW(env.ds,env.ds_bot)
|| STACK_OVERFLOW(env.ds,env.ds_bot))
2004-07-20 02:59:32 -04:00
reset_datastack();
if(STACK_UNDERFLOW(env.cs,env.cs_bot)
|| STACK_OVERFLOW(env.cs,env.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 */
cpush(env.cf);
env.cf = env.user[BREAK_ENV];
if(env.cf == 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 */
longjmp(toplevel,1);
}
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));
}