VM: Refactor entry_points to Factor style

db4
Erik Charlebois 2013-05-11 21:58:23 -04:00
parent d5f66d9561
commit d6bc190f51
2 changed files with 37 additions and 45 deletions

View File

@ -1,16 +1,13 @@
#include "master.hpp" #include "master.hpp"
namespace factor namespace factor {
{
void factor_vm::c_to_factor(cell quot) void factor_vm::c_to_factor(cell quot) {
{
/* First time this is called, wrap the c-to-factor sub-primitive inside /* First time this is called, wrap the c-to-factor sub-primitive inside
of a callback stub, which saves and restores non-volatile registers of a callback stub, which saves and restores non-volatile registers
per platform ABI conventions, so that the Factor compiler can treat per platform ABI conventions, so that the Factor compiler can treat
all registers as volatile */ all registers as volatile */
if(!c_to_factor_func) if (!c_to_factor_func) {
{
tagged<word> c_to_factor_word(special_objects[C_TO_FACTOR_WORD]); 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); code_block* c_to_factor_block = callbacks->add(c_to_factor_word.value(), 0);
void* func = c_to_factor_block->entry_point(); void* func = c_to_factor_block->entry_point();
@ -20,30 +17,26 @@ void factor_vm::c_to_factor(cell quot)
c_to_factor_func(quot); c_to_factor_func(quot);
} }
template<typename Func> Func factor_vm::get_entry_point(cell n) template <typename Func> Func factor_vm::get_entry_point(cell n) {
{
tagged<word> entry_point_word(special_objects[n]); tagged<word> entry_point_word(special_objects[n]);
return (Func) entry_point_word->entry_point; return (Func) entry_point_word->entry_point;
} }
void factor_vm::unwind_native_frames(cell quot, void *to) void factor_vm::unwind_native_frames(cell quot, void* to) {
{
tagged<word> entry_point_word(special_objects[UNWIND_NATIVE_FRAMES_WORD]); tagged<word> entry_point_word(special_objects[UNWIND_NATIVE_FRAMES_WORD]);
void* func = entry_point_word->entry_point; void* func = entry_point_word->entry_point;
CODE_TO_FUNCTION_POINTER(func); CODE_TO_FUNCTION_POINTER(func);
((unwind_native_frames_func_type) func)(quot, to); ((unwind_native_frames_func_type) func)(quot, to);
} }
cell factor_vm::get_fpu_state() cell factor_vm::get_fpu_state() {
{
tagged<word> entry_point_word(special_objects[GET_FPU_STATE_WORD]); tagged<word> entry_point_word(special_objects[GET_FPU_STATE_WORD]);
void* func = entry_point_word->entry_point; void* func = entry_point_word->entry_point;
CODE_TO_FUNCTION_POINTER(func); CODE_TO_FUNCTION_POINTER(func);
return ((get_fpu_state_func_type) func)(); return ((get_fpu_state_func_type) func)();
} }
void factor_vm::set_fpu_state(cell state) void factor_vm::set_fpu_state(cell state) {
{
tagged<word> entry_point_word(special_objects[SET_FPU_STATE_WORD]); tagged<word> entry_point_word(special_objects[SET_FPU_STATE_WORD]);
void* func = entry_point_word->entry_point; void* func = entry_point_word->entry_point;
CODE_TO_FUNCTION_POINTER(func); CODE_TO_FUNCTION_POINTER(func);

View File

@ -1,5 +1,4 @@
namespace factor namespace factor {
{
typedef void (*c_to_factor_func_type)(cell quot); typedef void (*c_to_factor_func_type)(cell quot);
typedef void (*unwind_native_frames_func_type)(cell quot, void* to); typedef void (*unwind_native_frames_func_type)(cell quot, void* to);