]> gitweb.factorcode.org Git - factor.git/blob - vm/factor.c
1eaff445953134ba304e8ed10d36e9fff631531c
[factor.git] / vm / factor.c
1 #include "factor.h"
2
3 void init_factor(const char* image,
4         CELL ds_size, CELL rs_size, CELL cs_size,
5         CELL gen_count, CELL young_size, CELL aging_size, CELL code_size)
6 {
7         init_ffi();
8         init_data_heap(gen_count,young_size,aging_size);
9         init_code_heap(code_size);
10         init_stacks(ds_size,rs_size,cs_size);
11         /* callframe must be valid in case load_image() does GC */
12         callframe = F;
13         callframe_scan = callframe_end = 0;
14         thrown_error = F;
15         load_image(image);
16         call(userenv[BOOT_ENV]);
17         init_c_io();
18         init_signals();
19         userenv[CPU_ENV] = tag_object(from_char_string(FACTOR_CPU_STRING));
20         userenv[OS_ENV] = tag_object(from_char_string(FACTOR_OS_STRING));
21         userenv[GEN_ENV] = tag_fixnum(gen_count);
22         userenv[CARD_OFF_ENV] = tag_cell(cards_offset);
23         userenv[IMAGE_ENV] = tag_object(from_char_string(image));
24         userenv[CELL_SIZE_ENV] = tag_fixnum(sizeof(CELL));
25 }
26
27 INLINE bool factor_arg(const char* str, const char* arg, CELL* value)
28 {
29         int val;
30         if(sscanf(str,arg,&val))
31         {
32                 *value = val;
33                 return true;
34         }
35         else
36                 return false;
37 }
38
39 int main(int argc, char** argv)
40 {
41         const char *image = NULL;
42         CELL ds_size = 128;
43         CELL rs_size = 128;
44         CELL cs_size = 128;
45         CELL generations = 2;
46         CELL young_size = 4 * CELLS;
47         CELL aging_size = 8 * CELLS;
48         CELL code_size = CELLS;
49         F_ARRAY *args;
50         CELL arg_count;
51         CELL i;
52         bool image_given = true;
53
54         early_init();
55
56         for(i = 1; i < argc; i++)
57         {
58                 if(factor_arg(argv[i],"-D=%d",&ds_size)) continue;
59                 if(factor_arg(argv[i],"-R=%d",&rs_size)) continue;
60                 if(factor_arg(argv[i],"-C=%d",&cs_size)) continue;
61                 if(factor_arg(argv[i],"-G=%d",&generations)) continue;
62                 if(factor_arg(argv[i],"-Y=%d",&young_size)) continue;
63                 if(factor_arg(argv[i],"-A=%d",&aging_size)) continue;
64                 if(factor_arg(argv[i],"-X=%d",&code_size)) continue;
65
66                 if(strncmp(argv[i],"-",1) != 0 && image == NULL)
67                         image = argv[1];
68         }
69
70         if(image == NULL)
71         {
72                 image_given = false;
73                 image = default_image_path();
74         }
75
76         init_factor(image,
77                 ds_size * 1024,
78                 rs_size * 1024,
79                 cs_size * 1024,
80                 generations,
81                 young_size * 1024 * 1024,
82                 aging_size * 1024 * 1024,
83                 code_size * 1024 * 1024);
84
85         arg_count = (image_given ? 2 : 1);
86         args = array(ARRAY_TYPE,argc,F);
87         while(arg_count < argc)
88         {
89                 put(AREF(args,arg_count),tag_object(from_char_string(argv[arg_count])));
90                 arg_count++;
91         }
92
93         userenv[ARGS_ENV] = tag_object(args);
94
95         platform_run();
96
97         critical_error("run() returned due to empty callstack",0);
98
99         return 0;
100 }