2004-07-16 02:26:21 -04:00
|
|
|
#include "factor.h"
|
|
|
|
|
|
|
|
void fatal_error(char* msg, CELL tagged)
|
|
|
|
{
|
2004-07-28 19:02:24 -04:00
|
|
|
printf("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-07-28 19:02:24 -04:00
|
|
|
printf("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-06 18:40:44 -04:00
|
|
|
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();
|
2004-08-06 18:40:44 -04:00
|
|
|
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();
|
|
|
|
|
2004-08-12 17:36:36 -04:00
|
|
|
dpush(error);
|
2004-07-16 02:26:21 -04:00
|
|
|
/* Execute the 'throw' word */
|
|
|
|
cpush(env.cf);
|
|
|
|
env.cf = env.user[BREAK_ENV];
|
2004-08-12 17:36:36 -04:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
void io_error(const char* func)
|
|
|
|
{
|
|
|
|
STRING* function = from_c_string(func);
|
|
|
|
STRING* error = from_c_string(strerror(errno));
|
|
|
|
|
|
|
|
CONS* c = cons(tag_object(function),tag_cons(
|
|
|
|
cons(tag_object(error),F)));
|
|
|
|
general_error(ERROR_IO,tag_cons(c));
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|