factor/native/factor.c

97 lines
2.4 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-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
{
srand((unsigned)time(NULL)); /* initialize random number generator */
init_ffi();
2005-05-10 22:30:58 -04:00
init_arena(young_size,aging_size);
init_compiler(code_size);
2005-05-09 22:34:47 -04:00
load_image(image,literal_size);
init_stacks(ds_size,cs_size);
init_c_io();
2004-11-22 19:15:14 -05:00
init_signals();
init_errors();
userenv[CPU_ENV] = tag_object(from_c_string(FACTOR_CPU_STRING));
userenv[OS_ENV] = tag_object(from_c_string(FACTOR_OS_STRING));
2005-05-12 01:02:39 -04:00
userenv[GEN_ENV] = tag_fixnum(GC_GENERATIONS);
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)
{
CELL ds_size = 2048;
CELL cs_size = 2048;
2005-05-12 01:02:39 -04:00
CELL young_size = 8;
CELL aging_size = 16;
CELL code_size = 2;
2005-05-09 22:34:47 -04:00
CELL literal_size = 64;
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");
2005-05-10 22:30:58 -04:00
printf(" +Yn Size of %d youngest generations, megabytes\n",
GC_GENERATIONS-1);
printf(" +An Size of tenured and semi-spaces, megabytes\n");
printf(" +Xn Code heap size, megabytes\n");
2005-05-09 22:34:47 -04:00
printf(" +Ln Literal table size, kilobytes. Only for bootstrapping\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;
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;
2005-05-09 22:34:47 -04:00
if(factor_arg(argv[i],"+L%d",&literal_size)) continue;
if(strncmp(argv[i],"+",1) == 0)
{
printf("Unknown option: %s\n",argv[i]);
return 1;
}
}
init_factor(argv[1],
ds_size * 1024,
cs_size * 1024,
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;
while(--argc != 0)
{
args = cons(tag_object(from_c_string(argv[argc])),args);
}
userenv[ARGS_ENV] = args;
platform_run();
2004-07-16 02:26:21 -04:00
return 0;
}