factor/native/error.c

78 lines
1.3 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);
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
}
2004-11-09 12:29:25 -05:00
void general_error(CELL error, CELL tagged)
{
2005-03-15 16:50:08 -05:00
CELL thrown = cons(userenv[ERROR_ENV],cons(error,cons(tagged,F)));
throw_error(thrown,true);
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)
{
throw_error(cons(userenv[ERROR_ENV],
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
}