factor/native/memory.c

65 lines
1.1 KiB
C
Raw Normal View History

2004-07-16 02:26:21 -04:00
#include "factor.h"
static ZONE* zalloc(CELL size)
{
ZONE* z = (ZONE*)malloc(sizeof(ZONE));
if(z == 0)
fatal_error("Cannot allocate zone header",size);
z->base = z->here = (CELL)malloc(size);
if(z->base == 0)
fatal_error("Cannot allocate zone",size);
z->limit = z->base + size;
z->base = align8(z->base);
return z;
}
void init_arena(CELL size)
{
z1 = zalloc(size);
z2 = zalloc(size);
active = z1;
}
CELL allot(CELL a)
{
CELL h = active->here;
active->here = align8(active->here + a);
if(active->here > active->limit)
2004-07-24 00:54:57 -04:00
{
printf("Out of memory\n");
2004-07-28 19:02:24 -04:00
printf("active->base = %ld\n",active->base);
printf("active->here = %ld\n",active->here);
printf("active->limit = %ld\n",active->limit);
printf("request = %ld\n",a);
2004-07-24 00:54:57 -04:00
exit(1);
}
2004-07-16 02:26:21 -04:00
return h;
}
void flip_zones()
{
if(active == z1)
{
prior = z1;
active = z2;
}
else
{
prior = z2;
active = z1;
}
}
bool in_zone(ZONE* z, CELL pointer)
{
return pointer >= z->base && pointer < z->limit;
}
2004-07-24 00:54:57 -04:00
void primitive_room(void)
{
/* push: limit here */
dpush(env.dt);
env.dt = tag_fixnum(active->limit - active->base);
dpush(tag_fixnum(active->here - active->base));
}