]> gitweb.factorcode.org Git - factor.git/blob - vm/entry_points.cpp
Merge branch 'docs-linearization-typo' of http://github.com/mncharity/factor
[factor.git] / vm / entry_points.cpp
1 #include "master.hpp"
2
3 namespace factor
4 {
5
6 void factor_vm::c_to_factor(cell quot)
7 {
8         /* First time this is called, wrap the c-to-factor sub-primitive inside
9         of a callback stub, which saves and restores non-volatile registers
10         as per platform ABI conventions, so that the Factor compiler can treat
11         all registers as volatile */
12         if(!c_to_factor_func)
13         {
14                 tagged<word> c_to_factor_word(special_objects[C_TO_FACTOR_WORD]);
15                 code_block *c_to_factor_block = callbacks->add(c_to_factor_word.value(),0);
16                 c_to_factor_func = (c_to_factor_func_type)c_to_factor_block->entry_point();
17         }
18
19         c_to_factor_func(quot);
20 }
21
22 template<typename Func> Func factor_vm::get_entry_point(cell n)
23 {
24         /* We return word->code->entry_point() and not word->entry_point,
25         because if profiling is enabled, we don't want to go through the
26         entry point's profiling stub. This clobbers registers, since entry
27         points use the C ABI and not the Factor ABI. */
28         tagged<word> entry_point_word(special_objects[n]);
29         return (Func)entry_point_word->code->entry_point();
30 }
31
32 void factor_vm::unwind_native_frames(cell quot, stack_frame *to)
33 {
34         get_entry_point<unwind_native_frames_func_type>(UNWIND_NATIVE_FRAMES_WORD)(quot,to);
35 }
36
37 cell factor_vm::get_fpu_state()
38 {
39         return get_entry_point<get_fpu_state_func_type>(GET_FPU_STATE_WORD)();
40 }
41
42 void factor_vm::set_fpu_state(cell state)
43 {
44         get_entry_point<set_fpu_state_func_type>(GET_FPU_STATE_WORD)(state);
45 }
46
47 }