2009-05-02 05:04:19 -04:00
|
|
|
#include <assert.h>
|
|
|
|
|
2009-05-04 02:46:13 -04:00
|
|
|
namespace factor
|
|
|
|
{
|
|
|
|
|
2009-05-04 05:50:24 -04:00
|
|
|
#define FRAME_RETURN_ADDRESS(frame) *(void **)(frame_successor(frame) + 1)
|
2009-05-02 05:04:19 -04:00
|
|
|
|
2009-05-04 05:50:24 -04:00
|
|
|
inline static void flush_icache(cell start, cell len) {}
|
2009-05-02 05:04:19 -04:00
|
|
|
|
2009-05-06 20:22:22 -04:00
|
|
|
static const unsigned char call_opcode = 0xe8;
|
|
|
|
static const unsigned char jmp_opcode = 0xe9;
|
|
|
|
|
|
|
|
inline static unsigned char call_site_opcode(cell return_address)
|
|
|
|
{
|
|
|
|
return *(unsigned char *)(return_address - 5);
|
|
|
|
}
|
|
|
|
|
2009-05-04 05:50:24 -04:00
|
|
|
inline static void check_call_site(cell return_address)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
|
|
|
#ifdef FACTOR_DEBUG
|
2009-05-06 20:22:22 -04:00
|
|
|
unsigned char opcode = call_site_opcode(return_address);
|
|
|
|
assert(opcode == call_opcode || opcode == jmp_opcode);
|
2009-05-02 05:04:19 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-05-04 05:50:24 -04:00
|
|
|
inline static void *get_call_target(cell return_address)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
|
|
|
check_call_site(return_address);
|
2009-05-04 05:50:24 -04:00
|
|
|
return (void *)(*(int *)(return_address - 4) + return_address);
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
|
|
|
|
2009-05-04 05:50:24 -04:00
|
|
|
inline static void set_call_target(cell return_address, void *target)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
|
|
|
check_call_site(return_address);
|
2009-05-04 05:50:24 -04:00
|
|
|
*(int *)(return_address - 4) = ((cell)target - return_address);
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
|
|
|
|
2009-05-06 20:22:22 -04:00
|
|
|
inline static bool tail_call_site_p(cell return_address)
|
|
|
|
{
|
|
|
|
return call_site_opcode(return_address) == jmp_opcode;
|
|
|
|
}
|
|
|
|
|
2009-05-02 05:04:19 -04:00
|
|
|
/* Defined in assembly */
|
2009-05-04 05:50:24 -04:00
|
|
|
VM_ASM_API void c_to_factor(cell quot);
|
|
|
|
VM_ASM_API void throw_impl(cell quot, stack_frame *rewind_to);
|
|
|
|
VM_ASM_API void lazy_jit_compile(cell quot);
|
2009-05-02 05:04:19 -04:00
|
|
|
|
2009-05-04 05:50:24 -04:00
|
|
|
VM_C_API void set_callstack(stack_frame *to,
|
|
|
|
stack_frame *from,
|
|
|
|
cell length,
|
2009-05-02 05:04:19 -04:00
|
|
|
void *(*memcpy)(void*,const void*, size_t));
|
2009-05-04 02:46:13 -04:00
|
|
|
|
|
|
|
}
|