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
);
59 for(i
= 1; i
< argc
; i
++)
61 if(factor_arg(argv
[i
],STRING_LITERAL("-datastack=%d"),&p
->ds_size
));
62 else if(factor_arg(argv
[i
],STRING_LITERAL("-retainstack=%d"),&p
->rs_size
));
63 else if(factor_arg(argv
[i
],STRING_LITERAL("-generations=%d"),&p
->gen_count
));
64 else if(factor_arg(argv
[i
],STRING_LITERAL("-young=%d"),&p
->young_size
));
65 else if(factor_arg(argv
[i
],STRING_LITERAL("-aging=%d"),&p
->aging_size
));
66 else if(factor_arg(argv
[i
],STRING_LITERAL("-tenured=%d"),&p
->tenured_size
));
67 else if(factor_arg(argv
[i
],STRING_LITERAL("-codeheap=%d"),&p
->code_size
));
68 else if(STRCMP(argv
[i
],STRING_LITERAL("-securegc")) == 0) p
->secure_gc
= true;
69 else if(STRCMP(argv
[i
],STRING_LITERAL("-fep")) == 0) p
->fep
= true;
70 else if(STRNCMP(argv
[i
],STRING_LITERAL("-i="),3) == 0) p
->image_path
= argv
[i
] + 3;
71 else if(STRCMP(argv
[i
],STRING_LITERAL("-console")) == 0) p
->console
= true;
72 else if(STRCMP(argv
[i
],STRING_LITERAL("-no-stack-traces")) == 0) p
->stack_traces
= false;
76 /* Do some initialization that we do once only */
77 void do_stage1_init(void)
79 print_string("*** Stage 2 early init... ");
83 userenv
[STAGE2_ENV
] = T
;
85 print_string("done\n");
89 void init_factor(F_PARAMETERS
*p
)
92 p
->ds_size
= align_page(p
->ds_size
<< 10);
93 p
->rs_size
= align_page(p
->rs_size
<< 10);
98 p
->tenured_size
<<= 20;
101 /* Disable GC during init as a sanity check */
104 /* OS-specific initialization */
107 if(p
->image_path
== NULL
)
108 p
->image_path
= default_image_path();
110 const F_CHAR
*executable_path
= vm_executable_path();
112 p
->executable_path
= executable_path
;
114 srand(current_micros());
116 init_stacks(p
->ds_size
,p
->rs_size
);
126 performing_gc
= false;
127 last_code_heap_scan
= NURSERY
;
128 collecting_aging_again
= false;
130 userenv
[CPU_ENV
] = tag_object(from_char_string(FACTOR_CPU_STRING
));
131 userenv
[OS_ENV
] = tag_object(from_char_string(FACTOR_OS_STRING
));
132 userenv
[CELL_SIZE_ENV
] = tag_fixnum(sizeof(CELL
));
133 userenv
[STACK_TRACES_ENV
] = tag_boolean(p
->stack_traces
);
134 userenv
[EXECUTABLE_ENV
] = (p
->executable_path
?
135 tag_object(from_native_string(p
->executable_path
)) : F
);
136 userenv
[ARGS_ENV
] = F
;
137 userenv
[EMBEDDED_ENV
] = F
;
146 /* May allocate memory */
147 void pass_args_to_factor(int argc
, F_CHAR
**argv
)
149 F_ARRAY
*args
= allot_array(ARRAY_TYPE
,argc
,F
);
152 for(i
= 1; i
< argc
; i
++)
154 REGISTER_UNTAGGED(args
);
155 CELL arg
= tag_object(from_native_string(argv
[i
]));
156 UNREGISTER_UNTAGGED(args
);
157 set_array_nth(args
,i
,arg
);
160 userenv
[ARGS_ENV
] = tag_object(args
);
163 void start_factor(F_PARAMETERS
*p
)
165 if(p
->fep
) factorbug();
168 c_to_factor_toplevel(userenv
[BOOT_ENV
]);
172 void start_embedded_factor(F_PARAMETERS
*p
)
174 userenv
[EMBEDDED_ENV
] = T
;
178 void start_standalone_factor(int argc
, F_CHAR
**argv
)
181 default_parameters(&p
);
182 init_parameters_from_args(&p
,argc
,argv
);
184 pass_args_to_factor(argc
,argv
);
188 char *factor_eval_string(char *string
)
190 char* (*callback
)(char*) = alien_offset(userenv
[EVAL_CALLBACK_ENV
]);
191 return callback(string
);
194 void factor_eval_free(char *result
)
199 void factor_yield(void)
201 void (*callback
)() = alien_offset(userenv
[YIELD_CALLBACK_ENV
]);
205 void factor_sleep(long us
)
207 void (*callback
)() = alien_offset(userenv
[SLEEP_CALLBACK_ENV
]);