/vm/entry_points.cpp

http://github.com/abeaumont/factor · C++ · 53 lines · 42 code · 7 blank · 4 comment · 1 complexity · 3d5851c92ac5c7650cf7d7afab5df0b1 MD5 · raw file

  1. #include "master.hpp"
  2. namespace factor
  3. {
  4. void factor_vm::c_to_factor(cell quot)
  5. {
  6. /* First time this is called, wrap the c-to-factor sub-primitive inside
  7. of a callback stub, which saves and restores non-volatile registers
  8. per platform ABI conventions, so that the Factor compiler can treat
  9. all registers as volatile */
  10. if(!c_to_factor_func)
  11. {
  12. tagged<word> c_to_factor_word(special_objects[C_TO_FACTOR_WORD]);
  13. code_block *c_to_factor_block = callbacks->add(c_to_factor_word.value(),0);
  14. void* func = c_to_factor_block->entry_point();
  15. CODE_TO_FUNCTION_POINTER_CALLBACK(this, func);
  16. c_to_factor_func = (c_to_factor_func_type)func;
  17. }
  18. c_to_factor_func(quot);
  19. }
  20. template<typename Func> Func factor_vm::get_entry_point(cell n)
  21. {
  22. tagged<word> entry_point_word(special_objects[n]);
  23. return (Func)entry_point_word->entry_point;
  24. }
  25. void factor_vm::unwind_native_frames(cell quot, void *to)
  26. {
  27. tagged<word> entry_point_word(special_objects[UNWIND_NATIVE_FRAMES_WORD]);
  28. void *func = entry_point_word->entry_point;
  29. CODE_TO_FUNCTION_POINTER(func);
  30. ((unwind_native_frames_func_type)func)(quot,to);
  31. }
  32. cell factor_vm::get_fpu_state()
  33. {
  34. tagged<word> entry_point_word(special_objects[GET_FPU_STATE_WORD]);
  35. void *func = entry_point_word->entry_point;
  36. CODE_TO_FUNCTION_POINTER(func);
  37. return ((get_fpu_state_func_type)func)();
  38. }
  39. void factor_vm::set_fpu_state(cell state)
  40. {
  41. tagged<word> entry_point_word(special_objects[SET_FPU_STATE_WORD]);
  42. void *func = entry_point_word->entry_point;
  43. CODE_TO_FUNCTION_POINTER(func);
  44. ((set_fpu_state_func_type)func)(state);
  45. }
  46. }