3 void default_parameters(F_PARAMETERS
*p
)
7 /* We make a wild guess here that if we're running on ARM, we don't
8 have a lot of memory. */
10 p
->ds_size
= 8 * CELLS
;
11 p
->rs_size
= 8 * CELLS
;
19 p
->ds_size
= 32 * CELLS
;
20 p
->rs_size
= 32 * CELLS
;
23 p
->code_size
= 8 * CELLS
;
24 p
->young_size
= CELLS
/ 4;
25 p
->aging_size
= CELLS
/ 2;
26 p
->tenured_size
= 4 * CELLS
;
38 p
->stack_traces
= true;
41 INLINE
bool factor_arg(const F_CHAR
* str
, const F_CHAR
* arg
, CELL
* value
)
44 if(SSCANF(str
,arg
,&val
) > 0)
53 void init_parameters_from_args(F_PARAMETERS
*p
, int argc
, F_CHAR
**argv
)
55 default_parameters(p
);
56 p
->executable_path
= argv
[0];
60 for(i
= 1; i
< argc
; i
++)
62 if(factor_arg(argv
[i
],STRING_LITERAL("-datastack=%d"),&p
->ds_size
));
63 else if(factor_arg(argv
[i
],STRING_LITERAL("-retainstack=%d"),&p
->rs_size
));
64 else if(factor_arg(argv
[i
],STRING_LITERAL("-generations=%d"),&p
->gen_count
));
65 else if(factor_arg(argv
[i
],STRING_LITERAL("-young=%d"),&p
->young_size
));
66 else if(factor_arg(argv
[i
],STRING_LITERAL("-aging=%d"),&p
->aging_size
));
67 else if(factor_arg(argv
[i
],STRING_LITERAL("-tenured=%d"),&p
->tenured_size
));
68 else if(factor_arg(argv
[i
],STRING_LITERAL("-codeheap=%d"),&p
->code_size
));
69 else if(STRCMP(argv
[i
],STRING_LITERAL("-securegc")) == 0) p
->secure_gc
= true;
70 else if(STRCMP(argv
[i
],STRING_LITERAL("-fep")) == 0) p
->fep
= true;
71 else if(STRNCMP(argv
[i
],STRING_LITERAL("-i="),3) == 0) p
->image_path
= argv
[i
] + 3;
72 else if(STRCMP(argv
[i
],STRING_LITERAL("-console")) == 0) p
->console
= true;
73 else if(STRCMP(argv
[i
],STRING_LITERAL("-no-stack-traces")) == 0) p
->stack_traces
= false;
77 /* Do some initialization that we do once only */
78 void do_stage1_init(void)
80 print_string("*** Stage 2 early init... ");
84 userenv
[STAGE2_ENV
] = T
;
86 print_string("done\n");
90 void init_factor(F_PARAMETERS
*p
)
93 p
->ds_size
= align_page(p
->ds_size
<< 10);
94 p
->rs_size
= align_page(p
->rs_size
<< 10);
99 p
->tenured_size
<<= 20;
102 /* Disable GC during init as a sanity check */
105 /* OS-specific initialization */
108 const F_CHAR
*executable_path
= vm_executable_path();
111 p
->executable_path
= executable_path
;
113 if(p
->image_path
== NULL
)
114 p
->image_path
= default_image_path();
116 srand(current_micros());
118 init_stacks(p
->ds_size
,p
->rs_size
);
128 performing_gc
= false;
129 last_code_heap_scan
= NURSERY
;
130 collecting_aging_again
= false;
132 userenv
[CPU_ENV
] = tag_object(from_char_string(FACTOR_CPU_STRING
));
133 userenv
[OS_ENV
] = tag_object(from_char_string(FACTOR_OS_STRING
));
134 userenv
[CELL_SIZE_ENV
] = tag_fixnum(sizeof(CELL
));
135 userenv
[STACK_TRACES_ENV
] = tag_boolean(p
->stack_traces
);
136 userenv
[EXECUTABLE_ENV
] = (p
->executable_path
?
137 tag_object(from_native_string(p
->executable_path
)) : F
);
138 userenv
[ARGS_ENV
] = F
;
139 userenv
[EMBEDDED_ENV
] = F
;
148 /* May allocate memory */
149 void pass_args_to_factor(int argc
, F_CHAR
**argv
)
151 F_ARRAY
*args
= allot_array(ARRAY_TYPE
,argc
,F
);
154 for(i
= 1; i
< argc
; i
++)
156 REGISTER_UNTAGGED(args
);
157 CELL arg
= tag_object(from_native_string(argv
[i
]));
158 UNREGISTER_UNTAGGED(args
);
159 set_array_nth(args
,i
,arg
);
162 userenv
[ARGS_ENV
] = tag_object(args
);
165 void start_factor(F_PARAMETERS
*p
)
167 if(p
->fep
) factorbug();
170 c_to_factor_toplevel(userenv
[BOOT_ENV
]);
174 void start_embedded_factor(F_PARAMETERS
*p
)
176 userenv
[EMBEDDED_ENV
] = T
;
180 void start_standalone_factor(int argc
, F_CHAR
**argv
)
183 default_parameters(&p
);
184 init_parameters_from_args(&p
,argc
,argv
);
186 pass_args_to_factor(argc
,argv
);
190 char *factor_eval_string(char *string
)
192 char* (*callback
)(char*) = alien_offset(userenv
[EVAL_CALLBACK_ENV
]);
193 return callback(string
);
196 void factor_eval_free(char *result
)
201 void factor_yield(void)
203 void (*callback
)() = alien_offset(userenv
[YIELD_CALLBACK_ENV
]);
207 void factor_sleep(long us
)
209 void (*callback
)() = alien_offset(userenv
[SLEEP_CALLBACK_ENV
]);