factor/native/factor.c

109 lines
2.7 KiB
C
Raw Normal View History

2004-07-16 02:26:21 -04:00
#include "factor.h"
void init_factor(char* image, CELL ds_size, CELL cs_size,
2005-07-13 15:14:57 -04:00
CELL gen_count,
2005-05-10 22:30:58 -04:00
CELL young_size, CELL aging_size,
CELL code_size, CELL literal_size)
2004-11-22 19:15:14 -05:00
{
init_ffi();
2005-07-13 15:14:57 -04:00
init_arena(gen_count,young_size,aging_size);
init_compiler(code_size);
init_stacks(ds_size,cs_size);
/* callframe must be valid in case load_image() does GC */
2005-08-19 21:46:12 -04:00
callframe = F;
load_image(image,literal_size);
callframe = userenv[BOOT_ENV];
init_c_io();
2004-11-22 19:15:14 -05:00
init_signals();
userenv[CPU_ENV] = tag_object(from_c_string(FACTOR_CPU_STRING));
userenv[OS_ENV] = tag_object(from_c_string(FACTOR_OS_STRING));
2005-07-13 15:14:57 -04:00
userenv[GEN_ENV] = tag_fixnum(gen_count);
userenv[CARD_OFF_ENV] = tag_cell(cards_offset);
userenv[IMAGE_ENV] = tag_object(from_c_string(image));
userenv[CELL_SIZE_ENV] = tag_fixnum(sizeof(CELL));
2005-12-11 15:14:41 -05:00
userenv[COMPILED_BASE_ENV] = tag_cell(compiling.base);
2004-11-22 19:15:14 -05:00
}
INLINE bool factor_arg(const char* str, const char* arg, CELL* value)
{
int val;
if(sscanf(str,arg,&val))
{
*value = val;
return true;
}
else
return false;
}
2004-07-16 02:26:21 -04:00
int main(int argc, char** argv)
{
2005-09-24 15:21:17 -04:00
char *image;
2006-01-25 01:26:31 -05:00
CELL ds_size = 512;
CELL cs_size = 512;
2005-07-13 15:34:38 -04:00
CELL generations = 2;
2006-01-25 01:26:31 -05:00
CELL young_size = 2 * CELLS;
CELL aging_size = 4 * CELLS;
CELL code_size = CELLS;
CELL literal_size = 128;
CELL args;
CELL i;
2004-07-16 02:26:21 -04:00
if(argc == 1)
{
printf("Usage: factor <image file> [ parameters ... ]\n");
printf("Runtime options -- n is a number:\n");
printf(" +Dn Data stack size, kilobytes\n");
printf(" +Cn Call stack size, kilobytes\n");
printf(" +Gn Number of generations, must be >= 2\n");
printf(" +Yn Size of n-1 youngest generations, megabytes\n");
2005-05-10 22:30:58 -04:00
printf(" +An Size of tenured and semi-spaces, megabytes\n");
printf(" +Xn Code heap size, megabytes\n");
printf("Other options are handled by the Factor library.\n");
printf("See the documentation for details.\n");
printf("Send bug reports to Slava Pestov <slava@jedit.org>.\n");
2004-07-16 02:26:21 -04:00
return 1;
}
for(i = 1; i < argc; i++)
{
if(factor_arg(argv[i],"+D%d",&ds_size)) continue;
if(factor_arg(argv[i],"+C%d",&cs_size)) continue;
if(factor_arg(argv[i],"+G%d",&generations)) continue;
2005-05-10 22:30:58 -04:00
if(factor_arg(argv[i],"+Y%d",&young_size)) continue;
if(factor_arg(argv[i],"+A%d",&aging_size)) continue;
if(factor_arg(argv[i],"+X%d",&code_size)) continue;
if(strncmp(argv[i],"+",1) == 0)
{
printf("Unknown option: %s\n",argv[i]);
return 1;
}
}
2005-09-24 15:21:17 -04:00
image = argv[1];
init_factor(image,
ds_size * 1024,
cs_size * 1024,
generations,
2005-05-10 22:30:58 -04:00
young_size * 1024 * 1024,
aging_size * 1024 * 1024,
2005-05-09 22:34:47 -04:00
code_size * 1024 * 1024,
literal_size * 1024);
2004-08-13 01:38:15 -04:00
args = F;
2005-09-24 15:21:17 -04:00
while(--argc != 1)
{
args = cons(tag_object(from_c_string(argv[argc])),args);
}
userenv[ARGS_ENV] = args;
platform_run();
2004-07-16 02:26:21 -04:00
2005-10-11 21:46:14 -04:00
critical_error("run() returned due to empty callstack",0);
2004-07-16 02:26:21 -04:00
return 0;
}