#define DEFINE_ALIEN_ACCESSOR(name,type,boxer,to) \
PRIMITIVE(alien_##name) \
{ \
- PRIMITIVE_GETVM()->boxer(*(type*)PRIMITIVE_GETVM()->alien_pointer()); \
+ ((factor_vm*)myvm)->boxer(*(type*)((factor_vm*)myvm)->alien_pointer()); \
} \
PRIMITIVE(set_alien_##name) \
{ \
- type *ptr = (type *)PRIMITIVE_GETVM()->alien_pointer(); \
- type value = PRIMITIVE_GETVM()->to(dpop()); \
+ type *ptr = (type *)((factor_vm*)myvm)->alien_pointer(); \
+ type value = ((factor_vm*)myvm)->to(dpop()); \
*ptr = value; \
}
VM_C_API char *alien_offset(cell obj, factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->alien_offset(obj);
+ return myvm->alien_offset(obj);
}
/* pop an object representing a C pointer */
VM_C_API char *unbox_alien(factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->unbox_alien();
+ return myvm->unbox_alien();
}
/* make an alien and push */
VM_C_API void box_alien(void *ptr, factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_alien(ptr);
+ return myvm->box_alien(ptr);
}
/* for FFI calls passing structs by value */
VM_C_API void to_value_struct(cell src, void *dest, cell size, factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->to_value_struct(src,dest,size);
+ return myvm->to_value_struct(src,dest,size);
}
/* for FFI callbacks receiving structs by value */
VM_C_API void box_value_struct(void *src, cell size,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_value_struct(src,size);
+ return myvm->box_value_struct(src,size);
}
/* On some x86 OSes, structs <= 8 bytes are returned in registers. */
VM_C_API void box_small_struct(cell x, cell y, cell size, factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_small_struct(x,y,size);
+ return myvm->box_small_struct(x,y,size);
}
/* On OS X/PPC, complex numbers are returned in registers. */
VM_C_API void box_medium_struct(cell x1, cell x2, cell x3, cell x4, cell size, factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_medium_struct(x1, x2, x3, x4, size);
+ return myvm->box_medium_struct(x1, x2, x3, x4, size);
}
void factor_vm::primitive_vm_ptr()
VM_C_API void box_boolean(bool value, factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_boolean(value);
+ return myvm->box_boolean(value);
}
bool factor_vm::to_boolean(cell value)
VM_C_API bool to_boolean(cell value, factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->to_boolean(value);
+ return myvm->to_boolean(value);
}
}
VM_ASM_API void save_callstack_bottom(stack_frame *callstack_bottom, factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->save_callstack_bottom(callstack_bottom);
+ return myvm->save_callstack_bottom(callstack_bottom);
}
}
void undefined_symbol()
{
- return SIGNAL_VM_PTR()->undefined_symbol();
+ return tls_vm()->undefined_symbol();
}
/* Look up an external library symbol referenced by a compiled code block */
void nest_stacks(factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->nest_stacks();
+ return myvm->nest_stacks();
}
/* called when leaving a compiled callback */
void unnest_stacks(factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->unnest_stacks();
+ return myvm->unnest_stacks();
}
/* called on startup */
print_string("You have triggered a bug in Factor. Please report.\n");
print_string("critical_error: "); print_string(msg);
print_string(": "); print_cell_hex(tagged); nl();
- SIGNAL_VM_PTR()->factorbug();
+ tls_vm()->factorbug();
}
void out_of_memory()
{
print_string("Out of memory\n\n");
- SIGNAL_VM_PTR()->dump_generations();
+ tls_vm()->dump_generations();
exit(1);
}
void memory_signal_handler_impl()
{
- SIGNAL_VM_PTR()->memory_signal_handler_impl();
+ tls_vm()->memory_signal_handler_impl();
}
void factor_vm::misc_signal_handler_impl()
void misc_signal_handler_impl()
{
- SIGNAL_VM_PTR()->misc_signal_handler_impl();
+ tls_vm()->misc_signal_handler_impl();
}
void factor_vm::fp_signal_handler_impl()
void fp_signal_handler_impl()
{
- SIGNAL_VM_PTR()->fp_signal_handler_impl();
+ tls_vm()->fp_signal_handler_impl();
}
}
VM_C_API void inline_gc(cell *gc_roots_base, cell gc_roots_size, factor_vm *myvm)
{
- ASSERTVM();
- VM_PTR->inline_gc(gc_roots_base,gc_roots_size);
+ myvm->inline_gc(gc_roots_base,gc_roots_size);
}
/*
VM_C_API void *inline_cache_miss(cell return_address, factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->inline_cache_miss(return_address);
+ return myvm->inline_cache_miss(return_address);
}
void factor_vm::primitive_reset_inline_cache_stats()
VM_C_API fixnum to_fixnum(cell tagged,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->to_fixnum(tagged);
+ return myvm->to_fixnum(tagged);
}
cell factor_vm::to_cell(cell tagged)
VM_C_API cell to_cell(cell tagged, factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->to_cell(tagged);
+ return myvm->to_cell(tagged);
}
void factor_vm::box_signed_1(s8 n)
VM_C_API void box_signed_1(s8 n,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_signed_1(n);
+ return myvm->box_signed_1(n);
}
void factor_vm::box_unsigned_1(u8 n)
VM_C_API void box_unsigned_1(u8 n,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_unsigned_1(n);
+ return myvm->box_unsigned_1(n);
}
void factor_vm::box_signed_2(s16 n)
VM_C_API void box_signed_2(s16 n,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_signed_2(n);
+ return myvm->box_signed_2(n);
}
void factor_vm::box_unsigned_2(u16 n)
VM_C_API void box_unsigned_2(u16 n,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_unsigned_2(n);
+ return myvm->box_unsigned_2(n);
}
void factor_vm::box_signed_4(s32 n)
VM_C_API void box_signed_4(s32 n,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_signed_4(n);
+ return myvm->box_signed_4(n);
}
void factor_vm::box_unsigned_4(u32 n)
VM_C_API void box_unsigned_4(u32 n,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_unsigned_4(n);
+ return myvm->box_unsigned_4(n);
}
void factor_vm::box_signed_cell(fixnum integer)
VM_C_API void box_signed_cell(fixnum integer,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_signed_cell(integer);
+ return myvm->box_signed_cell(integer);
}
void factor_vm::box_unsigned_cell(cell cell)
VM_C_API void box_unsigned_cell(cell cell,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_unsigned_cell(cell);
+ return myvm->box_unsigned_cell(cell);
}
void factor_vm::box_signed_8(s64 n)
VM_C_API void box_signed_8(s64 n,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_signed_8(n);
+ return myvm->box_signed_8(n);
}
s64 factor_vm::to_signed_8(cell obj)
VM_C_API s64 to_signed_8(cell obj,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->to_signed_8(obj);
+ return myvm->to_signed_8(obj);
}
void factor_vm::box_unsigned_8(u64 n)
VM_C_API void box_unsigned_8(u64 n,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_unsigned_8(n);
+ return myvm->box_unsigned_8(n);
}
u64 factor_vm::to_unsigned_8(cell obj)
VM_C_API u64 to_unsigned_8(cell obj,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->to_unsigned_8(obj);
+ return myvm->to_unsigned_8(obj);
}
void factor_vm::box_float(float flo)
VM_C_API void box_float(float flo, factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_float(flo);
+ return myvm->box_float(flo);
}
float factor_vm::to_float(cell value)
VM_C_API float to_float(cell value,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->to_float(value);
+ return myvm->to_float(value);
}
void factor_vm::box_double(double flo)
VM_C_API void box_double(double flo,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->box_double(flo);
+ return myvm->box_double(flo);
}
double factor_vm::to_double(cell value)
VM_C_API double to_double(cell value,factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->to_double(value);
+ return myvm->to_double(value);
}
/* The fixnum+, fixnum- and fixnum* primitives are defined in cpu_*.S. On
VM_ASM_API void overflow_fixnum_add(fixnum x, fixnum y, factor_vm *myvm)
{
- PRIMITIVE_OVERFLOW_GETVM()->overflow_fixnum_add(x,y);
+ ((factor_vm*)myvm)->overflow_fixnum_add(x,y);
}
inline void factor_vm::overflow_fixnum_subtract(fixnum x, fixnum y)
VM_ASM_API void overflow_fixnum_subtract(fixnum x, fixnum y, factor_vm *myvm)
{
- PRIMITIVE_OVERFLOW_GETVM()->overflow_fixnum_subtract(x,y);
+ ((factor_vm*)myvm)->overflow_fixnum_subtract(x,y);
}
inline void factor_vm::overflow_fixnum_multiply(fixnum x, fixnum y)
VM_ASM_API void overflow_fixnum_multiply(fixnum x, fixnum y, factor_vm *myvm)
{
- PRIMITIVE_OVERFLOW_GETVM()->overflow_fixnum_multiply(x,y);
+ ((factor_vm*)myvm)->overflow_fixnum_multiply(x,y);
}
}
: "r0","r1","r2");
if(result < 0)
- SIGNAL_VM_PTR->critical_error("flush_icache() failed",result);
+ tls_vm()critical_error("flush_icache() failed",result);
}
}
VM_C_API int inotify_init()
{
- VM_PTR->not_implemented_error();
+ myvm->not_implemented_error();
return -1;
}
VM_C_API int inotify_add_watch(int fd, const char *name, u32 mask)
{
- VM_PTR->not_implemented_error();
+ myvm->not_implemented_error();
return -1;
}
VM_C_API int inotify_rm_watch(int fd, u32 wd)
{
- VM_PTR->not_implemented_error();
+ myvm->not_implemented_error();
return -1;
}
void memory_signal_handler(int signal, siginfo_t *siginfo, void *uap)
{
- SIGNAL_VM_PTR()->memory_signal_handler(signal,siginfo,uap);
+ tls_vm()->memory_signal_handler(signal,siginfo,uap);
}
void factor_vm::misc_signal_handler(int signal, siginfo_t *siginfo, void *uap)
void misc_signal_handler(int signal, siginfo_t *siginfo, void *uap)
{
- SIGNAL_VM_PTR()->misc_signal_handler(signal,siginfo,uap);
+ tls_vm()->misc_signal_handler(signal,siginfo,uap);
}
void factor_vm::fpe_signal_handler(int signal, siginfo_t *siginfo, void *uap)
void fpe_signal_handler(int signal, siginfo_t *siginfo, void *uap)
{
- SIGNAL_VM_PTR()->fpe_signal_handler(signal, siginfo, uap);
+ tls_vm()->fpe_signal_handler(signal, siginfo, uap);
}
static void sigaction_safe(int signum, const struct sigaction *act, struct sigaction *oldact)
FACTOR_STDCALL LONG exception_handler(PEXCEPTION_POINTERS pe)
{
- return SIGNAL_VM_PTR()->exception_handler(pe);
+ return tls_vm()->exception_handler(pe);
}
bool handler_added = 0;
#define PRIMITIVE(name) extern "C" __attribute__ ((regparm (1))) void primitive_##name(void *myvm)
#define PRIMITIVE_FORWARD(name) extern "C" __attribute__ ((regparm (1))) void primitive_##name(void *myvm) \
{ \
- PRIMITIVE_GETVM()->primitive_##name(); \
+ ((factor_vm*)myvm)->primitive_##name(); \
}
#else
extern "C" typedef void (*primitive_type)(void *myvm);
#define PRIMITIVE(name) extern "C" void primitive_##name(void *myvm)
#define PRIMITIVE_FORWARD(name) extern "C" void primitive_##name(void *myvm) \
{ \
- PRIMITIVE_GETVM()->primitive_##name(); \
+ ((factor_vm*)myvm)->primitive_##name(); \
}
#endif
extern const primitive_type primitives[];
VM_ASM_API cell lazy_jit_compile_impl(cell quot_, stack_frame *stack, factor_vm *myvm)
{
- ASSERTVM();
- return VM_PTR->lazy_jit_compile_impl(quot_,stack);
+ return myvm->lazy_jit_compile_impl(quot_,stack);
}
void factor_vm::primitive_quot_compiled_p()
explicit tagged(cell tagged) : value_(tagged) {
#ifdef FACTOR_DEBUG
- untag_check(SIGNAL_VM_PTR());
+ untag_check(tls_vm());
#endif
}
explicit tagged(Type *untagged) : value_(factor::tag(untagged)) {
#ifdef FACTOR_DEBUG
- untag_check(SIGNAL_VM_PTR());
+ untag_check(tls_vm());
#endif
}
};
-#ifndef FACTOR_REENTRANT
- #define FACTOR_SINGLE_THREADED_TESTING
-#endif
-
-#ifdef FACTOR_SINGLE_THREADED_SINGLETON
-/* calls are dispatched using the singleton vm ptr */
- extern factor_vm *vm;
- #define PRIMITIVE_GETVM() vm
- #define PRIMITIVE_OVERFLOW_GETVM() vm
- #define VM_PTR vm
- #define ASSERTVM()
- #define SIGNAL_VM_PTR() vm
-#endif
-
-#ifdef FACTOR_SINGLE_THREADED_TESTING
-/* calls are dispatched as per multithreaded, but checked against singleton */
- extern factor_vm *vm;
- #define ASSERTVM() assert(vm==myvm)
- #define PRIMITIVE_GETVM() ((factor_vm*)myvm)
- #define PRIMITIVE_OVERFLOW_GETVM() ASSERTVM(); myvm
- #define VM_PTR myvm
- #define SIGNAL_VM_PTR() tls_vm()
-#endif
-
-#ifdef FACTOR_REENTRANT_TLS
-/* uses thread local storage to obtain vm ptr */
- #define PRIMITIVE_GETVM() tls_vm()
- #define PRIMITIVE_OVERFLOW_GETVM() tls_vm()
- #define VM_PTR tls_vm()
- #define ASSERTVM()
- #define SIGNAL_VM_PTR() tls_vm()
-#endif
-
-#ifdef FACTOR_REENTRANT
- #define PRIMITIVE_GETVM() ((factor_vm*)myvm)
- #define PRIMITIVE_OVERFLOW_GETVM() ((factor_vm*)myvm)
- #define VM_PTR myvm
- #define ASSERTVM()
- #define SIGNAL_VM_PTR() tls_vm()
-#endif
-
extern unordered_map<THREADHANDLE, factor_vm *> thread_vms;
}