]> gitweb.factorcode.org Git - factor.git/blob - vm/vm.hpp
renamed vmprim_ to primitive_
[factor.git] / vm / vm.hpp
1 #include "vm-data.hpp"
2
3 namespace factor
4 {
5
6 struct factorvm : factorvmdata {
7
8         // segments
9         inline cell align_page(cell a);
10
11         // contexts
12         void reset_datastack();
13         void reset_retainstack();
14         void fix_stacks();
15         void save_stacks();
16         context *alloc_context();
17         void dealloc_context(context *old_context);
18         void nest_stacks();
19         void unnest_stacks();
20         void init_stacks(cell ds_size_, cell rs_size_);
21         bool stack_to_array(cell bottom, cell top);
22         cell array_to_stack(array *array, cell bottom);
23         inline void primitive_datastack();
24         inline void primitive_retainstack();
25         inline void primitive_set_datastack();
26         inline void primitive_set_retainstack();
27         inline void primitive_check_datastack();
28
29         // run
30         inline void primitive_getenv();
31         inline void primitive_setenv();
32         inline void primitive_exit();
33         inline void primitive_micros();
34         inline void primitive_sleep();
35         inline void primitive_set_slot();
36         inline void primitive_load_locals();
37         cell clone_object(cell obj_);
38         inline void primitive_clone();
39
40         // profiler
41         void init_profiler();
42         code_block *compile_profiling_stub(cell word_);
43         void set_profiling(bool profiling);
44         inline void primitive_profiling();
45
46         // errors
47         void out_of_memory();
48         void critical_error(const char* msg, cell tagged);
49         void throw_error(cell error, stack_frame *callstack_top);
50         void not_implemented_error();
51         bool in_page(cell fault, cell area, cell area_size, int offset);
52         void memory_protection_error(cell addr, stack_frame *native_stack);
53         void signal_error(int signal, stack_frame *native_stack);
54         void divide_by_zero_error();
55         void fp_trap_error(unsigned int fpu_status, stack_frame *signal_callstack_top);
56         inline void primitive_call_clear();
57         inline void primitive_unimplemented();
58         void memory_signal_handler_impl();
59         void misc_signal_handler_impl();
60         void fp_signal_handler_impl();
61         void type_error(cell type, cell tagged);
62         void general_error(vm_error_type error, cell arg1, cell arg2, stack_frame *native_stack);
63
64         //callstack
65
66         // bignum
67         int bignum_equal_p(bignum * x, bignum * y);
68         enum bignum_comparison bignum_compare(bignum * x, bignum * y);
69         bignum *bignum_add(bignum * x, bignum * y);
70         bignum *bignum_subtract(bignum * x, bignum * y);
71         bignum *bignum_multiply(bignum * x, bignum * y);
72         void bignum_divide(bignum * numerator, bignum * denominator, bignum * * quotient, bignum * * remainder);
73         bignum *bignum_quotient(bignum * numerator, bignum * denominator);
74         bignum *bignum_remainder(bignum * numerator, bignum * denominator);
75         cell bignum_to_cell(bignum * bignum);
76         fixnum bignum_to_fixnum(bignum * bignum);
77         s64 bignum_to_long_long(bignum * bignum);
78         u64 bignum_to_ulong_long(bignum * bignum);
79         double bignum_to_double(bignum * bignum);
80         bignum *double_to_bignum(double x);
81         int bignum_equal_p_unsigned(bignum * x, bignum * y);
82         enum bignum_comparison bignum_compare_unsigned(bignum * x, bignum * y);
83         bignum *bignum_add_unsigned(bignum * x, bignum * y, int negative_p);
84         bignum *bignum_subtract_unsigned(bignum * x, bignum * y);
85         bignum *bignum_multiply_unsigned(bignum * x, bignum * y, int negative_p);
86         bignum *bignum_multiply_unsigned_small_factor(bignum * x, bignum_digit_type y,int negative_p);
87         void bignum_destructive_add(bignum * bignum, bignum_digit_type n);
88         void bignum_destructive_scale_up(bignum * bignum, bignum_digit_type factor);
89         void bignum_divide_unsigned_large_denominator(bignum * numerator, bignum * denominator, 
90                                                                                                   bignum * * quotient, bignum * * remainder, int q_negative_p, int r_negative_p);
91         void bignum_divide_unsigned_normalized(bignum * u, bignum * v, bignum * q);
92         bignum_digit_type bignum_divide_subtract(bignum_digit_type * v_start, bignum_digit_type * v_end, 
93                                                                                          bignum_digit_type guess, bignum_digit_type * u_start);
94         void bignum_divide_unsigned_medium_denominator(bignum * numerator,bignum_digit_type denominator, 
95                                                                                                    bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p);
96         void bignum_destructive_normalization(bignum * source, bignum * target, int shift_left);
97         void bignum_destructive_unnormalization(bignum * bignum, int shift_right);
98         bignum_digit_type bignum_digit_divide(bignum_digit_type uh, bignum_digit_type ul, 
99                                                                                   bignum_digit_type v, bignum_digit_type * q) /* return value */;
100         bignum_digit_type bignum_digit_divide_subtract(bignum_digit_type v1, bignum_digit_type v2, 
101                                                                                                    bignum_digit_type guess, bignum_digit_type * u);
102         void bignum_divide_unsigned_small_denominator(bignum * numerator, bignum_digit_type denominator, 
103                                                                                                   bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p);
104         bignum_digit_type bignum_destructive_scale_down(bignum * bignum, bignum_digit_type denominator);
105         bignum * bignum_remainder_unsigned_small_denominator(bignum * n, bignum_digit_type d, int negative_p);
106         bignum *bignum_digit_to_bignum(bignum_digit_type digit, int negative_p);
107         bignum *allot_bignum(bignum_length_type length, int negative_p);
108         bignum * allot_bignum_zeroed(bignum_length_type length, int negative_p);
109         bignum *bignum_shorten_length(bignum * bignum, bignum_length_type length);
110         bignum *bignum_trim(bignum * bignum);
111         bignum *bignum_new_sign(bignum * x, int negative_p);
112         bignum *bignum_maybe_new_sign(bignum * x, int negative_p);
113         void bignum_destructive_copy(bignum * source, bignum * target);
114         bignum *bignum_bitwise_not(bignum * x);
115         bignum *bignum_arithmetic_shift(bignum * arg1, fixnum n);
116         bignum *bignum_bitwise_and(bignum * arg1, bignum * arg2);
117         bignum *bignum_bitwise_ior(bignum * arg1, bignum * arg2);
118         bignum *bignum_bitwise_xor(bignum * arg1, bignum * arg2);
119         bignum *bignum_magnitude_ash(bignum * arg1, fixnum n);
120         bignum *bignum_pospos_bitwise_op(int op, bignum * arg1, bignum * arg2);
121         bignum *bignum_posneg_bitwise_op(int op, bignum * arg1, bignum * arg2);
122         bignum *bignum_negneg_bitwise_op(int op, bignum * arg1, bignum * arg2);
123         void bignum_negate_magnitude(bignum * arg);
124         bignum *bignum_integer_length(bignum * x);
125         int bignum_logbitp(int shift, bignum * arg);
126         int bignum_unsigned_logbitp(int shift, bignum * bignum);
127         bignum *digit_stream_to_bignum(unsigned int n_digits, unsigned int (*producer)(unsigned int, factorvm *), unsigned int radix, int negative_p);
128
129         //data_heap
130         cell init_zone(zone *z, cell size, cell start);
131         void init_card_decks();
132         data_heap *alloc_data_heap(cell gens, cell young_size,cell aging_size,cell tenured_size);
133         data_heap *grow_data_heap(data_heap *data, cell requested_bytes);
134         void dealloc_data_heap(data_heap *data);
135         void clear_cards(cell from, cell to);
136         void clear_decks(cell from, cell to);
137         void clear_allot_markers(cell from, cell to);
138         void reset_generation(cell i);
139         void reset_generations(cell from, cell to);
140         void set_data_heap(data_heap *data_);
141         void init_data_heap(cell gens,cell young_size,cell aging_size,cell tenured_size,bool secure_gc_);
142         cell untagged_object_size(object *pointer);
143         cell unaligned_object_size(object *pointer);
144         inline void primitive_size();
145         cell binary_payload_start(object *pointer);
146         inline void primitive_data_room();
147         void begin_scan();
148         void end_scan();
149         inline void primitive_begin_scan();
150         cell next_object();
151         inline void primitive_next_object();
152         inline void primitive_end_scan();
153         template<typename T> void each_object(T &functor);
154         cell find_all_words();
155         cell object_size(cell tagged);
156
157         
158         //write barrier
159         inline card *addr_to_card(cell a);
160         inline cell card_to_addr(card *c);
161         inline cell card_offset(card *c);
162         inline card_deck *addr_to_deck(cell a);
163         inline cell deck_to_addr(card_deck *c);
164         inline card *deck_to_card(card_deck *d);
165         inline card *addr_to_allot_marker(object *a);
166         inline void write_barrier(object *obj);
167         inline void allot_barrier(object *address);
168
169
170         //data_gc
171         void init_data_gc();
172         object *copy_untagged_object_impl(object *pointer, cell size);
173         object *copy_object_impl(object *untagged);
174         bool should_copy_p(object *untagged);
175         object *resolve_forwarding(object *untagged);
176         template <typename T> T *copy_untagged_object(T *untagged);
177         cell copy_object(cell pointer);
178         void copy_handle(cell *handle);
179         void copy_card(card *ptr, cell gen, cell here);
180         void copy_card_deck(card_deck *deck, cell gen, card mask, card unmask);
181         void copy_gen_cards(cell gen);
182         void copy_cards();
183         void copy_stack_elements(segment *region, cell top);
184         void copy_registered_locals();
185         void copy_registered_bignums();
186         void copy_roots();
187         cell copy_next_from_nursery(cell scan);
188         cell copy_next_from_aging(cell scan);
189         cell copy_next_from_tenured(cell scan);
190         void copy_reachable_objects(cell scan, cell *end);
191         void begin_gc(cell requested_bytes);
192         void end_gc(cell gc_elapsed);
193         void garbage_collection(cell gen,bool growing_data_heap_,cell requested_bytes);
194         void gc();
195         inline void primitive_gc();
196         inline void primitive_gc_stats();
197         void clear_gc_stats();
198         inline void primitive_become();
199         void inline_gc(cell *gc_roots_base, cell gc_roots_size);
200         inline bool collecting_accumulation_gen_p();
201         inline object *allot_zone(zone *z, cell a);
202         inline object *allot_object(header header, cell size);
203         template <typename TYPE> TYPE *allot(cell size);
204         inline void check_data_pointer(object *pointer);
205         inline void check_tagged_pointer(cell tagged);
206         inline void primitive_clear_gc_stats();
207
208         // generic arrays
209         template <typename T> T *allot_array_internal(cell capacity);
210         template <typename T> bool reallot_array_in_place_p(T *array, cell capacity);
211         template <typename TYPE> TYPE *reallot_array(TYPE *array_, cell capacity);
212
213         //debug
214         void print_chars(string* str);
215         void print_word(word* word, cell nesting);
216         void print_factor_string(string* str);
217         void print_array(array* array, cell nesting);
218         void print_tuple(tuple *tuple, cell nesting);
219         void print_nested_obj(cell obj, fixnum nesting);
220         void print_obj(cell obj);
221         void print_objects(cell *start, cell *end);
222         void print_datastack();
223         void print_retainstack();
224         void print_stack_frame(stack_frame *frame);
225         void print_callstack();
226         void dump_cell(cell x);
227         void dump_memory(cell from, cell to);
228         void dump_zone(zone *z);
229         void dump_generations();
230         void dump_objects(cell type);
231         void find_data_references_step(cell *scan);
232         void find_data_references(cell look_for_);
233         void dump_code_heap();
234         void factorbug();
235         inline void primitive_die();
236
237         //arrays
238         array *allot_array(cell capacity, cell fill_);
239         inline void primitive_array();
240         cell allot_array_1(cell obj_);
241         cell allot_array_2(cell v1_, cell v2_);
242         cell allot_array_4(cell v1_, cell v2_, cell v3_, cell v4_);
243         inline void primitive_resize_array();
244         inline void set_array_nth(array *array, cell slot, cell value);
245
246         //strings
247         cell string_nth(string* str, cell index);
248         void set_string_nth_fast(string *str, cell index, cell ch);
249         void set_string_nth_slow(string *str_, cell index, cell ch);
250         void set_string_nth(string *str, cell index, cell ch);
251         string *allot_string_internal(cell capacity);
252         void fill_string(string *str_, cell start, cell capacity, cell fill);
253         string *allot_string(cell capacity, cell fill);
254         inline void primitive_string();
255         bool reallot_string_in_place_p(string *str, cell capacity);
256         string* reallot_string(string *str_, cell capacity);
257         inline void primitive_resize_string();
258         inline void primitive_string_nth();
259         inline void primitive_set_string_nth_fast();
260         inline void primitive_set_string_nth_slow();
261
262         //booleans
263         void box_boolean(bool value);
264         bool to_boolean(cell value);
265         inline cell tag_boolean(cell untagged);
266
267         //byte arrays
268         byte_array *allot_byte_array(cell size);
269         inline void primitive_byte_array();
270         inline void primitive_uninitialized_byte_array();
271         inline void primitive_resize_byte_array();
272
273         //tuples
274         tuple *allot_tuple(cell layout_);
275         inline void primitive_tuple();
276         inline void primitive_tuple_boa();
277
278         //words
279         word *allot_word(cell vocab_, cell name_);
280         inline void primitive_word();
281         inline void primitive_word_xt();
282         void update_word_xt(cell w_);
283         inline void primitive_optimized_p();
284         inline void primitive_wrapper();
285
286         //math
287         inline void primitive_bignum_to_fixnum();
288         inline void primitive_float_to_fixnum();
289         inline void primitive_fixnum_divint();
290         inline void primitive_fixnum_divmod();
291         bignum *fixnum_to_bignum(fixnum);
292         bignum *cell_to_bignum(cell);
293         bignum *long_long_to_bignum(s64 n);
294         bignum *ulong_long_to_bignum(u64 n);
295         inline fixnum sign_mask(fixnum x);
296         inline fixnum branchless_max(fixnum x, fixnum y);
297         inline fixnum branchless_abs(fixnum x);
298         inline void primitive_fixnum_shift();
299         inline void primitive_fixnum_to_bignum();
300         inline void primitive_float_to_bignum();
301         inline void primitive_bignum_eq();
302         inline void primitive_bignum_add();
303         inline void primitive_bignum_subtract();
304         inline void primitive_bignum_multiply();
305         inline void primitive_bignum_divint();
306         inline void primitive_bignum_divmod();
307         inline void primitive_bignum_mod();
308         inline void primitive_bignum_and();
309         inline void primitive_bignum_or();
310         inline void primitive_bignum_xor();
311         inline void primitive_bignum_shift();
312         inline void primitive_bignum_less();
313         inline void primitive_bignum_lesseq();
314         inline void primitive_bignum_greater();
315         inline void primitive_bignum_greatereq();
316         inline void primitive_bignum_not();
317         inline void primitive_bignum_bitp();
318         inline void primitive_bignum_log2();
319         unsigned int bignum_producer(unsigned int digit);
320         inline void primitive_byte_array_to_bignum();
321         cell unbox_array_size();
322         inline void primitive_fixnum_to_float();
323         inline void primitive_bignum_to_float();
324         inline void primitive_str_to_float();
325         inline void primitive_float_to_str();
326         inline void primitive_float_eq();
327         inline void primitive_float_add();
328         inline void primitive_float_subtract();
329         inline void primitive_float_multiply();
330         inline void primitive_float_divfloat();
331         inline void primitive_float_mod();
332         inline void primitive_float_less();
333         inline void primitive_float_lesseq();
334         inline void primitive_float_greater();
335         inline void primitive_float_greatereq();
336         inline void primitive_float_bits();
337         inline void primitive_bits_float();
338         inline void primitive_double_bits();
339         inline void primitive_bits_double();
340         fixnum to_fixnum(cell tagged);
341         cell to_cell(cell tagged);
342         void box_signed_1(s8 n);
343         void box_unsigned_1(u8 n);
344         void box_signed_2(s16 n);
345         void box_unsigned_2(u16 n);
346         void box_signed_4(s32 n);
347         void box_unsigned_4(u32 n);
348         void box_signed_cell(fixnum integer);
349         void box_unsigned_cell(cell cell);
350         void box_signed_8(s64 n);
351         s64 to_signed_8(cell obj);
352         void box_unsigned_8(u64 n);
353         u64 to_unsigned_8(cell obj);
354         void box_float(float flo);
355         float to_float(cell value);
356         void box_double(double flo);
357         double to_double(cell value);
358         inline void overflow_fixnum_add(fixnum x, fixnum y);
359         inline void overflow_fixnum_subtract(fixnum x, fixnum y);
360         inline void overflow_fixnum_multiply(fixnum x, fixnum y);
361         inline cell allot_integer(fixnum x);
362         inline cell allot_cell(cell x);
363         inline cell allot_float(double n);
364         inline bignum *float_to_bignum(cell tagged);
365         inline double bignum_to_float(cell tagged);
366         inline double untag_float(cell tagged);
367         inline double untag_float_check(cell tagged);
368         inline fixnum float_to_fixnum(cell tagged);
369         inline double fixnum_to_float(cell tagged);
370         template <typename T> T *untag_check(cell value);
371         template <typename T> T *untag(cell value);
372         
373         //io
374         void init_c_io();
375         void io_error();
376         inline void primitive_fopen();
377         inline void primitive_fgetc();
378         inline void primitive_fread();
379         inline void primitive_fputc();
380         inline void primitive_fwrite();
381         inline void primitive_fseek();
382         inline void primitive_fflush();
383         inline void primitive_fclose();
384
385         //code_gc
386         void clear_free_list(heap *heap);
387         void new_heap(heap *heap, cell size);
388         void add_to_free_list(heap *heap, free_heap_block *block);
389         void build_free_list(heap *heap, cell size);
390         void assert_free_block(free_heap_block *block);
391         free_heap_block *find_free_block(heap *heap, cell size);
392         free_heap_block *split_free_block(heap *heap, free_heap_block *block, cell size);
393         heap_block *heap_allot(heap *heap, cell size);
394         void heap_free(heap *heap, heap_block *block);
395         void mark_block(heap_block *block);
396         void unmark_marked(heap *heap);
397         void free_unmarked(heap *heap, heap_iterator iter);
398         void heap_usage(heap *heap, cell *used, cell *total_free, cell *max_free);
399         cell heap_size(heap *heap);
400         cell compute_heap_forwarding(heap *heap, unordered_map<heap_block *,char *> &forwarding);
401         void compact_heap(heap *heap, unordered_map<heap_block *,char *> &forwarding);
402
403         //code_block
404         relocation_type relocation_type_of(relocation_entry r);
405         relocation_class relocation_class_of(relocation_entry r);
406         cell relocation_offset_of(relocation_entry r);
407         void flush_icache_for(code_block *block);
408         int number_of_parameters(relocation_type type);
409         void *object_xt(cell obj);
410         void *xt_pic(word *w, cell tagged_quot);
411         void *word_xt_pic(word *w);
412         void *word_xt_pic_tail(word *w);
413         void undefined_symbol();
414         void *get_rel_symbol(array *literals, cell index);
415         cell compute_relocation(relocation_entry rel, cell index, code_block *compiled);
416         void iterate_relocations(code_block *compiled, relocation_iterator iter);
417         void store_address_2_2(cell *ptr, cell value);
418         void store_address_masked(cell *ptr, fixnum value, cell mask, fixnum shift);
419         void store_address_in_code_block(cell klass, cell offset, fixnum absolute_value);
420         void update_literal_references_step(relocation_entry rel, cell index, code_block *compiled);
421         void update_literal_references(code_block *compiled);
422         void copy_literal_references(code_block *compiled);
423         void relocate_code_block_step(relocation_entry rel, cell index, code_block *compiled);
424         void update_word_references_step(relocation_entry rel, cell index, code_block *compiled);
425         void update_word_references(code_block *compiled);
426         void update_literal_and_word_references(code_block *compiled);
427         void check_code_address(cell address);
428         void mark_code_block(code_block *compiled);
429         void mark_stack_frame_step(stack_frame *frame);
430         void mark_active_blocks(context *stacks);
431         void mark_object_code_block(object *object);
432         void relocate_code_block(code_block *compiled);
433         void fixup_labels(array *labels, code_block *compiled);
434         code_block *allot_code_block(cell size);
435         code_block *add_code_block(cell type,cell code_,cell labels_,cell relocation_,cell literals_);
436         inline bool stack_traces_p()
437         {
438                 return userenv[STACK_TRACES_ENV] != F;
439         }
440
441         //code_heap
442         void init_code_heap(cell size);
443         bool in_code_heap_p(cell ptr);
444         void jit_compile_word(cell word_, cell def_, bool relocate);
445         void iterate_code_heap(code_heap_iterator iter);
446         void copy_code_heap_roots();
447         void update_code_heap_words();
448         inline void primitive_modify_code_heap();
449         inline void primitive_code_room();
450         code_block *forward_xt(code_block *compiled);
451         void forward_frame_xt(stack_frame *frame);
452         void forward_object_xts();
453         void fixup_object_xts();
454         void compact_code_heap();
455         inline void check_code_pointer(cell ptr);
456
457
458         //image
459         void init_objects(image_header *h);
460         void load_data_heap(FILE *file, image_header *h, vm_parameters *p);
461         void load_code_heap(FILE *file, image_header *h, vm_parameters *p);
462         bool save_image(const vm_char *filename);
463         inline void primitive_save_image();
464         inline void primitive_save_image_and_exit();
465         void data_fixup(cell *cell);
466         template <typename T> void code_fixup(T **handle);
467         void fixup_word(word *word);
468         void fixup_quotation(quotation *quot);
469         void fixup_alien(alien *d);
470         void fixup_stack_frame(stack_frame *frame);
471         void fixup_callstack_object(callstack *stack);
472         void relocate_object(object *object);
473         void relocate_data();
474         void fixup_code_block(code_block *compiled);
475         void relocate_code();
476         void load_image(vm_parameters *p);
477
478         //callstack
479         template<typename T> void iterate_callstack_object(callstack *stack_, T &iterator);
480         void check_frame(stack_frame *frame);
481         callstack *allot_callstack(cell size);
482         stack_frame *fix_callstack_top(stack_frame *top, stack_frame *bottom);
483         stack_frame *capture_start();
484         inline void primitive_callstack();
485         inline void primitive_set_callstack();
486         code_block *frame_code(stack_frame *frame);
487         cell frame_type(stack_frame *frame);
488         cell frame_executing(stack_frame *frame);
489         stack_frame *frame_successor(stack_frame *frame);
490         cell frame_scan(stack_frame *frame);
491         inline void primitive_callstack_to_array();
492         stack_frame *innermost_stack_frame(callstack *stack);
493         stack_frame *innermost_stack_frame_quot(callstack *callstack);
494         inline void primitive_innermost_stack_frame_executing();
495         inline void primitive_innermost_stack_frame_scan();
496         inline void primitive_set_innermost_stack_frame_quot();
497         void save_callstack_bottom(stack_frame *callstack_bottom);
498         template<typename T> void iterate_callstack(cell top, cell bottom, T &iterator);
499         inline void do_slots(cell obj, void (* iter)(cell *,factorvm*));
500
501
502         //alien
503         char *pinned_alien_offset(cell obj);
504         cell allot_alien(cell delegate_, cell displacement);
505         inline void primitive_displaced_alien();
506         inline void primitive_alien_address();
507         void *alien_pointer();
508         inline void primitive_dlopen();
509         inline void primitive_dlsym();
510         inline void primitive_dlclose();
511         inline void primitive_dll_validp();
512         inline void primitive_vm_ptr();
513         char *alien_offset(cell obj);
514         char *unbox_alien();
515         void box_alien(void *ptr);
516         void to_value_struct(cell src, void *dest, cell size);
517         void box_value_struct(void *src, cell size);
518         void box_small_struct(cell x, cell y, cell size);
519         void box_medium_struct(cell x1, cell x2, cell x3, cell x4, cell size);
520
521         //quotations
522         inline void primitive_jit_compile();
523         inline void primitive_array_to_quotation();
524         inline void primitive_quotation_xt();
525         void set_quot_xt(quotation *quot, code_block *code);
526         void jit_compile(cell quot_, bool relocating);
527         void compile_all_words();
528         fixnum quot_code_offset_to_scan(cell quot_, cell offset);
529         cell lazy_jit_compile_impl(cell quot_, stack_frame *stack);
530         inline void primitive_quot_compiled_p();
531
532         //dispatch
533         cell search_lookup_alist(cell table, cell klass);
534         cell search_lookup_hash(cell table, cell klass, cell hashcode);
535         cell nth_superclass(tuple_layout *layout, fixnum echelon);
536         cell nth_hashcode(tuple_layout *layout, fixnum echelon);
537         cell lookup_tuple_method(cell obj, cell methods);
538         cell lookup_hi_tag_method(cell obj, cell methods);
539         cell lookup_hairy_method(cell obj, cell methods);
540         cell lookup_method(cell obj, cell methods);
541         inline void primitive_lookup_method();
542         cell object_class(cell obj);
543         cell method_cache_hashcode(cell klass, array *array);
544         void update_method_cache(cell cache, cell klass, cell method);
545         inline void primitive_mega_cache_miss();
546         inline void primitive_reset_dispatch_stats();
547         inline void primitive_dispatch_stats();
548
549         //inline cache
550         void init_inline_caching(int max_size);
551         void deallocate_inline_cache(cell return_address);
552         cell determine_inline_cache_type(array *cache_entries);
553         void update_pic_count(cell type);
554         code_block *compile_inline_cache(fixnum index,cell generic_word_,cell methods_,cell cache_entries_,bool tail_call_p);
555         void *megamorphic_call_stub(cell generic_word);
556         cell inline_cache_size(cell cache_entries);
557         cell add_inline_cache_entry(cell cache_entries_, cell klass_, cell method_);
558         void update_pic_transitions(cell pic_size);
559         void *inline_cache_miss(cell return_address);
560         inline void primitive_reset_inline_cache_stats();
561         inline void primitive_inline_cache_stats();
562
563         //factor
564         void default_parameters(vm_parameters *p);
565         bool factor_arg(const vm_char* str, const vm_char* arg, cell* value);
566         void init_parameters_from_args(vm_parameters *p, int argc, vm_char **argv);
567         void do_stage1_init();
568         void init_factor(vm_parameters *p);
569         void pass_args_to_factor(int argc, vm_char **argv);
570         void start_factor(vm_parameters *p);
571         void start_embedded_factor(vm_parameters *p);
572         void start_standalone_factor(int argc, vm_char **argv);
573         char *factor_eval_string(char *string);
574         void factor_eval_free(char *result);
575         void factor_yield();
576         void factor_sleep(long us);
577
578         // os-*
579         inline void primitive_existsp();
580         void init_ffi();
581         void ffi_dlopen(dll *dll);
582         void *ffi_dlsym(dll *dll, symbol_char *symbol);
583         void ffi_dlclose(dll *dll);
584         segment *alloc_segment(cell size);
585         void c_to_factor_toplevel(cell quot);
586
587         // os-windows
588   #if defined(WINDOWS)
589         void sleep_micros(u64 usec);
590         long getpagesize();
591         void dealloc_segment(segment *block);
592         const vm_char *vm_executable_path();
593         const vm_char *default_image_path();
594         void windows_image_path(vm_char *full_path, vm_char *temp_path, unsigned int length);
595         bool windows_stat(vm_char *path);
596         
597    #if defined(WINNT)
598         void open_console();
599         LONG exception_handler(PEXCEPTION_POINTERS pe);
600         // next method here:    
601    #endif
602   #else  // UNIX
603         void memory_signal_handler(int signal, siginfo_t *siginfo, void *uap);
604         void misc_signal_handler(int signal, siginfo_t *siginfo, void *uap);
605         void fpe_signal_handler(int signal, siginfo_t *siginfo, void *uap);
606         stack_frame *uap_stack_pointer(void *uap);
607
608   #endif
609
610   #ifdef __APPLE__
611         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);
612   #endif
613         
614         void print_vm_data();
615 };
616
617
618 #ifndef FACTOR_REENTRANT
619    #define FACTOR_SINGLE_THREADED_SINGLETON
620 #endif
621
622 #ifdef FACTOR_SINGLE_THREADED_SINGLETON
623 /* calls are dispatched using the singleton vm ptr */
624   extern factorvm *vm;
625   #define PRIMITIVE_GETVM() vm
626   #define PRIMITIVE_OVERFLOW_GETVM() vm
627   #define VM_PTR vm
628   #define ASSERTVM() 
629   #define SIGNAL_VM_PTR() vm
630 #endif
631
632 #ifdef FACTOR_SINGLE_THREADED_TESTING
633 /* calls are dispatched as per multithreaded, but checked against singleton */
634   extern factorvm *vm;
635   #define ASSERTVM() assert(vm==myvm)
636   #define PRIMITIVE_GETVM() ((factorvm*)myvm)
637   #define PRIMITIVE_OVERFLOW_GETVM() ASSERTVM(); myvm
638   #define VM_PTR myvm
639   #define SIGNAL_VM_PTR() tls_vm()
640 #endif
641
642 #ifdef FACTOR_REENTRANT_TLS
643 /* uses thread local storage to obtain vm ptr */
644   #define PRIMITIVE_GETVM() tls_vm()
645   #define PRIMITIVE_OVERFLOW_GETVM() tls_vm()
646   #define VM_PTR tls_vm()
647   #define ASSERTVM() 
648   #define SIGNAL_VM_PTR() tls_vm()
649 #endif
650
651 #ifdef FACTOR_REENTRANT
652   #define PRIMITIVE_GETVM() ((factorvm*)myvm)
653   #define PRIMITIVE_OVERFLOW_GETVM() ((factorvm*)myvm)
654   #define VM_PTR myvm
655   #define ASSERTVM() 
656   #define SIGNAL_VM_PTR() tls_vm()
657 #endif
658
659 }