2004-09-06 02:32:04 -04:00
|
|
|
#include "factor.h"
|
|
|
|
|
2005-03-14 11:25:41 -05:00
|
|
|
void init_compiler(CELL size)
|
|
|
|
{
|
2005-05-10 22:30:58 -04:00
|
|
|
compiling.base = compiling.here = (CELL)alloc_guarded(size);
|
|
|
|
if(compiling.base == 0)
|
|
|
|
fatal_error("Cannot allocate code heap",size);
|
|
|
|
compiling.limit = compiling.base + size;
|
2005-03-14 11:25:41 -05:00
|
|
|
last_flush = compiling.base;
|
|
|
|
}
|
|
|
|
|
2004-09-06 22:39:12 -04:00
|
|
|
void primitive_compiled_offset(void)
|
2004-09-06 02:32:04 -04:00
|
|
|
{
|
2005-03-28 23:45:13 -05:00
|
|
|
box_unsigned_cell(compiling.here);
|
2004-09-06 02:32:04 -04:00
|
|
|
}
|
2004-09-06 22:39:12 -04:00
|
|
|
|
|
|
|
void primitive_set_compiled_offset(void)
|
|
|
|
{
|
2005-03-28 23:45:13 -05:00
|
|
|
CELL offset = unbox_unsigned_cell();
|
2004-09-06 22:39:12 -04:00
|
|
|
compiling.here = offset;
|
2006-02-08 22:12:20 -05:00
|
|
|
if(compiling.here > compiling.limit)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"Code space exhausted\n");
|
|
|
|
factorbug();
|
|
|
|
}
|
2004-09-06 22:39:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_literal_top(void)
|
|
|
|
{
|
2005-03-28 23:45:13 -05:00
|
|
|
box_unsigned_cell(literal_top);
|
2004-09-06 22:39:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_set_literal_top(void)
|
|
|
|
{
|
2005-03-28 23:45:13 -05:00
|
|
|
CELL offset = unbox_unsigned_cell();
|
2004-12-25 02:55:03 -05:00
|
|
|
if(offset >= literal_max)
|
|
|
|
critical_error("Too many compiled literals",offset);
|
2004-09-06 22:39:12 -04:00
|
|
|
literal_top = offset;
|
|
|
|
}
|
|
|
|
|
2005-03-14 11:25:41 -05:00
|
|
|
void primitive_flush_icache(void)
|
|
|
|
{
|
|
|
|
flush_icache((void*)last_flush,compiling.here - last_flush);
|
|
|
|
last_flush = compiling.here;
|
|
|
|
}
|
|
|
|
|
2004-09-06 22:39:12 -04:00
|
|
|
void collect_literals(void)
|
|
|
|
{
|
2004-12-24 02:52:02 -05:00
|
|
|
CELL i;
|
|
|
|
for(i = compiling.base; i < literal_top; i += CELLS)
|
2005-02-19 23:25:21 -05:00
|
|
|
copy_handle((CELL*)i);
|
2004-09-06 22:39:12 -04:00
|
|
|
}
|