+!IF DEFINED(DEBUG)\r
+LINK_FLAGS = /nologo /DEBUG shell32.lib\r
+CL_FLAGS = /nologo /Zi /O2 /W3 /DFACTOR_DEBUG\r
+!ELSE\r
LINK_FLAGS = /nologo shell32.lib\r
CL_FLAGS = /nologo /O2 /W3\r
+!ENDIF\r
\r
EXE_OBJS = factor.dll.lib vm\main-windows-nt.obj vm\factor.res\r
\r
.cpp.obj:\r
cl /EHsc $(CL_FLAGS) /Fo$@ /c $<\r
\r
+.c.obj:\r
+ cl $(CL_FLAGS) /Fo$@ /c $<\r
+\r
.rs.res:\r
rc $<\r
\r
all: factor.com factor.exe\r
\r
+libfactor-ffi-test.dll: vm/ffi_test.obj\r
+ link $(LINK_FLAGS) /out:libfactor-ffi-test.dll /dll vm/ffi_test.obj\r
+\r
factor.dll.lib: $(DLL_OBJS)\r
link $(LINK_FLAGS) /implib:factor.dll.lib /out:factor.dll /dll $(DLL_OBJS)\r
\r
! Copyright (C) 2005, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays kernel math namespaces make sequences
-system layouts alien alien.c-types alien.accessors slots
-splitting assocs combinators locals compiler.constants
+system layouts alien alien.c-types alien.accessors alien.libraries
+slots splitting assocs combinators locals compiler.constants
compiler.codegen compiler.codegen.fixup
compiler.cfg.instructions compiler.cfg.builder
compiler.cfg.intrinsics compiler.cfg.stack-frame
! this is the end of alien-callback
n [ n rep reg-class-of return-reg rep %save-param-reg ] when ;
-M: x86.64 %unbox-long-long ( n func -- )
- [ int-rep ] dip %unbox ;
-
: %unbox-struct-field ( c-type i -- )
! Alien must be in param-reg-0.
R11 swap cells [+] swap rep>> reg-class-of {
] [
rep load-return-value
] if
- rep int-rep? [ param-reg-1 ] [ param-reg-0 ] if %mov-vm-ptr
+ rep int-rep?
+ cpu x86.64? os windows? and or
+ param-reg-1 param-reg-0 ? %mov-vm-ptr
func f %alien-invoke ;
-M: x86.64 %box-long-long ( n func -- )
- [ int-rep ] dip %box ;
-
: box-struct-field@ ( i -- operand ) 1 + cells param@ ;
: %box-struct-field ( c-type i -- )
M:: x86.64 %unary-float-function ( dst src func -- )
0 src float-function-param
- func f %alien-invoke
+ func "libm" load-library %alien-invoke
dst float-function-return ;
M:: x86.64 %binary-float-function ( dst src1 src2 func -- )
! src2 is always a spill slot
0 src1 float-function-param
1 src2 float-function-param
- func f %alien-invoke
+ func "libm" load-library %alien-invoke
dst float-function-return ;
M:: x86.64 %call-gc ( gc-root-count temp -- )
M: x86.64 dummy-fp-params? t ;
-M: x86.64 temp-reg RAX ;
+M: x86.64 temp-reg R11 ;
-#error "lol"
DLL_PATH=http://factorcode.org/dlls/64
CC=$(WIN64_PATH)-gcc.exe
WINDRES=$(WIN64_PATH)-windres.exe
#endif
#elif defined(FACTOR_AMD64)
#if defined(_MSC_VER)
- _BitScanReverse64(&n,x);
+ n = 0;
+ _BitScanReverse64((DWORD *)&n,x);
#else
asm ("bsr %1, %0;":"=r"(n):"r"(x));
#endif
}
}
-void factor_vm::check_code_address(cell address)
-{
-#ifdef FACTOR_DEBUG
- assert(address >= code->seg->start && address < code->seg->end);
-#endif
-}
-
/* References to undefined symbols are patched up to call this function on
image load */
void factor_vm::undefined_symbol()
inline static void set_call_target(cell return_address, void *target)
{
check_call_site(return_address);
- *(int *)(return_address - 4) = ((cell)target - return_address);
+ *(int *)(return_address - 4) = (u32)((cell)target - return_address);
}
inline static bool tail_call_site_p(cell return_address)
general_error(ERROR_MEMORY,allot_cell(addr),false_object,native_stack);
}
-void factor_vm::signal_error(int signal, stack_frame *native_stack)
+void factor_vm::signal_error(cell signal, stack_frame *native_stack)
{
general_error(ERROR_SIGNAL,allot_cell(signal),false_object,native_stack);
}
-#include <stdbool.h>
+#ifdef _MSC_VER
+ #define WINDOWS
+#else
+ #include <stdbool.h>
+#endif
#if defined(i386) || defined(__i386) || defined(__i386__) || defined(WIN32)
#define F_STDCALL __attribute__((stdcall))
for(; iter < end; iter++)
{
code_root *root = *iter;
- code_block *block = (code_block *)(root->value & -data_alignment);
+ code_block *block = (code_block *)(root->value & (~data_alignment - 1));
if(root->valid && !state->marked_p(block))
root->valid = false;
}
void instruction_operand::store_value_masked(fixnum value, cell mask, cell shift)
{
u32 *ptr = (u32 *)(pointer - sizeof(u32));
- *ptr = ((*ptr & ~mask) | ((value >> shift) & mask));
+ *ptr = (u32)((*ptr & ~mask) | ((value >> shift) & mask));
}
void instruction_operand::store_value(fixnum absolute_value)
*(cell *)(pointer - sizeof(cell)) = absolute_value;
break;
case RC_ABSOLUTE:
- *(u32 *)(pointer - sizeof(u32)) = absolute_value;
+ *(u32 *)(pointer - sizeof(u32)) = (u32)absolute_value;
break;
case RC_RELATIVE:
- *(s32 *)(pointer - sizeof(s32)) = relative_value;
+ *(s32 *)(pointer - sizeof(s32)) = (s32)relative_value;
break;
case RC_ABSOLUTE_PPC_2_2:
store_value_2_2(absolute_value);
relocation_class rel_class,
cell offset)
{
- value = (rel_type << 28) | (rel_class << 24) | offset;
+ value = (u32)((rel_type << 28) | (rel_class << 24) | offset);
}
relocation_type rel_type()
/* Detect target CPU type */
#if defined(__arm__)
#define FACTOR_ARM
-#elif defined(__amd64__) || defined(__x86_64__)
+#elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64)
#define FACTOR_AMD64
#define FACTOR_64
-#elif defined(i386) || defined(__i386) || defined(__i386__) || defined(WIN32) || defined(_MSC_VER)
+#elif defined(i386) || defined(__i386) || defined(__i386__) || defined(_M_IX86)
#define FACTOR_X86
#elif defined(__POWERPC__) || defined(__ppc__) || defined(_ARCH_PPC)
#define FACTOR_PPC
#define WINDOWS
#endif
-#ifndef _MSC_VER
- #include <stdbool.h>
-#endif
-
/* Forward-declare this since it comes up in function prototypes */
namespace factor
{
void factor_vm::primitive_bignum_bitp()
{
- fixnum bit = to_fixnum(ctx->pop());
+ int bit = (int)to_fixnum(ctx->pop());
bignum *x = untag<bignum>(ctx->pop());
ctx->push(tag_boolean(bignum_logbitp(bit,x)));
}
void factor_vm::primitive_byte_array_to_bignum()
{
- cell n_digits = array_capacity(untag_check<byte_array>(ctx->peek()));
+ unsigned int n_digits = (unsigned int)array_capacity(untag_check<byte_array>(ctx->peek()));
bignum * result = digit_stream_to_bignum(n_digits,factor::bignum_producer,0x100,0);
ctx->replace(tag<bignum>(result));
}
void factor_vm::primitive_bits_float()
{
- ctx->push(allot_float(bits_float(to_cell(ctx->pop()))));
+ ctx->push(allot_float(bits_float((u32)to_cell(ctx->pop()))));
}
void factor_vm::primitive_double_bits()
#define ESP Rsp
#define EIP Rip
-#define X87SW(ctx) (ctx)->FloatSave.StatusWord
#define MXCSR(ctx) (ctx)->MxCsr
}
case STATUS_FLOAT_UNDERFLOW:
case STATUS_FLOAT_MULTIPLE_FAULTS:
case STATUS_FLOAT_MULTIPLE_TRAPS:
+#ifdef FACTOR_AMD64
+ signal_fpu_status = fpu_status(MXCSR(c));
+#else
signal_fpu_status = fpu_status(X87SW(c) | MXCSR(c));
X87SW(c) = 0;
+#endif
MXCSR(c) &= 0xffffffc0;
c->EIP = (cell)factor::fp_signal_handler_impl;
break;
void factor_vm::primitive_exit()
{
- exit(to_fixnum(ctx->pop()));
+ exit((int)to_fixnum(ctx->pop()));
}
void factor_vm::primitive_system_micros()
data_root<string> str(str_,this);
if(fill <= 0x7f)
- memset(&str->data()[start],fill,capacity - start);
+ memset(&str->data()[start],(int)fill,capacity - start);
else
{
cell i;
void not_implemented_error();
bool in_page(cell fault, cell area, cell area_size, int offset);
void memory_protection_error(cell addr, stack_frame *native_stack);
- void signal_error(int signal, stack_frame *native_stack);
+ void signal_error(cell signal, stack_frame *native_stack);
void divide_by_zero_error();
void fp_trap_error(unsigned int fpu_status, stack_frame *signal_callstack_top);
void primitive_call_clear();
cell compute_entry_point_pic_tail_address(cell w_);
cell code_block_owner(code_block *compiled);
void update_word_references(code_block *compiled);
- void check_code_address(cell address);
void undefined_symbol();
cell compute_dlsym_address(array *literals, cell index);
cell compute_vm_address(cell arg);
inline void check_code_pointer(cell ptr)
{
#ifdef FACTOR_DEBUG
- assert(in_code_heap_p(ptr));
+ //assert(in_code_heap_p(ptr));
#endif
}