]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/entry_points.cpp
alien.syntax: clarify that we can dispatch off ENUM: members
[factor.git] / vm / entry_points.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 9f4c827..05ec2ea
@@ -1,47 +1,41 @@
 #include "master.hpp"
 
-namespace factor
-{
-
-void factor_vm::c_to_factor(cell quot)
-{
-       /* First time this is called, wrap the c-to-factor sub-primitive inside
-       of a callback stub, which saves and restores non-volatile registers
-       as per platform ABI conventions, so that the Factor compiler can treat
-       all registers as volatile */
-       if(!c_to_factor_func)
-       {
-               tagged<word> c_to_factor_word(special_objects[C_TO_FACTOR_WORD]);
-               code_block *c_to_factor_block = callbacks->add(c_to_factor_word.value(),0);
-               c_to_factor_func = (c_to_factor_func_type)c_to_factor_block->entry_point();
-       }
-
-       c_to_factor_func(quot);
-}
-
-template<typename Func> Func factor_vm::get_entry_point(cell n)
-{
-       /* We return word->code->entry_point() and not word->entry_point,
-       because if profiling is enabled, we don't want to go through the
-       entry point's profiling stub. This clobbers registers, since entry
-       points use the C ABI and not the Factor ABI. */
-       tagged<word> entry_point_word(special_objects[n]);
-       return (Func)entry_point_word->code->entry_point();
+namespace factor {
+
+void factor_vm::c_to_factor(cell quot) {
+  // First time this is called, wrap the c-to-factor sub-primitive inside
+  // of a callback stub, which saves and restores non-volatile registers
+  // per platform ABI conventions, so that the Factor compiler can treat
+  // all registers as volatile
+  if (!c_to_factor_func) {
+    tagged<word> c_to_factor_word(special_objects[C_TO_FACTOR_WORD]);
+    code_block* c_to_factor_block = callbacks->add(c_to_factor_word.value(), 0);
+    cell func = c_to_factor_block->entry_point();
+    CODE_TO_FUNCTION_POINTER_CALLBACK(this, func);
+    c_to_factor_func = (c_to_factor_func_type) func;
+  }
+  c_to_factor_func(quot);
 }
 
-void factor_vm::unwind_native_frames(cell quot, stack_frame *to)
-{
-       get_entry_point<unwind_native_frames_func_type>(UNWIND_NATIVE_FRAMES_WORD)(quot,to);
+void factor_vm::unwind_native_frames(cell quot, cell to) {
+  tagged<word> entry_point_word(special_objects[UNWIND_NATIVE_FRAMES_WORD]);
+  cell func = entry_point_word->entry_point;
+  CODE_TO_FUNCTION_POINTER(func);
+  ((unwind_native_frames_func_type) func)(quot, to);
 }
 
-cell factor_vm::get_fpu_state()
-{
-       return get_entry_point<get_fpu_state_func_type>(GET_FPU_STATE_WORD)();
+cell factor_vm::get_fpu_state() {
+  tagged<word> entry_point_word(special_objects[GET_FPU_STATE_WORD]);
+  cell func = entry_point_word->entry_point;
+  CODE_TO_FUNCTION_POINTER(func);
+  return ((get_fpu_state_func_type) func)();
 }
 
-void factor_vm::set_fpu_state(cell state)
-{
-       get_entry_point<set_fpu_state_func_type>(GET_FPU_STATE_WORD)(state);
+void factor_vm::set_fpu_state(cell state) {
+  tagged<word> entry_point_word(special_objects[SET_FPU_STATE_WORD]);
+  cell func = entry_point_word->entry_point;
+  CODE_TO_FUNCTION_POINTER(func);
+  ((set_fpu_state_func_type) func)(state);
 }
 
 }