Win32 version ported to gcc, eliminate MSVC hacks, add gcc hacks
parent
d22b17c169
commit
88ba22ff6c
45
Makefile
45
Makefile
|
|
@ -4,7 +4,15 @@ DEFAULT_LIBS = -lm
|
||||||
|
|
||||||
STRIP = strip
|
STRIP = strip
|
||||||
|
|
||||||
OBJS = native/arithmetic.o native/array.o native/bignum.o \
|
obj-$(UNIX) += native/unix/file.o native/unix/io.o native/unix/socket.o \
|
||||||
|
native/unix/signal.o native/unix/read.o native/unix/write.o \
|
||||||
|
native/unix/ffi.o native/unix/run.o
|
||||||
|
|
||||||
|
obj-$(WIN32) += native/win32/ffi.o native/win32/file.o native/win32/io.o \
|
||||||
|
native/win32/misc.o native/win32/read.o native/win32/write.o \
|
||||||
|
native/win32/run.o
|
||||||
|
|
||||||
|
obj-y += native/arithmetic.o native/array.o native/bignum.o \
|
||||||
native/s48_bignum.o \
|
native/s48_bignum.o \
|
||||||
native/complex.o native/cons.o native/error.o \
|
native/complex.o native/cons.o native/error.o \
|
||||||
native/factor.o native/fixnum.o \
|
native/factor.o native/fixnum.o \
|
||||||
|
|
@ -17,13 +25,6 @@ OBJS = native/arithmetic.o native/array.o native/bignum.o \
|
||||||
native/string.o native/types.o native/vector.o \
|
native/string.o native/types.o native/vector.o \
|
||||||
native/word.o native/compiler.o \
|
native/word.o native/compiler.o \
|
||||||
native/ffi.o native/boolean.o \
|
native/ffi.o native/boolean.o \
|
||||||
native/unix/file.o \
|
|
||||||
native/unix/io.o \
|
|
||||||
native/unix/socket.o \
|
|
||||||
native/unix/signal.o \
|
|
||||||
native/unix/read.o \
|
|
||||||
native/unix/write.o \
|
|
||||||
native/unix/ffi.o \
|
|
||||||
native/debug.o \
|
native/debug.o \
|
||||||
native/hashtable.o
|
native/hashtable.o
|
||||||
|
|
||||||
|
|
@ -35,6 +36,7 @@ default:
|
||||||
@echo "linux"
|
@echo "linux"
|
||||||
@echo "macosx"
|
@echo "macosx"
|
||||||
@echo "solaris"
|
@echo "solaris"
|
||||||
|
@echo "windows"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Also, you might want to set the SITE_CFLAGS environment"
|
@echo "Also, you might want to set the SITE_CFLAGS environment"
|
||||||
@echo "variable to enable some CPU-specific optimizations; this"
|
@echo "variable to enable some CPU-specific optimizations; this"
|
||||||
|
|
@ -45,34 +47,45 @@ default:
|
||||||
bsd:
|
bsd:
|
||||||
$(MAKE) f \
|
$(MAKE) f \
|
||||||
CFLAGS="$(DEFAULT_CFLAGS) -DFFI -export-dynamic -pthread" \
|
CFLAGS="$(DEFAULT_CFLAGS) -DFFI -export-dynamic -pthread" \
|
||||||
LIBS="$(DEFAULT_LIBS)"
|
LIBS="$(DEFAULT_LIBS)" \
|
||||||
|
UNIX=y
|
||||||
|
|
||||||
bsd-nopthread:
|
bsd-nopthread:
|
||||||
$(MAKE) f \
|
$(MAKE) f \
|
||||||
CFLAGS="$(DEFAULT_CFLAGS) -DFFI -export-dynamic" \
|
CFLAGS="$(DEFAULT_CFLAGS) -DFFI -export-dynamic" \
|
||||||
LIBS="$(DEFAULT_LIBS)"
|
LIBS="$(DEFAULT_LIBS)" \
|
||||||
|
UNIX=y
|
||||||
|
|
||||||
macosx:
|
macosx:
|
||||||
$(MAKE) f \
|
$(MAKE) f \
|
||||||
CFLAGS="$(DEFAULT_CFLAGS) -DFFI" \
|
CFLAGS="$(DEFAULT_CFLAGS) -DFFI" \
|
||||||
LIBS="$(DEFAULT_LIBS)"
|
LIBS="$(DEFAULT_LIBS)" \
|
||||||
|
UNIX=y
|
||||||
|
|
||||||
linux:
|
linux:
|
||||||
$(MAKE) f \
|
$(MAKE) f \
|
||||||
CFLAGS="$(DEFAULT_CFLAGS) -DFFI -export-dynamic" \
|
CFLAGS="$(DEFAULT_CFLAGS) -DFFI -export-dynamic" \
|
||||||
LIBS="$(DEFAULT_LIBS) -ldl"
|
LIBS="$(DEFAULT_LIBS) -ldl" \
|
||||||
|
UNIX=y
|
||||||
|
|
||||||
solaris:
|
solaris:
|
||||||
$(MAKE) f \
|
$(MAKE) f \
|
||||||
CFLAGS="$(DEFAULT_CFLAGS)" \
|
CFLAGS="$(DEFAULT_CFLAGS)" \
|
||||||
LIBS="$(DEFAULT_LIBS) -lsocket -lnsl -lm"
|
LIBS="$(DEFAULT_LIBS) -lsocket -lnsl -lm" \
|
||||||
|
UNIX=y
|
||||||
|
|
||||||
f: $(OBJS)
|
windows:
|
||||||
$(CC) $(LIBS) $(CFLAGS) -o $@ $(OBJS)
|
$(MAKE) f \
|
||||||
|
CFLAGS="$(DEFAULT_CFLAGS) -DFFI -DWIN32" \
|
||||||
|
LIBS="$(DEFAULT_LIBS)" \
|
||||||
|
WIN32=y
|
||||||
|
|
||||||
|
f: $(obj-y)
|
||||||
|
$(CC) $(LIBS) $(CFLAGS) -o $@ $(obj-y)
|
||||||
$(STRIP) $@
|
$(STRIP) $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS)
|
rm -f $(obj-y)
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) -c $(CFLAGS) -o $@ $<
|
$(CC) -c $(CFLAGS) -o $@ $<
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ C: dlist-node
|
||||||
|
|
||||||
: (dlist-each) ( quot dnode -- )
|
: (dlist-each) ( quot dnode -- )
|
||||||
[
|
[
|
||||||
[ dlist-node-data swap [ call ] keep ] keep
|
[ dlist-node-data swap call ] 2keep
|
||||||
dlist-node-next (dlist-each)
|
dlist-node-next (dlist-each)
|
||||||
] [
|
] [
|
||||||
drop
|
drop
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
userenv[ARGS_ENV] = args;
|
userenv[ARGS_ENV] = args;
|
||||||
|
|
||||||
run();
|
platform_run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ DLLEXPORT CELL cs;
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -57,33 +58,11 @@ DLLEXPORT CELL cs;
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
#pragma warning(disable:4312)
|
|
||||||
#pragma warning(disable:4311)
|
|
||||||
typedef enum { false, true } _Bool;
|
|
||||||
typedef enum _Bool bool;
|
|
||||||
typedef unsigned char uint8_t;
|
|
||||||
typedef unsigned short uint16_t;
|
|
||||||
typedef unsigned int uint32_t;
|
|
||||||
typedef unsigned __int64 uint64_t;
|
|
||||||
typedef signed char int8_t;
|
|
||||||
typedef signed short int16_t;
|
|
||||||
typedef signed int int32_t;
|
|
||||||
typedef signed __int64 int64_t;
|
|
||||||
#define snprintf _snprintf
|
|
||||||
#else
|
|
||||||
#include <stdbool.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(FFI) && !defined(WIN32)
|
#if defined(FFI) && !defined(WIN32)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif /* FFI */
|
#endif /* FFI */
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#define INLINE inline static
|
||||||
#define INLINE static __inline
|
|
||||||
#else
|
|
||||||
#define INLINE inline static
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define FIXNUM_MAX (LONG_MAX >> TAG_BITS)
|
#define FIXNUM_MAX (LONG_MAX >> TAG_BITS)
|
||||||
#define FIXNUM_MIN (LONG_MIN >> TAG_BITS)
|
#define FIXNUM_MIN (LONG_MIN >> TAG_BITS)
|
||||||
|
|
@ -101,7 +80,7 @@ DLLEXPORT CELL cs;
|
||||||
typedef unsigned char BYTE;
|
typedef unsigned char BYTE;
|
||||||
|
|
||||||
/* Memory areas */
|
/* Memory areas */
|
||||||
#define DEFAULT_ARENA (8 * 1024 * 1024)
|
#define DEFAULT_ARENA (16 * 1024 * 1024)
|
||||||
#define COMPILE_ZONE_SIZE (8 * 1024 * 1024)
|
#define COMPILE_ZONE_SIZE (8 * 1024 * 1024)
|
||||||
#define STACK_SIZE (2 * 1024 * 1024)
|
#define STACK_SIZE (2 * 1024 * 1024)
|
||||||
|
|
||||||
|
|
|
||||||
12
native/run.c
12
native/run.c
|
|
@ -21,12 +21,9 @@ void run(void)
|
||||||
/* Error handling. */
|
/* Error handling. */
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
setjmp(toplevel);
|
setjmp(toplevel);
|
||||||
__try
|
|
||||||
{
|
|
||||||
#else
|
#else
|
||||||
sigsetjmp(toplevel, 1);
|
sigsetjmp(toplevel, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(thrown_error != F)
|
if(thrown_error != F)
|
||||||
{
|
{
|
||||||
if(thrown_keep_stacks)
|
if(thrown_keep_stacks)
|
||||||
|
|
@ -61,15 +58,6 @@ void run(void)
|
||||||
else
|
else
|
||||||
dpush(next);
|
dpush(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
}
|
|
||||||
__except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
|
|
||||||
EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
|
|
||||||
{
|
|
||||||
signal_error(SIGSEGV);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XT of deferred words */
|
/* XT of deferred words */
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,7 @@ INLINE void call(CELL quot)
|
||||||
void clear_environment(void);
|
void clear_environment(void);
|
||||||
|
|
||||||
void run(void);
|
void run(void);
|
||||||
|
void platform_run(void);
|
||||||
void undefined(F_WORD* word);
|
void undefined(F_WORD* word);
|
||||||
void docol(F_WORD* word);
|
void docol(F_WORD* word);
|
||||||
void dosym(F_WORD* word);
|
void dosym(F_WORD* word);
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,4 @@ void call_profiling_step(int signal, siginfo_t* siginfo, void* uap);
|
||||||
void init_signals(void);
|
void init_signals(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void primitive_call_profiling(void);
|
void primitive_call_profiling(F_WORD *);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
void init_sockaddr(struct sockaddr_in *name,
|
void init_sockaddr(struct sockaddr_in *name,
|
||||||
const char *hostname, uint16_t port);
|
const char *hostname, uint16_t port);
|
||||||
int make_client_socket(const char* hostname, uint16_t port);
|
int make_client_socket(const char* hostname, uint16_t port);
|
||||||
void primitive_client_socket(void);
|
void primitive_client_socket(F_WORD *);
|
||||||
int make_server_socket(uint16_t port);
|
int make_server_socket(uint16_t port);
|
||||||
void primitive_server_socket(void);
|
void primitive_server_socket(F_WORD *);
|
||||||
void primitive_add_accept_io_task(void);
|
void primitive_add_accept_io_task(F_WORD *);
|
||||||
CELL accept_connection(F_PORT* p);
|
CELL accept_connection(F_PORT* p);
|
||||||
void primitive_accept_fd(void);
|
void primitive_accept_fd(F_WORD *);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "../factor.h"
|
||||||
|
|
||||||
|
void platform_run()
|
||||||
|
{
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -60,7 +60,7 @@ void init_signals(void)
|
||||||
sigaction(SIGQUIT,&dump_sigaction,NULL);
|
sigaction(SIGQUIT,&dump_sigaction,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void primitive_call_profiling(void)
|
void primitive_call_profiling(F_WORD *word)
|
||||||
{
|
{
|
||||||
CELL d = dpop();
|
CELL d = dpop();
|
||||||
if(d == F)
|
if(d == F)
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ int make_client_socket(const char* hostname, uint16_t port)
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
void primitive_client_socket(void)
|
void primitive_client_socket(F_WORD *word)
|
||||||
{
|
{
|
||||||
uint16_t p = (uint16_t)to_fixnum(dpop());
|
uint16_t p = (uint16_t)to_fixnum(dpop());
|
||||||
char* host;
|
char* host;
|
||||||
|
|
@ -94,14 +94,14 @@ int make_server_socket(uint16_t port)
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
void primitive_server_socket(void)
|
void primitive_server_socket(F_WORD *word)
|
||||||
{
|
{
|
||||||
uint16_t p = (uint16_t)to_fixnum(dpop());
|
uint16_t p = (uint16_t)to_fixnum(dpop());
|
||||||
maybe_garbage_collection();
|
maybe_garbage_collection();
|
||||||
dpush(tag_object(port(PORT_SPECIAL,make_server_socket(p))));
|
dpush(tag_object(port(PORT_SPECIAL,make_server_socket(p))));
|
||||||
}
|
}
|
||||||
|
|
||||||
void primitive_add_accept_io_task(void)
|
void primitive_add_accept_io_task(F_WORD *word)
|
||||||
{
|
{
|
||||||
CELL callback, port;
|
CELL callback, port;
|
||||||
maybe_garbage_collection();
|
maybe_garbage_collection();
|
||||||
|
|
@ -133,7 +133,7 @@ CELL accept_connection(F_PORT* p)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void primitive_accept_fd(void)
|
void primitive_accept_fd(F_WORD *word)
|
||||||
{
|
{
|
||||||
F_PORT* p;
|
F_PORT* p;
|
||||||
maybe_garbage_collection();
|
maybe_garbage_collection();
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
* Various stubs for functions not currently implemented in the Windows port.
|
* Various stubs for functions not currently implemented in the Windows port.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void init_signals(void)
|
void init_signals()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void primitive_accept_fd(F_WORD *word)
|
void primitive_accept_fd(F_WORD *word)
|
||||||
|
|
@ -32,3 +32,4 @@ void primitive_call_profiling(F_WORD *word)
|
||||||
{
|
{
|
||||||
undefined(word);
|
undefined(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
#include "../factor.h"
|
||||||
|
|
||||||
|
/* SEH support. Proceed with caution. */
|
||||||
|
typedef long exception_handler_t(
|
||||||
|
void *rec, void *frame, void *context, void *dispatch);
|
||||||
|
|
||||||
|
typedef struct exception_record {
|
||||||
|
struct exception_record *next_handler;
|
||||||
|
void *handler_func;
|
||||||
|
} exception_record_t;
|
||||||
|
|
||||||
|
void seh_call(void (*func)(), exception_handler_t *handler)
|
||||||
|
{
|
||||||
|
exception_record_t record;
|
||||||
|
asm("mov %%fs:0, %0" : "=r" (record.next_handler));
|
||||||
|
asm("mov %0, %%fs:0" : : "r" (&record));
|
||||||
|
record.handler_func = handler;
|
||||||
|
func();
|
||||||
|
asm("mov %0, %%fs:0" : "=r" (record.next_handler));
|
||||||
|
}
|
||||||
|
|
||||||
|
static long exception_handler(void *rec, void *frame, void *ctx, void *dispatch)
|
||||||
|
{
|
||||||
|
signal_error(SIGSEGV);
|
||||||
|
}
|
||||||
|
|
||||||
|
void platform_run ()
|
||||||
|
{
|
||||||
|
seh_call(run, exception_handler);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue