2004-12-28 00:04:20 -05:00
|
|
|
#include "factor.h"
|
|
|
|
|
|
|
|
void print_cons(CELL cons)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"[ ");
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
print_obj(untag_cons(cons)->car);
|
|
|
|
fprintf(stderr," ");
|
|
|
|
cons = untag_cons(cons)->cdr;
|
|
|
|
}
|
|
|
|
while(TAG(cons) == CONS_TYPE);
|
|
|
|
|
|
|
|
if(cons != F)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"| ");
|
|
|
|
print_obj(cons);
|
|
|
|
fprintf(stderr," ");
|
|
|
|
}
|
|
|
|
fprintf(stderr,"]");
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_word(F_WORD* word)
|
|
|
|
{
|
2005-08-29 02:34:04 -04:00
|
|
|
if(type_of(word->name) == STRING_TYPE)
|
2005-12-12 18:51:45 -05:00
|
|
|
fprintf(stderr,"%s",to_c_string(untag_string(word->name),true));
|
2004-12-28 00:04:20 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr,"#<not a string: ");
|
2005-08-29 02:34:04 -04:00
|
|
|
print_obj(word->name);
|
2004-12-28 00:04:20 -05:00
|
|
|
fprintf(stderr,">");
|
|
|
|
}
|
|
|
|
|
2005-08-29 02:34:04 -04:00
|
|
|
fprintf(stderr," (#%ld)",untag_fixnum_fast(word->primitive));
|
2004-12-28 00:04:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_string(F_STRING* str)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"\"");
|
2005-12-12 18:51:45 -05:00
|
|
|
fprintf(stderr,"%s",to_c_string(str,true));
|
2004-12-28 00:04:20 -05:00
|
|
|
fprintf(stderr,"\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_obj(CELL obj)
|
|
|
|
{
|
2005-07-24 22:44:33 -04:00
|
|
|
F_ARRAY *array;
|
2005-10-11 21:46:14 -04:00
|
|
|
CELL class;
|
2005-07-24 22:44:33 -04:00
|
|
|
|
2004-12-28 00:04:20 -05:00
|
|
|
switch(type_of(obj))
|
|
|
|
{
|
2005-01-30 15:57:25 -05:00
|
|
|
case FIXNUM_TYPE:
|
2005-02-14 21:58:07 -05:00
|
|
|
fprintf(stderr,"%ld",untag_fixnum_fast(obj));
|
2005-01-30 15:57:25 -05:00
|
|
|
break;
|
2004-12-28 00:04:20 -05:00
|
|
|
case CONS_TYPE:
|
|
|
|
print_cons(obj);
|
|
|
|
break;
|
|
|
|
case WORD_TYPE:
|
|
|
|
print_word(untag_word(obj));
|
|
|
|
break;
|
|
|
|
case STRING_TYPE:
|
|
|
|
print_string(untag_string(obj));
|
|
|
|
break;
|
|
|
|
case F_TYPE:
|
|
|
|
fprintf(stderr,"f");
|
|
|
|
break;
|
2005-07-24 22:44:33 -04:00
|
|
|
case TUPLE_TYPE:
|
2005-09-11 20:46:55 -04:00
|
|
|
array = (F_ARRAY*)UNTAG(obj);
|
2005-07-24 22:44:33 -04:00
|
|
|
fprintf(stderr,"<< ");
|
2005-10-11 21:46:14 -04:00
|
|
|
class = get(AREF(array,0));
|
|
|
|
if(type_of(class) == WORD_TYPE)
|
|
|
|
print_word(untag_word(class));
|
|
|
|
else
|
|
|
|
fprintf(stderr," corrupt tuple: %lx ",class);
|
2005-08-15 03:25:39 -04:00
|
|
|
fprintf(stderr," %lx >>",obj);
|
2005-07-24 22:44:33 -04:00
|
|
|
break;
|
2004-12-28 00:04:20 -05:00
|
|
|
default:
|
2005-05-12 01:02:39 -04:00
|
|
|
fprintf(stderr,"#<type %ld @ %lx>",type_of(obj),obj);
|
2004-12-28 00:04:20 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-12 01:02:39 -04:00
|
|
|
void print_objects(CELL start, CELL end)
|
2004-12-28 00:04:20 -05:00
|
|
|
{
|
2005-05-12 01:02:39 -04:00
|
|
|
for(; start <= end; start += CELLS)
|
2004-12-28 00:04:20 -05:00
|
|
|
{
|
2005-05-12 01:02:39 -04:00
|
|
|
print_obj(get(start));
|
2004-12-28 00:04:20 -05:00
|
|
|
fprintf(stderr,"\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-12 01:02:39 -04:00
|
|
|
void dump_cell(CELL cell)
|
2004-12-28 00:04:20 -05:00
|
|
|
{
|
2005-05-12 01:02:39 -04:00
|
|
|
fprintf(stderr,"%08lx: ",cell);
|
|
|
|
|
|
|
|
cell = get(cell);
|
|
|
|
|
|
|
|
fprintf(stderr,"%08lx tag %ld",cell,TAG(cell));
|
|
|
|
|
|
|
|
switch(TAG(cell))
|
|
|
|
{
|
|
|
|
case OBJECT_TYPE:
|
|
|
|
case BIGNUM_TYPE:
|
|
|
|
case FLOAT_TYPE:
|
|
|
|
if(cell == F)
|
|
|
|
fprintf(stderr," -- F");
|
|
|
|
else if(cell < TYPE_COUNT<<TAG_BITS)
|
|
|
|
fprintf(stderr," -- header: %ld",cell>>TAG_BITS);
|
|
|
|
else if(cell >= heap_start && cell < heap_end)
|
|
|
|
{
|
|
|
|
CELL header = get(UNTAG(cell));
|
|
|
|
CELL type = header>>TAG_BITS;
|
|
|
|
fprintf(stderr," -- object; ");
|
|
|
|
if(TAG(header) == OBJECT_TYPE && type < TYPE_COUNT)
|
|
|
|
fprintf(stderr," type %ld",type);
|
|
|
|
else
|
|
|
|
fprintf(stderr," header corrupt");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GC_COLLECTED:
|
|
|
|
fprintf(stderr," -- forwarding pointer");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-12-28 00:04:20 -05:00
|
|
|
fprintf(stderr,"\n");
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void dump_memory(CELL from, CELL to)
|
|
|
|
{
|
2005-07-24 22:44:33 -04:00
|
|
|
from = UNTAG(from);
|
|
|
|
|
2005-05-12 01:02:39 -04:00
|
|
|
for(; from <= to; from += CELLS)
|
|
|
|
dump_cell(from);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump_generation(ZONE *z)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"base=%lx, size=%lx, here=%lx, alarm=%lx\n",
|
|
|
|
z->base,
|
|
|
|
z->limit - z->base,
|
|
|
|
z->here - z->base,
|
|
|
|
z->alarm - z->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump_generations(void)
|
|
|
|
{
|
|
|
|
int i;
|
2005-07-13 15:14:57 -04:00
|
|
|
for(i = 0; i < gen_count; i++)
|
2005-05-12 01:02:39 -04:00
|
|
|
{
|
|
|
|
fprintf(stderr,"Generation %d: ",i);
|
|
|
|
dump_generation(&generations[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr,"Semispace: ");
|
|
|
|
dump_generation(&prior);
|
|
|
|
|
|
|
|
fprintf(stderr,"Cards: base=%lx, size=%lx\n",(CELL)cards,
|
|
|
|
(CELL)(cards_end - cards));
|
|
|
|
}
|
|
|
|
|
|
|
|
void factorbug(void)
|
|
|
|
{
|
2005-06-08 22:06:33 -04:00
|
|
|
#ifndef WIN32
|
2005-05-14 00:23:00 -04:00
|
|
|
fcntl(0,F_SETFL,0);
|
|
|
|
fcntl(1,F_SETFL,0);
|
2005-06-08 22:06:33 -04:00
|
|
|
#endif
|
2005-05-14 00:23:00 -04:00
|
|
|
|
2005-09-20 20:18:01 -04:00
|
|
|
fprintf(stderr," Front end processor commands:\n");
|
|
|
|
fprintf(stderr,"t -- throw exception in Factor\n");
|
|
|
|
fprintf(stderr,"q -- continue executing Factor\n");
|
|
|
|
fprintf(stderr,"im -- save image to fep.image\n");
|
|
|
|
fprintf(stderr,"x -- exit Factor\n");
|
|
|
|
fprintf(stderr," Advanced commands:\n");
|
2005-05-12 01:02:39 -04:00
|
|
|
fprintf(stderr,"d <addr> <count> -- dump memory\n");
|
2005-09-20 20:18:01 -04:00
|
|
|
fprintf(stderr,"u <addr> -- dump object at tagged <addr>\n");
|
|
|
|
fprintf(stderr,". <addr> -- print object at tagged <addr>\n");
|
|
|
|
fprintf(stderr,"s s -- dump data and return stacks\n");
|
2005-05-12 01:02:39 -04:00
|
|
|
fprintf(stderr,".s .r -- print data and return stacks\n");
|
|
|
|
fprintf(stderr,"i -- dump interpreter state\n");
|
|
|
|
fprintf(stderr,"e -- dump environment\n");
|
|
|
|
fprintf(stderr,"g -- dump generations\n");
|
|
|
|
fprintf(stderr,"card <addr> -- print card containing address\n");
|
|
|
|
fprintf(stderr,"addr <card> -- print address containing card\n");
|
|
|
|
fprintf(stderr,"c <gen> -- force garbage collection\n");
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
char cmd[1024];
|
|
|
|
|
2005-09-20 20:18:01 -04:00
|
|
|
fprintf(stderr,"fep> ");
|
2005-05-12 01:02:39 -04:00
|
|
|
fflush(stdout);
|
|
|
|
|
2005-09-20 20:18:01 -04:00
|
|
|
if(scanf("%1000s",cmd) <= 0)
|
2005-05-12 01:02:39 -04:00
|
|
|
exit(1);
|
|
|
|
|
|
|
|
if(strcmp(cmd,"d") == 0)
|
|
|
|
{
|
|
|
|
CELL addr, count;
|
|
|
|
scanf("%lx %lx",&addr,&count);
|
|
|
|
dump_memory(addr,addr+count);
|
|
|
|
}
|
2005-09-20 20:18:01 -04:00
|
|
|
if(strcmp(cmd,"u") == 0)
|
2005-05-12 01:02:39 -04:00
|
|
|
{
|
2005-09-20 20:18:01 -04:00
|
|
|
CELL addr, count;
|
2005-05-12 01:02:39 -04:00
|
|
|
scanf("%lx",&addr);
|
2005-09-20 20:18:01 -04:00
|
|
|
count = object_size(addr);
|
|
|
|
dump_memory(addr,addr+count);
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
2005-09-20 20:18:01 -04:00
|
|
|
else if(strcmp(cmd,".") == 0)
|
2005-05-12 01:02:39 -04:00
|
|
|
{
|
|
|
|
CELL addr;
|
|
|
|
scanf("%lx",&addr);
|
2005-09-20 20:18:01 -04:00
|
|
|
print_obj(addr);
|
|
|
|
fprintf(stderr,"\n");
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
|
|
|
else if(strcmp(cmd,"s") == 0)
|
2005-10-11 21:46:14 -04:00
|
|
|
dump_memory(ds_bot,ds);
|
2005-05-12 01:02:39 -04:00
|
|
|
else if(strcmp(cmd,"r") == 0)
|
2005-10-11 21:46:14 -04:00
|
|
|
dump_memory(cs_bot,cs);
|
2005-05-12 01:02:39 -04:00
|
|
|
else if(strcmp(cmd,".s") == 0)
|
2005-10-11 21:46:14 -04:00
|
|
|
print_objects(ds_bot,ds);
|
2005-05-12 01:02:39 -04:00
|
|
|
else if(strcmp(cmd,".r") == 0)
|
2005-10-11 21:46:14 -04:00
|
|
|
print_objects(cs_bot,cs);
|
2005-05-12 01:02:39 -04:00
|
|
|
else if(strcmp(cmd,"i") == 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"Call frame:\n");
|
2005-05-13 18:27:18 -04:00
|
|
|
print_obj(callframe);
|
2005-05-12 01:02:39 -04:00
|
|
|
fprintf(stderr,"\n");
|
|
|
|
fprintf(stderr,"Executing:\n");
|
2005-05-13 18:27:18 -04:00
|
|
|
print_obj(executing);
|
2005-05-12 01:02:39 -04:00
|
|
|
fprintf(stderr,"\n");
|
|
|
|
}
|
|
|
|
else if(strcmp(cmd,"e") == 0)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < USER_ENV; i++)
|
2005-10-11 21:46:14 -04:00
|
|
|
dump_cell((CELL)&userenv[i]);
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
|
|
|
else if(strcmp(cmd,"g") == 0)
|
|
|
|
dump_generations();
|
|
|
|
else if(strcmp(cmd,"c") == 0)
|
|
|
|
{
|
|
|
|
CELL gen;
|
|
|
|
scanf("%lu",&gen);
|
|
|
|
garbage_collection(gen);
|
|
|
|
}
|
|
|
|
else if(strcmp(cmd,"card") == 0)
|
|
|
|
{
|
|
|
|
CELL addr;
|
|
|
|
scanf("%lx",&addr);
|
|
|
|
fprintf(stderr,"%lx\n",(CELL)ADDR_TO_CARD(addr));
|
|
|
|
}
|
|
|
|
else if(strcmp(cmd,"addr") == 0)
|
|
|
|
{
|
|
|
|
CELL card;
|
|
|
|
scanf("%lx",&card);
|
|
|
|
fprintf(stderr,"%lx\n",(CELL)CARD_TO_ADDR(card));
|
|
|
|
}
|
|
|
|
else if(strcmp(cmd,"t") == 0)
|
2006-02-07 19:09:46 -05:00
|
|
|
general_error(ERROR_USER_INTERRUPT,F,true);
|
2005-09-20 20:18:01 -04:00
|
|
|
else if(strcmp(cmd,"q") == 0)
|
2005-05-12 01:02:39 -04:00
|
|
|
return;
|
2005-09-20 20:18:01 -04:00
|
|
|
else if(strcmp(cmd,"x") == 0)
|
|
|
|
exit(1);
|
2005-06-12 20:55:30 -04:00
|
|
|
else if(strcmp(cmd,"im") == 0)
|
2005-09-20 20:18:01 -04:00
|
|
|
save_image("fep.image");
|
2005-05-12 01:02:39 -04:00
|
|
|
else
|
|
|
|
fprintf(stderr,"unknown command\n");
|
|
|
|
}
|
2004-12-28 00:04:20 -05:00
|
|
|
}
|