]> gitweb.factorcode.org Git - factor.git/blob - vm/vm.hpp
vm: split up TLS code and add a dummy implementation for a dummy OS known as NetBSD
[factor.git] / vm / vm.hpp
1 namespace factor
2 {
3
4 struct growable_array;
5 struct code_root;
6
7 struct factor_vm
8 {
9         // First 5 fields accessed directly by compiler. See basis/vm/vm.factor
10
11         /* Current context */
12         context *ctx;
13
14         /* Spare context -- for callbacks */
15         context *spare_ctx;
16
17         /* New objects are allocated here */
18         nursery_space nursery;
19
20         /* Add this to a shifted address to compute write barrier offsets */
21         cell cards_offset;
22         cell decks_offset;
23
24         /* Various special objects, accessed by special-object and
25         set-special-object primitives */
26         cell special_objects[special_object_count];
27
28         /* Data stack and retain stack sizes */
29         cell datastack_size, retainstack_size, callstack_size;
30
31         /* Stack of callback IDs */
32         std::vector<int> callback_ids;
33
34         /* Next callback ID */
35         int callback_id;
36
37         /* Pooling unused contexts to make context allocation cheaper */
38         std::vector<context *> unused_contexts;
39
40         /* Active contexts, for tracing by the GC */
41         std::set<context *> active_contexts;
42
43         /* Canonical truth value. In Factor, 't' */
44         cell true_object;
45
46         /* External entry points */
47         c_to_factor_func_type c_to_factor_func;
48
49         /* Is call counting enabled? */
50         bool profiling_p;
51
52         /* Global variables used to pass fault handler state from signal handler to
53            user-space */
54         cell signal_number;
55         cell signal_fault_addr;
56         unsigned int signal_fpu_status;
57         stack_frame *signal_callstack_top;
58
59         /* GC is off during heap walking */
60         bool gc_off;
61
62         /* Data heap */
63         data_heap *data;
64
65         /* Code heap */
66         code_heap *code;
67
68         /* Pinned callback stubs */
69         callback_heap *callbacks;
70
71         /* Only set if we're performing a GC */
72         gc_state *current_gc;
73
74         /* Mark stack */
75         std::vector<cell> mark_stack;
76
77         /* If not NULL, we push GC events here */
78         std::vector<gc_event> *gc_events;
79
80         /* If a runtime function needs to call another function which potentially
81            allocates memory, it must wrap any references to the data and code
82            heaps with data_root and code_root smart pointers, which register
83            themselves here. See data_roots.hpp and code_roots.hpp */
84         std::vector<data_root_range> data_roots;
85         std::vector<cell> bignum_roots;
86         std::vector<code_root *> code_roots;
87
88         /* Debugger */
89         bool fep_disabled;
90         bool full_output;
91
92         /* Canonical bignums */
93         cell bignum_zero;
94         cell bignum_pos_one;
95         cell bignum_neg_one;
96
97         /* Method dispatch statistics */
98         dispatch_statistics dispatch_stats;
99
100         /* Number of entries in a polymorphic inline cache */
101         cell max_pic_size;
102
103         /* Incrementing object counter for identity hashing */
104         cell object_counter;
105
106         /* Sanity check to ensure that monotonic counter doesn't
107         decrease */
108         u64 last_nano_count;
109
110         /* Stack for signal handlers, only used on Unix */
111         segment *signal_callstack_seg;
112
113         // contexts
114         context *new_context();
115         void delete_context(context *old_context);
116         void init_contexts(cell datastack_size_, cell retainstack_size_, cell callstack_size_);
117         void delete_contexts();
118         void begin_callback();
119         void end_callback();
120         void primitive_current_callback();
121         void primitive_context_object();
122         void primitive_set_context_object();
123         bool stack_to_array(cell bottom, cell top);
124         cell array_to_stack(array *array, cell bottom);
125         void primitive_datastack();
126         void primitive_retainstack();
127         void primitive_set_datastack();
128         void primitive_set_retainstack();
129         void primitive_check_datastack();
130         void primitive_load_locals();
131         void primitive_context();
132         void primitive_delete_context();
133
134         template<typename Iterator> void iterate_active_callstacks(Iterator &iter)
135         {
136                 std::set<context *>::const_iterator begin = active_contexts.begin();
137                 std::set<context *>::const_iterator end = active_contexts.end();
138                 while(begin != end) iterate_callstack(*begin++,iter);
139         }
140
141         // run
142         void primitive_exit();
143         void primitive_system_micros();
144         void primitive_nano_count();
145         void primitive_sleep();
146         void primitive_set_slot();
147
148         // objects
149         void primitive_special_object();
150         void primitive_set_special_object();
151         void primitive_identity_hashcode();
152         void compute_identity_hashcode(object *obj);
153         void primitive_compute_identity_hashcode();
154         cell object_size(cell tagged);
155         cell clone_object(cell obj_);
156         void primitive_clone();
157         void primitive_become();
158
159         // profiler
160         void init_profiler();
161         code_block *compile_profiling_stub(cell word_);
162         void set_profiling(bool profiling);
163         void primitive_profiling();
164
165         // errors
166         void throw_error(cell error, stack_frame *stack);
167         void general_error(vm_error_type error, cell arg1, cell arg2, stack_frame *stack);
168         void general_error(vm_error_type error, cell arg1, cell arg2);
169         void type_error(cell type, cell tagged);
170         void not_implemented_error();
171         void memory_protection_error(cell addr, stack_frame *stack);
172         void signal_error(cell signal, stack_frame *stack);
173         void divide_by_zero_error();
174         void fp_trap_error(unsigned int fpu_status, stack_frame *stack);
175         void primitive_call_clear();
176         void primitive_unimplemented();
177         void memory_signal_handler_impl();
178         void misc_signal_handler_impl();
179         void fp_signal_handler_impl();
180
181         // bignum
182         int bignum_equal_p(bignum * x, bignum * y);
183         enum bignum_comparison bignum_compare(bignum * x, bignum * y);
184         bignum *bignum_add(bignum * x, bignum * y);
185         bignum *bignum_subtract(bignum * x, bignum * y);
186         bignum *bignum_multiply(bignum * x, bignum * y);
187         void bignum_divide(bignum * numerator, bignum * denominator, bignum * * quotient, bignum * * remainder);
188         bignum *bignum_quotient(bignum * numerator, bignum * denominator);
189         bignum *bignum_remainder(bignum * numerator, bignum * denominator);
190         cell bignum_to_cell(bignum * bignum);
191         fixnum bignum_to_fixnum(bignum * bignum);
192         s64 bignum_to_long_long(bignum * bignum);
193         u64 bignum_to_ulong_long(bignum * bignum);
194         double bignum_to_double(bignum * bignum);
195         bignum *double_to_bignum(double x);
196         int bignum_equal_p_unsigned(bignum * x, bignum * y);
197         enum bignum_comparison bignum_compare_unsigned(bignum * x, bignum * y);
198         bignum *bignum_add_unsigned(bignum * x, bignum * y, int negative_p);
199         bignum *bignum_subtract_unsigned(bignum * x, bignum * y);
200         bignum *bignum_multiply_unsigned(bignum * x, bignum * y, int negative_p);
201         bignum *bignum_multiply_unsigned_small_factor(bignum * x, bignum_digit_type y,int negative_p);
202         void bignum_destructive_add(bignum * bignum, bignum_digit_type n);
203         void bignum_destructive_scale_up(bignum * bignum, bignum_digit_type factor);
204         void bignum_divide_unsigned_large_denominator(bignum * numerator, bignum * denominator,
205                                                         bignum * * quotient, bignum * * remainder, int q_negative_p, int r_negative_p);
206         void bignum_divide_unsigned_normalized(bignum * u, bignum * v, bignum * q);
207         bignum_digit_type bignum_divide_subtract(bignum_digit_type * v_start, bignum_digit_type * v_end,
208                                                         bignum_digit_type guess, bignum_digit_type * u_start);
209         void bignum_divide_unsigned_medium_denominator(bignum * numerator,bignum_digit_type denominator,
210                                                         bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p);
211         void bignum_destructive_normalization(bignum * source, bignum * target, int shift_left);
212         void bignum_destructive_unnormalization(bignum * bignum, int shift_right);
213         bignum_digit_type bignum_digit_divide(bignum_digit_type uh, bignum_digit_type ul,
214                                                         bignum_digit_type v, bignum_digit_type * q) /* return value */;
215         bignum_digit_type bignum_digit_divide_subtract(bignum_digit_type v1, bignum_digit_type v2,
216                                                         bignum_digit_type guess, bignum_digit_type * u);
217         void bignum_divide_unsigned_small_denominator(bignum * numerator, bignum_digit_type denominator,
218                                                         bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p);
219         bignum_digit_type bignum_destructive_scale_down(bignum * bignum, bignum_digit_type denominator);
220         bignum * bignum_remainder_unsigned_small_denominator(bignum * n, bignum_digit_type d, int negative_p);
221         bignum *bignum_digit_to_bignum(bignum_digit_type digit, int negative_p);
222         bignum *allot_bignum(bignum_length_type length, int negative_p);
223         bignum * allot_bignum_zeroed(bignum_length_type length, int negative_p);
224         bignum *bignum_shorten_length(bignum * bignum, bignum_length_type length);
225         bignum *bignum_trim(bignum * bignum);
226         bignum *bignum_new_sign(bignum * x, int negative_p);
227         bignum *bignum_maybe_new_sign(bignum * x, int negative_p);
228         void bignum_destructive_copy(bignum * source, bignum * target);
229         bignum *bignum_bitwise_not(bignum * x);
230         bignum *bignum_arithmetic_shift(bignum * arg1, fixnum n);
231         bignum *bignum_bitwise_and(bignum * arg1, bignum * arg2);
232         bignum *bignum_bitwise_ior(bignum * arg1, bignum * arg2);
233         bignum *bignum_bitwise_xor(bignum * arg1, bignum * arg2);
234         bignum *bignum_magnitude_ash(bignum * arg1, fixnum n);
235         bignum *bignum_pospos_bitwise_op(int op, bignum * arg1, bignum * arg2);
236         bignum *bignum_posneg_bitwise_op(int op, bignum * arg1, bignum * arg2);
237         bignum *bignum_negneg_bitwise_op(int op, bignum * arg1, bignum * arg2);
238         void bignum_negate_magnitude(bignum * arg);
239         bignum *bignum_integer_length(bignum * x);
240         int bignum_logbitp(int shift, bignum * arg);
241         int bignum_unsigned_logbitp(int shift, bignum * bignum);
242         bignum *digit_stream_to_bignum(unsigned int n_digits, unsigned int (*producer)(unsigned int, factor_vm *), unsigned int radix, int negative_p);
243
244         //data heap
245         void init_card_decks();
246         void set_data_heap(data_heap *data_);
247         void init_data_heap(cell young_size, cell aging_size, cell tenured_size);
248         void primitive_size();
249         data_heap_room data_room();
250         void primitive_data_room();
251         void begin_scan();
252         void end_scan();
253         cell instances(cell type);
254         void primitive_all_instances();
255
256         template<typename Generation, typename Iterator>
257         inline void each_object(Generation *gen, Iterator &iterator)
258         {
259                 cell obj = gen->first_object();
260                 while(obj)
261                 {
262                         iterator((object *)obj);
263                         obj = gen->next_object_after(obj);
264                 }
265         }
266
267         template<typename Iterator> inline void each_object(Iterator &iterator)
268         {
269                 gc_off = true;
270
271                 each_object(data->tenured,iterator);
272                 each_object(data->aging,iterator);
273                 each_object(data->nursery,iterator);
274
275                 gc_off = false;
276         }
277
278         /* the write barrier must be called any time we are potentially storing a
279            pointer from an older generation to a younger one */
280         inline void write_barrier(cell *slot_ptr)
281         {
282                 *(char *)(cards_offset + ((cell)slot_ptr >> card_bits)) = card_mark_mask;
283                 *(char *)(decks_offset + ((cell)slot_ptr >> deck_bits)) = card_mark_mask;
284         }
285
286         inline void write_barrier(object *obj, cell size)
287         {
288                 cell start = (cell)obj & (~card_size + 1);
289                 cell end = ((cell)obj + size + card_size - 1) & (~card_size + 1);
290
291                 for(cell offset = start; offset < end; offset += card_size)
292                         write_barrier((cell *)offset);
293         }
294
295         // data heap checker
296         void check_data_heap();
297
298         // gc
299         void end_gc();
300         void start_gc_again();
301         void update_code_heap_for_minor_gc(std::set<code_block *> *remembered_set);
302         void collect_nursery();
303         void collect_aging();
304         void collect_to_tenured();
305         void update_code_roots_for_sweep();
306         void update_code_roots_for_compaction();
307         void collect_mark_impl(bool trace_contexts_p);
308         void collect_sweep_impl();
309         void collect_full(bool trace_contexts_p);
310         void collect_compact_impl(bool trace_contexts_p);
311         void collect_compact_code_impl(bool trace_contexts_p);
312         void collect_compact(bool trace_contexts_p);
313         void collect_growing_heap(cell requested_bytes, bool trace_contexts_p);
314         void gc(gc_op op, cell requested_bytes, bool trace_contexts_p);
315         void primitive_minor_gc();
316         void primitive_full_gc();
317         void primitive_compact_gc();
318         void inline_gc(cell *data_roots_base, cell data_roots_size);
319         void primitive_enable_gc_events();
320         void primitive_disable_gc_events();
321         object *allot_object(cell type, cell size);
322         object *allot_large_object(cell type, cell size);
323
324         template<typename Type> Type *allot(cell size)
325         {
326                 return (Type *)allot_object(Type::type_number,size);
327         }
328
329         inline void check_data_pointer(object *pointer)
330         {
331         #ifdef FACTOR_DEBUG
332                 if(!(current_gc && current_gc->op == collect_growing_heap_op))
333                 {
334                         assert((cell)pointer >= data->seg->start
335                                 && (cell)pointer < data->seg->end);
336                 }
337         #endif
338         }
339
340         // generic arrays
341         template<typename Array> Array *allot_uninitialized_array(cell capacity);
342         template<typename Array> bool reallot_array_in_place_p(Array *array, cell capacity);
343         template<typename Array> Array *reallot_array(Array *array_, cell capacity);
344
345         // debug
346         void print_chars(string* str);
347         void print_word(word* word, cell nesting);
348         void print_factor_string(string* str);
349         void print_array(array* array, cell nesting);
350         void print_tuple(tuple *tuple, cell nesting);
351         void print_nested_obj(cell obj, fixnum nesting);
352         void print_obj(cell obj);
353         void print_objects(cell *start, cell *end);
354         void print_datastack();
355         void print_retainstack();
356         void print_callstack();
357         void dump_cell(cell x);
358         void dump_memory(cell from, cell to);
359         template<typename Generation> void dump_generation(const char *name, Generation *gen);
360         void dump_generations();
361         void dump_objects(cell type);
362         void find_data_references_step(cell *scan);
363         void find_data_references(cell look_for_);
364         void dump_code_heap();
365         void factorbug();
366         void primitive_die();
367
368         // arrays
369         inline void set_array_nth(array *array, cell slot, cell value);
370         array *allot_array(cell capacity, cell fill_);
371         void primitive_array();
372         cell allot_array_1(cell obj_);
373         cell allot_array_2(cell v1_, cell v2_);
374         cell allot_array_4(cell v1_, cell v2_, cell v3_, cell v4_);
375         void primitive_resize_array();
376         cell std_vector_to_array(std::vector<cell> &elements);
377
378         // strings
379         cell string_nth(const string *str, cell index);
380         void set_string_nth_fast(string *str, cell index, cell ch);
381         void set_string_nth_slow(string *str_, cell index, cell ch);
382         void set_string_nth(string *str, cell index, cell ch);
383         string *allot_string_internal(cell capacity);
384         void fill_string(string *str_, cell start, cell capacity, cell fill);
385         string *allot_string(cell capacity, cell fill);
386         void primitive_string();
387         bool reallot_string_in_place_p(string *str, cell capacity);
388         string* reallot_string(string *str_, cell capacity);
389         void primitive_resize_string();
390         void primitive_string_nth();
391         void primitive_set_string_nth_fast();
392         void primitive_set_string_nth_slow();
393
394         // booleans
395         cell tag_boolean(cell untagged)
396         {
397                 return (untagged ? true_object : false_object);
398         }
399
400         // byte arrays
401         byte_array *allot_byte_array(cell size);
402         void primitive_byte_array();
403         void primitive_uninitialized_byte_array();
404         void primitive_resize_byte_array();
405
406         template<typename Type> byte_array *byte_array_from_value(Type *value);
407
408         // tuples
409         void primitive_tuple();
410         void primitive_tuple_boa();
411
412         // words
413         word *allot_word(cell name_, cell vocab_, cell hashcode_);
414         void primitive_word();
415         void primitive_word_code();
416         void update_word_entry_point(word *w_);
417         void primitive_optimized_p();
418         void primitive_wrapper();
419         void jit_compile_word(cell word_, cell def_, bool relocating);
420         cell find_all_words();
421         void compile_all_words();
422
423         // math
424         void primitive_bignum_to_fixnum();
425         void primitive_float_to_fixnum();
426         void primitive_fixnum_divint();
427         void primitive_fixnum_divmod();
428         bignum *fixnum_to_bignum(fixnum);
429         bignum *cell_to_bignum(cell);
430         bignum *long_long_to_bignum(s64 n);
431         bignum *ulong_long_to_bignum(u64 n);
432         inline fixnum sign_mask(fixnum x);
433         inline fixnum branchless_max(fixnum x, fixnum y);
434         inline fixnum branchless_abs(fixnum x);
435         void primitive_fixnum_shift();
436         void primitive_fixnum_to_bignum();
437         void primitive_float_to_bignum();
438         void primitive_bignum_eq();
439         void primitive_bignum_add();
440         void primitive_bignum_subtract();
441         void primitive_bignum_multiply();
442         void primitive_bignum_divint();
443         void primitive_bignum_divmod();
444         void primitive_bignum_mod();
445         void primitive_bignum_and();
446         void primitive_bignum_or();
447         void primitive_bignum_xor();
448         void primitive_bignum_shift();
449         void primitive_bignum_less();
450         void primitive_bignum_lesseq();
451         void primitive_bignum_greater();
452         void primitive_bignum_greatereq();
453         void primitive_bignum_not();
454         void primitive_bignum_bitp();
455         void primitive_bignum_log2();
456         unsigned int bignum_producer(unsigned int digit);
457         void primitive_byte_array_to_bignum();
458         inline cell unbox_array_size();
459         cell unbox_array_size_slow();
460         void primitive_fixnum_to_float();
461         void primitive_bignum_to_float();
462         void primitive_float_to_str();
463         void primitive_float_eq();
464         void primitive_float_add();
465         void primitive_float_subtract();
466         void primitive_float_multiply();
467         void primitive_float_divfloat();
468         void primitive_float_mod();
469         void primitive_float_less();
470         void primitive_float_lesseq();
471         void primitive_float_greater();
472         void primitive_float_greatereq();
473         void primitive_float_bits();
474         void primitive_bits_float();
475         void primitive_double_bits();
476         void primitive_bits_double();
477         fixnum to_fixnum(cell tagged);
478         cell to_cell(cell tagged);
479         cell from_signed_1(s8 n);
480         cell from_unsigned_1(u8 n);
481         cell from_signed_2(s16 n);
482         cell from_unsigned_2(u16 n);
483         cell from_signed_4(s32 n);
484         cell from_unsigned_4(u32 n);
485         cell from_signed_cell(fixnum integer);
486         cell from_unsigned_cell(cell integer);
487         cell from_signed_8(s64 n);
488         s64 to_signed_8(cell obj);
489         cell from_unsigned_8(u64 n);
490         u64 to_unsigned_8(cell obj);
491         float to_float(cell value);
492         double to_double(cell value);
493         inline void overflow_fixnum_add(fixnum x, fixnum y);
494         inline void overflow_fixnum_subtract(fixnum x, fixnum y);
495         inline void overflow_fixnum_multiply(fixnum x, fixnum y);
496         inline cell allot_integer(fixnum x);
497         inline cell allot_cell(cell x);
498         inline cell allot_float(double n);
499         inline bignum *float_to_bignum(cell tagged);
500         inline double bignum_to_float(cell tagged);
501         inline double untag_float(cell tagged);
502         inline double untag_float_check(cell tagged);
503         inline fixnum float_to_fixnum(cell tagged);
504         inline double fixnum_to_float(cell tagged);
505
506         // tagged
507         template<typename Type> Type *untag_check(cell value);
508
509         // io
510         void init_c_io();
511         void io_error();
512         FILE* safe_fopen(char *filename, char *mode);
513         int safe_fgetc(FILE *stream);
514         size_t safe_fread(void *ptr, size_t size, size_t nitems, FILE *stream);
515         void safe_fputc(int c, FILE* stream);
516         size_t safe_fwrite(void *ptr, size_t size, size_t nitems, FILE *stream);
517         int safe_ftell(FILE *stream);
518         void safe_fseek(FILE *stream, off_t offset, int whence);
519         void safe_fflush(FILE *stream);
520         void safe_fclose(FILE *stream);
521         void primitive_fopen();
522         FILE *pop_file_handle();
523         void primitive_fgetc();
524         void primitive_fread();
525         void primitive_fputc();
526         void primitive_fwrite();
527         void primitive_ftell();
528         void primitive_fseek();
529         void primitive_fflush();
530         void primitive_fclose();
531
532         // code_block
533         cell compute_entry_point_address(cell obj);
534         cell compute_entry_point_pic_address(word *w, cell tagged_quot);
535         cell compute_entry_point_pic_address(cell w_);
536         cell compute_entry_point_pic_tail_address(cell w_);
537         cell code_block_owner(code_block *compiled);
538         void update_word_references(code_block *compiled, bool reset_inline_caches);
539         void undefined_symbol();
540         cell compute_dlsym_address(array *literals, cell index);
541         cell compute_vm_address(cell arg);
542         void store_external_address(instruction_operand op);
543         cell compute_here_address(cell arg, cell offset, code_block *compiled);
544         void initialize_code_block(code_block *compiled, cell literals);
545         void initialize_code_block(code_block *compiled);
546         void fixup_labels(array *labels, code_block *compiled);
547         code_block *allot_code_block(cell size, code_block_type type);
548         code_block *add_code_block(code_block_type type, cell code_, cell labels_, cell owner_, cell relocation_, cell parameters_, cell literals_);
549
550         //code heap
551         inline void check_code_pointer(cell ptr) { }
552
553         template<typename Iterator> void each_code_block(Iterator &iter)
554         {
555                 code->allocator->iterate(iter);
556         }
557
558         void init_code_heap(cell size);
559         bool in_code_heap_p(cell ptr);
560         void update_code_heap_words(bool reset_inline_caches);
561         void initialize_code_blocks();
562         void primitive_modify_code_heap();
563         code_heap_room code_room();
564         void primitive_code_room();
565         void primitive_strip_stack_traces();
566         cell code_blocks();
567         void primitive_code_blocks();
568
569         // callbacks
570         void init_callbacks(cell size);
571         void primitive_callback();
572
573         // image
574         void init_objects(image_header *h);
575         void load_data_heap(FILE *file, image_header *h, vm_parameters *p);
576         void load_code_heap(FILE *file, image_header *h, vm_parameters *p);
577         bool save_image(const vm_char *saving_filename, const vm_char *filename);
578         void primitive_save_image();
579         void primitive_save_image_and_exit();
580         void fixup_data(cell data_offset, cell code_offset);
581         void fixup_code(cell data_offset, cell code_offset);
582         void load_image(vm_parameters *p);
583
584         // callstack
585         template<typename Iterator> void iterate_callstack_object(callstack *stack_, Iterator &iterator);
586         void check_frame(stack_frame *frame);
587         callstack *allot_callstack(cell size);
588         stack_frame *fix_callstack_top(stack_frame *top);
589         stack_frame *second_from_top_stack_frame();
590         void primitive_callstack();
591         code_block *frame_code(stack_frame *frame);
592         code_block_type frame_type(stack_frame *frame);
593         cell frame_executing(stack_frame *frame);
594         cell frame_executing_quot(stack_frame *frame);
595         stack_frame *frame_successor(stack_frame *frame);
596         cell frame_scan(stack_frame *frame);
597         void primitive_callstack_to_array();
598         stack_frame *innermost_stack_frame(callstack *stack);
599         void primitive_innermost_stack_frame_executing();
600         void primitive_innermost_stack_frame_scan();
601         void primitive_set_innermost_stack_frame_quot();
602         template<typename Iterator> void iterate_callstack(context *ctx, Iterator &iterator);
603
604         // alien
605         char *pinned_alien_offset(cell obj);
606         cell allot_alien(cell delegate_, cell displacement);
607         cell allot_alien(void *address);
608         void primitive_displaced_alien();
609         void primitive_alien_address();
610         void *alien_pointer();
611         void primitive_dlopen();
612         void primitive_dlsym();
613         void primitive_dlclose();
614         void primitive_dll_validp();
615         char *alien_offset(cell obj);
616         void to_value_struct(cell src, void *dest, cell size);
617         cell from_value_struct(void *src, cell size);
618         cell from_small_struct(cell x, cell y, cell size);
619         cell from_medium_struct(cell x1, cell x2, cell x3, cell x4, cell size);
620
621         // quotations
622         void primitive_jit_compile();
623         code_block *lazy_jit_compile_block();
624         void primitive_array_to_quotation();
625         void primitive_quotation_code();
626         void set_quot_entry_point(quotation *quot, code_block *code);
627         code_block *jit_compile_quot(cell owner_, cell quot_, bool relocating);
628         void jit_compile_quot(cell quot_, bool relocating);
629         fixnum quot_code_offset_to_scan(cell quot_, cell offset);
630         cell lazy_jit_compile(cell quot);
631         bool quot_compiled_p(quotation *quot);
632         void primitive_quot_compiled_p();
633         cell find_all_quotations();
634         void initialize_all_quotations();
635
636         // dispatch
637         cell search_lookup_alist(cell table, cell klass);
638         cell search_lookup_hash(cell table, cell klass, cell hashcode);
639         cell nth_superclass(tuple_layout *layout, fixnum echelon);
640         cell nth_hashcode(tuple_layout *layout, fixnum echelon);
641         cell lookup_tuple_method(cell obj, cell methods);
642         cell lookup_method(cell obj, cell methods);
643         void primitive_lookup_method();
644         cell object_class(cell obj);
645         cell method_cache_hashcode(cell klass, array *array);
646         void update_method_cache(cell cache, cell klass, cell method);
647         void primitive_mega_cache_miss();
648         void primitive_reset_dispatch_stats();
649         void primitive_dispatch_stats();
650
651         // inline cache
652         void init_inline_caching(int max_size);
653         void deallocate_inline_cache(cell return_address);
654         cell determine_inline_cache_type(array *cache_entries);
655         void update_pic_count(cell type);
656         code_block *compile_inline_cache(fixnum index,cell generic_word_,cell methods_,cell cache_entries_,bool tail_call_p);
657         void *megamorphic_call_stub(cell generic_word);
658         cell inline_cache_size(cell cache_entries);
659         cell add_inline_cache_entry(cell cache_entries_, cell klass_, cell method_);
660         void update_pic_transitions(cell pic_size);
661         void *inline_cache_miss(cell return_address);
662
663         // entry points
664         void c_to_factor(cell quot);
665         void unwind_native_frames(cell quot, stack_frame *to);
666
667         // factor
668         void default_parameters(vm_parameters *p);
669         bool factor_arg(const vm_char *str, const vm_char *arg, cell *value);
670         void init_parameters_from_args(vm_parameters *p, int argc, vm_char **argv);
671         void prepare_boot_image();
672         void init_factor(vm_parameters *p);
673         void pass_args_to_factor(int argc, vm_char **argv);
674         void start_factor(vm_parameters *p);
675         void stop_factor();
676         void start_embedded_factor(vm_parameters *p);
677         void start_standalone_factor(int argc, vm_char **argv);
678         char *factor_eval_string(char *string);
679         void factor_eval_free(char *result);
680         void factor_yield();
681         void factor_sleep(long us);
682
683         // os-*
684         void primitive_existsp();
685         void move_file(const vm_char *path1, const vm_char *path2);
686         void init_ffi();
687         void ffi_dlopen(dll *dll);
688         void *ffi_dlsym(dll *dll, symbol_char *symbol);
689         void ffi_dlclose(dll *dll);
690         void c_to_factor_toplevel(cell quot);
691         void init_signals();
692
693         // os-windows
694   #if defined(WINDOWS)
695         const vm_char *vm_executable_path();
696         const vm_char *default_image_path();
697         void windows_image_path(vm_char *full_path, vm_char *temp_path, unsigned int length);
698         BOOL windows_stat(vm_char *path);
699
700   #if defined(WINNT)
701         void open_console();
702         LONG exception_handler(PEXCEPTION_POINTERS pe);
703   #endif
704
705   #else  // UNIX
706         void dispatch_signal(void *uap, void (handler)());
707         void unix_init_signals();
708   #endif
709
710   #ifdef __APPLE__
711         void call_fault_handler(exception_type_t exception, exception_data_type_t code, MACH_EXC_STATE_TYPE *exc_state, MACH_THREAD_STATE_TYPE *thread_state, MACH_FLOAT_STATE_TYPE *float_state);
712   #endif
713
714         factor_vm();
715         ~factor_vm();
716 };
717
718 }