factor/native/relocate.c

75 lines
1.3 KiB
C
Raw Normal View History

2004-07-16 02:26:21 -04:00
#include "factor.h"
void fixup(CELL* cell)
{
if(TAG(*cell) != FIXNUM_TYPE)
*cell += (active->base - relocation_base);
}
void relocate_object()
{
CELL size;
size = untagged_object_size(relocating);
switch(untag_header(get(relocating)))
{
2004-07-27 23:29:37 -04:00
case WORD_TYPE:
fixup_word((WORD*)relocating);
break;
2004-07-16 02:26:21 -04:00
case ARRAY_TYPE:
fixup_array((ARRAY*)relocating);
break;
case VECTOR_TYPE:
fixup_vector((VECTOR*)relocating);
break;
case SBUF_TYPE:
fixup_sbuf((SBUF*)relocating);
break;
case PORT_TYPE:
fixup_port((PORT*)relocating);
2004-07-16 02:26:21 -04:00
}
relocating += size;
}
void relocate_next()
{
switch(TAG(get(relocating)))
{
case HEADER_TYPE:
relocate_object();
break;
default:
fixup((CELL*)relocating);
relocating += CELLS;
}
}
void relocate(CELL r)
{
relocation_base = r;
2004-08-20 18:48:08 -04:00
fixup(&userenv[BOOT_ENV]);
fixup(&userenv[GLOBAL_ENV]);
2004-07-16 02:26:21 -04:00
relocating = active->base;
/* The first two objects in the image must always be F, T */
2004-07-16 02:26:21 -04:00
if(untag_header(get(relocating)) != F_TYPE)
fatal_error("Not F",get(relocating));
2004-08-04 22:43:58 -04:00
F = tag_object((CELL*)relocating);
2004-07-16 02:26:21 -04:00
relocate_next();
if(untag_header(get(relocating)) != T_TYPE)
fatal_error("Not T",get(relocating));
2004-08-04 22:43:58 -04:00
T = tag_object((CELL*)relocating);
2004-07-16 02:26:21 -04:00
relocate_next();
for(;;)
{
if(relocating >= active->here)
break;
relocate_next();
}
}