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,
|
2006-08-08 01:38:32 -04:00
|
|
|
CELL gen_count, CELL young_size, CELL aging_size, CELL code_size)
|
2004-11-22 19:15:14 -05:00
|
|
|
{
|
2006-10-17 02:44:05 -04:00
|
|
|
srand(current_millis());
|
2005-04-30 00:43:39 -04:00
|
|
|
init_ffi();
|
2006-09-26 18:44:18 -04:00
|
|
|
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);
|
2005-10-11 23:28:17 -04:00
|
|
|
/* 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;
|
2006-02-19 22:08:08 -05:00
|
|
|
thrown_error = F;
|
2006-08-08 01:38:32 -04:00
|
|
|
load_image(image);
|
2006-05-17 14:55:46 -04:00
|
|
|
call(userenv[BOOT_ENV]);
|
2005-04-22 20:09:46 -04:00
|
|
|
init_c_io();
|
2004-11-22 19:15:14 -05:00
|
|
|
init_signals();
|
2006-05-22 23:32:27 -04:00
|
|
|
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);
|
2005-05-14 00:23:00 -04:00
|
|
|
userenv[CARD_OFF_ENV] = tag_cell(cards_offset);
|
2006-05-22 23:32:27 -04:00
|
|
|
userenv[IMAGE_ENV] = tag_object(from_char_string(image));
|
2005-12-01 23:40:44 -05:00
|
|
|
userenv[CELL_SIZE_ENV] = tag_fixnum(sizeof(CELL));
|
2004-11-22 19:15:14 -05:00
|
|
|
}
|
|
|
|
|
2005-03-27 01:52:13 -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;
|
2005-03-27 01:52:13 -05:00
|
|
|
CELL i;
|
2006-04-09 19:14:30 -04:00
|
|
|
bool image_given = true;
|
2004-08-22 01:46:26 -04:00
|
|
|
|
2006-03-19 02:42:40 -05:00
|
|
|
early_init();
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2005-03-27 01:52:13 -05: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;
|
2005-03-27 01:52:13 -05:00
|
|
|
|
2006-03-19 02:42:40 -05:00
|
|
|
if(strncmp(argv[i],"-",1) != 0 && image == NULL)
|
|
|
|
image = argv[1];
|
2005-03-27 01:52:13 -05:00
|
|
|
}
|
|
|
|
|
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,
|
2005-03-27 01:52:13 -05:00
|
|
|
ds_size * 1024,
|
2006-05-14 23:09:47 -04:00
|
|
|
rs_size * 1024,
|
2005-03-27 01:52:13 -05:00
|
|
|
cs_size * 1024,
|
2005-07-13 14:53:45 -04:00
|
|
|
generations,
|
2005-05-10 22:30:58 -04:00
|
|
|
young_size * 1024 * 1024,
|
|
|
|
aging_size * 1024 * 1024,
|
2006-08-08 01:38:32 -04:00
|
|
|
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)
|
2004-08-22 01:46:26 -04:00
|
|
|
{
|
2006-05-22 23:32:27 -04:00
|
|
|
put(AREF(args,arg_count),tag_object(from_char_string(argv[arg_count])));
|
2006-05-15 00:03:55 -04:00
|
|
|
arg_count++;
|
2004-08-22 01:46:26 -04:00
|
|
|
}
|
|
|
|
|
2006-05-15 00:03:55 -04:00
|
|
|
userenv[ARGS_ENV] = tag_object(args);
|
2004-08-22 01:46:26 -04:00
|
|
|
|
2006-10-15 00:10:54 -04:00
|
|
|
run_toplevel();
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2006-10-15 00:10:54 -04:00
|
|
|
critical_error("run_toplevel() returned due to empty callstack",0);
|
2005-10-11 21:46:14 -04:00
|
|
|
|
2004-07-16 02:26:21 -04:00
|
|
|
return 0;
|
|
|
|
}
|