some cleanup of run-file

cvs
Slava Pestov 2004-07-20 06:59:32 +00:00
parent 2d778fb77f
commit f2b186ffc7
9 changed files with 48 additions and 20 deletions

View File

@ -6,8 +6,25 @@ void fatal_error(char* msg, CELL tagged)
exit(1); exit(1);
} }
void critical_error(char* msg, CELL tagged)
{
printf("Critical error: %s %d\n",msg,tagged);
save_image("factor.crash.image");
exit(1);
}
void fix_stacks(void)
{
if(env.ds < env.ds_bot + sizeof(ARRAY))
reset_datastack();
if(env.cs <= env.cs_bot + sizeof(ARRAY))
reset_callstack();
}
void throw_error(CELL error) void throw_error(CELL error)
{ {
fix_stacks();
dpush(env.dt); dpush(env.dt);
env.dt = error; env.dt = error;
/* Execute the 'throw' word */ /* Execute the 'throw' word */
@ -19,14 +36,14 @@ void throw_error(CELL error)
void general_error(CELL error, CELL tagged) void general_error(CELL error, CELL tagged)
{ {
CONS* c = cons(error,tag_cons( CONS* c = cons(error,tag_cons(cons(tagged,F)));
cons(tagged,F)));
throw_error(tag_cons(c)); throw_error(tag_cons(c));
} }
void type_error(CELL type, CELL tagged) void type_error(CELL type, CELL tagged)
{ {
CONS* c = cons(type,tag_cons(cons(tagged,F))); printf("throwing %d %d\n",type,tagged);
CONS* c = cons(tag_fixnum(type),tag_cons(cons(tagged,F)));
general_error(ERROR_TYPE,tag_cons(c)); general_error(ERROR_TYPE,tag_cons(c));
} }

View File

@ -3,8 +3,11 @@
#define ERROR_TYPE (2<<3) #define ERROR_TYPE (2<<3)
#define ERROR_RANGE (3<<3) #define ERROR_RANGE (3<<3)
#define ERROR_UNDERFLOW (4<<3) #define ERROR_UNDERFLOW (4<<3)
#define ERROR_BAD_PRIMITIVE (5<<3)
void fatal_error(char* msg, CELL tagged); void fatal_error(char* msg, CELL tagged);
void critical_error(char* msg, CELL tagged);
void fix_stacks(void);
void throw_error(CELL object); void throw_error(CELL object);
void general_error(CELL error, CELL tagged); void general_error(CELL error, CELL tagged);
void type_error(CELL type, CELL tagged); void type_error(CELL type, CELL tagged);

View File

@ -32,7 +32,7 @@ void copy_object(CELL* handle)
CELL header, newpointer; CELL header, newpointer;
if(in_zone(active,pointer)) if(in_zone(active,pointer))
fatal_error("copy_object given newspace ptr",pointer); critical_error("copy_object given newspace ptr",pointer);
if(tag == FIXNUM_TYPE) if(tag == FIXNUM_TYPE)
{ {
@ -56,7 +56,7 @@ void copy_object(CELL* handle)
} }
if(tag == GC_COLLECTED) if(tag == GC_COLLECTED)
fatal_error("installing forwarding pointer in newspace",newpointer); critical_error("installing forwarding pointer in newspace",newpointer);
*handle = RETAG(newpointer,tag); *handle = RETAG(newpointer,tag);
} }

View File

@ -10,7 +10,8 @@ void load_image(char* filename)
file = fopen(filename,"rb"); file = fopen(filename,"rb");
fread(&h,sizeof(HEADER),1,file); /* read it in native byte order */
fread(&h,sizeof(HEADER)/sizeof(CELL),sizeof(CELL),file);
if(h.magic != IMAGE_MAGIC) if(h.magic != IMAGE_MAGIC)
fatal_error("Bad magic number",h.magic); fatal_error("Bad magic number",h.magic);

View File

@ -26,7 +26,7 @@ CELL allot(CELL a)
CELL h = active->here; CELL h = active->here;
active->here = align8(active->here + a); active->here = align8(active->here + a);
if(active->here > active->limit) if(active->here > active->limit)
fatal_error("Out of memory",active->here); critical_error("Out of memory",active->here);
return h; return h;
} }

View File

@ -87,7 +87,7 @@ CELL primitive_to_xt(CELL primitive)
XT xt; XT xt;
if(primitive < 0 || primitive >= PRIMITIVE_COUNT) if(primitive < 0 || primitive >= PRIMITIVE_COUNT)
fatal_error("Invalid primitive",primitive); general_error("Invalid primitive",tag_fixnum(primitive));
xt = primitives[primitive]; xt = primitives[primitive];
if((CELL)xt % 8 != 0) if((CELL)xt % 8 != 0)

View File

@ -7,18 +7,25 @@ void clear_environment(void)
env.user[i] = 0; env.user[i] = 0;
} }
void reset_datastack(void)
{
env.ds = UNTAG(env.ds_bot) + sizeof(ARRAY);
env.dt = empty;
}
void reset_callstack(void)
{
env.cs = UNTAG(env.cs_bot) + sizeof(ARRAY);
cpush(empty);
}
void init_environment(void) void init_environment(void)
{ {
/* + CELLS * 2 to skip header and length cell */ /* + CELLS * 2 to skip header and length cell */
env.ds_bot = (CELL)array(STACK_SIZE,empty); env.ds_bot = tag_object(array(STACK_SIZE,empty));
env.ds = env.ds_bot + sizeof(ARRAY); reset_datastack();
env.ds_bot = tag_object(env.ds_bot); env.cs_bot = tag_object(array(STACK_SIZE,empty));
/* dpush(empty); */ reset_callstack();
env.dt = empty;
env.cs_bot = (CELL)array(STACK_SIZE,empty);
env.cs = env.cs_bot + sizeof(ARRAY);
env.cs_bot = tag_object(env.cs_bot);
cpush(empty);
env.cf = env.boot; env.cf = env.boot;
} }

View File

@ -60,7 +60,7 @@ CELL object_size(CELL pointer)
case OBJECT_TYPE: case OBJECT_TYPE:
return untagged_object_size(UNTAG(pointer)); return untagged_object_size(UNTAG(pointer));
default: default:
fatal_error("Cannot determine size",pointer); critical_error("Cannot determine size",pointer);
return -1; return -1;
} }
} }
@ -90,7 +90,7 @@ CELL untagged_object_size(CELL pointer)
size = sizeof(SBUF); size = sizeof(SBUF);
break; break;
default: default:
fatal_error("Cannot determine size",relocating); critical_error("Cannot determine size",relocating);
size = -1;/* can't happen */ size = -1;/* can't happen */
break; break;
} }

View File

@ -61,7 +61,7 @@ INLINE CELL tag_header(CELL cell)
INLINE CELL untag_header(CELL cell) INLINE CELL untag_header(CELL cell)
{ {
if(TAG(cell) != HEADER_TYPE) if(TAG(cell) != HEADER_TYPE)
fatal_error("header type check",cell); critical_error("header type check",cell);
return cell >> TAG_BITS; return cell >> TAG_BITS;
} }