factor/native/error.c

82 lines
1.6 KiB
C
Raw Normal View History

2004-07-16 02:26:21 -04:00
#include "factor.h"
2004-11-06 15:51:17 -05:00
void init_errors(void)
{
thrown_error = F;
}
2004-07-16 02:26:21 -04:00
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-11-09 12:29:25 -05:00
void throw_error(CELL error, bool keep_stacks)
2004-07-16 02:26:21 -04:00
{
2004-11-06 15:51:17 -05:00
thrown_error = error;
2004-11-09 12:29:25 -05:00
thrown_keep_stacks = keep_stacks;
thrown_ds = ds;
thrown_cs = cs;
2004-07-16 02:26:21 -04:00
/* Return to run() method */
2004-12-10 21:39:45 -05:00
#ifdef WIN32
longjmp(toplevel,1);
#else
siglongjmp(toplevel,1);
2004-12-10 21:39:45 -05:00
#endif
2004-07-16 02:26:21 -04:00
}
2004-11-09 12:29:25 -05:00
void early_error(CELL error)
2004-07-16 02:26:21 -04:00
{
if(userenv[BREAK_ENV] == F)
{
/* Crash at startup */
2004-11-28 21:56:58 -05:00
if(type_of(error) == FIXNUM_TYPE)
fprintf(stderr,"Error: %ld\n",to_fixnum(error));
else if(type_of(error) == STRING_TYPE)
fprintf(stderr,"Error: %s\n",to_c_string(untag_string(error)));
fflush(stderr);
exit(1);
}
2004-11-09 12:29:25 -05:00
}
2004-11-28 21:56:58 -05:00
void primitive_throw(void)
{
CELL error = dpop();
early_error(error);
throw_error(error,true);
}
2004-11-09 12:29:25 -05:00
void general_error(CELL error, CELL tagged)
{
early_error(error);
throw_error(cons(error,cons(tagged,F)),true);
}
/* It is not safe to access 'ds' from a signal handler, so we just not
touch it */
void signal_error(int signal)
{
early_error(ERROR_SIGNAL);
throw_error(cons(ERROR_SIGNAL,cons(tag_fixnum(signal),F)),false);
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, F_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
}