factor/vm/factor.c

101 lines
2.3 KiB
C
Raw Normal View History

2004-07-16 02:26:21 -04:00
#include "factor.h"
2006-05-14 23:09:47 -04:00
void init_factor(const char* image,
CELL ds_size, CELL rs_size, CELL cs_size,
CELL gen_count, CELL young_size, CELL aging_size, CELL code_size)
2004-11-22 19:15:14 -05:00
{
init_ffi();
init_data_heap(gen_count,young_size,aging_size);
init_code_heap(code_size);
2006-05-14 23:09:47 -04:00
init_stacks(ds_size,rs_size,cs_size);
/* callframe must be valid in case load_image() does GC */
2005-08-19 21:46:12 -04:00
callframe = F;
2006-05-17 14:55:46 -04:00
callframe_scan = callframe_end = 0;
thrown_error = F;
load_image(image);
2006-05-17 14:55:46 -04:00
call(userenv[BOOT_ENV]);
init_c_io();
2004-11-22 19:15:14 -05:00
init_signals();
userenv[CPU_ENV] = tag_object(from_char_string(FACTOR_CPU_STRING));
userenv[OS_ENV] = tag_object(from_char_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_char_string(image));
userenv[CELL_SIZE_ENV] = tag_fixnum(sizeof(CELL));
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)
{
2006-03-19 19:59:45 -05:00
const char *image = NULL;
2006-02-13 17:16:34 -05:00
CELL ds_size = 128;
2006-05-14 23:09:47 -04:00
CELL rs_size = 128;
2006-02-13 17:16:34 -05:00
CELL cs_size = 128;
2005-07-13 15:34:38 -04:00
CELL generations = 2;
2006-09-03 21:15:25 -04:00
CELL young_size = 4 * CELLS;
CELL aging_size = 8 * CELLS;
2006-01-25 01:26:31 -05:00
CELL code_size = CELLS;
2006-05-15 00:03:55 -04:00
F_ARRAY *args;
CELL arg_count;
CELL i;
2006-04-09 19:14:30 -04:00
bool image_given = true;
2006-03-19 02:42:40 -05:00
early_init();
2004-07-16 02:26:21 -04:00
for(i = 1; i < argc; i++)
{
2006-07-02 18:51:57 -04:00
if(factor_arg(argv[i],"-D=%d",&ds_size)) continue;
if(factor_arg(argv[i],"-R=%d",&rs_size)) continue;
if(factor_arg(argv[i],"-C=%d",&cs_size)) continue;
if(factor_arg(argv[i],"-G=%d",&generations)) continue;
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;
2006-03-19 02:42:40 -05:00
if(strncmp(argv[i],"-",1) != 0 && image == NULL)
image = argv[1];
}
2006-03-19 02:42:40 -05:00
if(image == NULL)
2006-04-09 19:14:30 -04:00
{
image_given = false;
2006-03-19 02:42:40 -05:00
image = default_image_path();
2006-04-09 19:14:30 -04:00
}
2005-09-24 15:21:17 -04:00
init_factor(image,
ds_size * 1024,
2006-05-14 23:09:47 -04:00
rs_size * 1024,
cs_size * 1024,
generations,
2005-05-10 22:30:58 -04:00
young_size * 1024 * 1024,
aging_size * 1024 * 1024,
code_size * 1024 * 1024);
2004-08-13 01:38:15 -04:00
2006-05-15 00:03:55 -04:00
arg_count = (image_given ? 2 : 1);
args = array(ARRAY_TYPE,argc,F);
while(arg_count < argc)
{
put(AREF(args,arg_count),tag_object(from_char_string(argv[arg_count])));
2006-05-15 00:03:55 -04:00
arg_count++;
}
2006-05-15 00:03:55 -04:00
userenv[ARGS_ENV] = tag_object(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;
}