factor/native/error.c

82 lines
1.8 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);
2005-05-12 01:02:39 -04:00
factorbug();
2004-07-20 02:59:32 -04:00
}
2005-03-15 16:50:08 -05:00
void early_error(CELL error)
{
if(userenv[BREAK_ENV] == F)
{
/* Crash at startup */
fprintf(stderr,"Error during startup: ");
print_obj(error);
fprintf(stderr,"\n");
2005-05-12 01:02:39 -04:00
factorbug();
2005-03-15 16:50:08 -05:00
}
}
2004-11-09 12:29:25 -05:00
void throw_error(CELL error, bool keep_stacks)
2004-07-16 02:26:21 -04:00
{
2005-03-15 16:50:08 -05:00
early_error(error);
throwing = true;
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;
thrown_callframe = callframe;
thrown_executing = executing;
2004-07-16 02:26:21 -04:00
/* Return to run() method */
2005-10-11 21:46:14 -04:00
LONGJMP(toplevel,1);
2004-07-16 02:26:21 -04:00
}
2004-11-28 21:56:58 -05:00
void primitive_throw(void)
{
2005-09-17 22:25:18 -04:00
throw_error(dpop(),true);
2004-11-28 21:56:58 -05:00
}
2005-03-07 00:39:57 -05:00
void primitive_die(void)
{
2005-05-12 01:02:39 -04:00
factorbug();
2005-03-07 00:39:57 -05:00
}
2006-02-07 19:09:46 -05:00
void general_error(CELL error, CELL tagged, bool keep_stacks)
2004-11-09 12:29:25 -05:00
{
2005-03-15 16:50:08 -05:00
CELL thrown = cons(userenv[ERROR_ENV],cons(error,cons(tagged,F)));
2006-02-07 19:09:46 -05:00
throw_error(thrown,keep_stacks);
2004-11-09 12:29:25 -05:00
}
/* It is not safe to access 'ds' from a signal handler, so we just not
touch it */
void signal_error(int signal)
{
2006-02-07 19:09:46 -05:00
general_error(ERROR_SIGNAL,tag_fixnum(signal),false);
2004-07-16 02:26:21 -04:00
}
/* called from signal.c when a sigv tells us that we under/overflowed a page.
* The first bool is true if it was the return stack (otherwise it's the data
* stack) and the second bool is true if we overflowed it (otherwise we
* underflowed it) */
void signal_stack_error(bool is_return_stack, bool is_overflow)
{
2006-02-07 19:09:46 -05:00
CELL errors[] = { ERROR_DS_UNDERFLOW, ERROR_DS_OVERFLOW,
ERROR_CS_UNDERFLOW, ERROR_CS_OVERFLOW };
general_error(errors[is_return_stack * 2 + is_overflow],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));
2006-02-07 19:09:46 -05:00
general_error(ERROR_TYPE,c,true);
2004-07-16 02:26:21 -04:00
}