chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Question about embedding Chicken scheme


From: Felix
Subject: Re: [Chicken-users] Question about embedding Chicken scheme
Date: Fri, 08 Feb 2013 20:29:44 +0100 (CET)

From: Felix <address@hidden>
Subject: Re: [Chicken-users] Question about embedding Chicken scheme
Date: Tue, 22 Jan 2013 21:59:53 +0100 (CET)

> From: Julian Day <address@hidden>
> Subject: Re: [Chicken-users] Question about embedding Chicken scheme
> Date: Mon, 21 Jan 2013 18:41:21 -0600
> 
>> On 20/01/2013 2:53 PM, Felix wrote:
>> 
>>> That's correct. Visual C++ is currently not supported and the current
>>> CHICKEN sources will not compile with it.
>> 
>> Hi Felix,
>> 
>> Are there any fundamental issues preventing Visual C++ support, or is
>> it a case of there just being no support at present?
> 
> There is currently no one who is willing to maintain the build.
> Visual C++ support was there once - to resurrect it, it would be
> necessary to dig in the repo history. But there is no intrinsic reason
> for a lack of support apart from having to deal with MS development
> tools.

Attached is an (untested) patch with changes I pulled out of the very
first commit in the git repository. It may be a start for getting
MSVC support back into a usable state.


cheers,
felix
diff --git a/chicken.h b/chicken.h
index 566aad3..c812b8d 100644
--- a/chicken.h
+++ b/chicken.h
@@ -93,7 +93,8 @@
 # define C_SOLARIS
 #endif
 
-#ifdef __MINGW64__
+/*YYY MSVC variant? */
+#if defined(__MINGW64__)
 # define C_LLP
 #endif
 
@@ -141,14 +142,21 @@
 # include <sys/byteorder.h>
 #endif
 
-#if defined(__MINGW32__) || defined(__WATCOMC__)
+#if defined(__MINGW32__) || defined(__WATCOMC__) || defined(_MSC_VER)
 # include <malloc.h>
 #endif
 
+#ifdef _MSC_VER
+# include <io.h>
+#endif
+
 /* Much better with stack allocation API */
 
+#ifdef _MSC_VER
+# define alloca             _alloca
+#endif
+
 #ifdef HAVE_ALLOCA_H
-# include <alloca.h>
 #elif !defined(alloca) /* predefined by HP cc +Olibcalls */
 void *alloca ();
 #endif
@@ -180,6 +188,20 @@ void *alloca ();
 
 /* Make sure some common C identifiers are availble w/ Windows */
 
+#ifdef _MSC_VER
+# define strncasecmp       strnicmp
+# define isatty            _isatty
+typedef __int8             int8_t;
+typedef unsigned __int8    uint8_t;
+typedef __int16            int16_t;
+typedef unsigned  __int16  uint16_t;
+typedef __int32            int32_t;
+typedef unsigned __int32   uint32_t;
+typedef __int64            int64_t;
+typedef unsigned __int64   uint64_t;
+# pragma warning(disable: 4101)
+#endif
+
 /* Could be used by C++ source */
 
 #ifdef __cplusplus
@@ -207,6 +229,23 @@ void *alloca ();
 #   undef  C_varextern
 #   define C_varextern             C_extern __declspec(dllimport)
 #  endif
+# elif defined(_MSC_VER)
+#  undef  C_fctimport
+#  define C_fctimport              __declspec(dllexport)
+#  undef  C_externimport
+#  undef  C_externexport
+#  define C_externexport           C_extern __declspec(dllexport)
+#  undef  C_varextern
+#  undef  C_fctexport
+#  ifdef C_BUILDING_LIBCHICKEN
+#   define C_varextern             C_extern __declspec(dllexport)
+#   define C_fctexport             __declspec(dllexport)
+#   define C_externimport          C_extern __declspec(dllexport)
+#  else
+#   define C_varextern             C_extern __declspec(dllimport)
+#   define C_fctexport             __declspec(dllimport)
+#   define C_externimport          C_extern __declspec(dllimport)
+#  endif
 # elif defined(__WATCOMC__)
 #  undef  C_fctimport
 #  define C_fctimport              __declspec(dllexport)
@@ -243,6 +282,8 @@ void *alloca ();
 # if defined(__i386__) && !defined(__clang__)
 #  define C_regparm               __attribute__ ((regparm(3)))
 # endif
+#elif defined(_MSC_VER)
+# define C_fcall                  __fastcall
 #elif defined(__WATCOMC__)
 # define C_ccall                  __cdecl
 #endif
@@ -282,6 +323,8 @@ void *alloca ();
 #ifdef C_ENABLE_TLS
 # if defined(__GNUC__)
 #  define C_TLS                    __thread
+# elif defined(_MSC_VER)
+#  define C_TLS                    __declspec(thread)
 # endif
 #endif
 
@@ -502,7 +545,7 @@ static inline int isinf_ld (long double x)
 #define C_F32_LOCATIVE            8
 #define C_F64_LOCATIVE            9
 
-#if defined (__MINGW32__)
+#if defined(_MSC_VER) || defined (__MINGW32__)
 # define C_s64                    __int64
 # define C_u64                    unsigned __int64
 #else
@@ -675,6 +718,8 @@ static inline int isinf_ld (long double x)
 
 #if defined(__CYGWIN__)
 # define C_BUILD_PLATFORM "cygwin"
+#elif defined(_MSC_VER)
+# define C_BUILD_PLATFORM "msvc"
 #elif defined(__SUNPRO_C)
 # define C_BUILD_PLATFORM "sun"
 #elif defined(__MINGW32__)
@@ -973,6 +1018,11 @@ DECL_C_PROC_p0 (128,  1,0,0,0,0,0,0,0)
 # define C_access                   access
 # define C_getpid                   getpid
 # define C_getenv                   getenv
+# ifdef _MSC_VER
+#  define C_stat                    _stat
+# else
+#  define C_stat                    stat
+# endif
 # ifdef __linux__
 extern double round(double);
 extern double trunc(double);
diff --git a/runtime.c b/runtime.c
index 8f1949a..f7adf54 100644
--- a/runtime.c
+++ b/runtime.c
@@ -115,12 +115,23 @@ static C_TLS int timezone;
 # endif
 #endif
 
-#ifdef C_HACKED_APPLY
-# if defined(__MACH__) || defined(__MINGW32__) || defined(__CYGWIN__)
+#ifdef _MSC_VER
+# define S_IFMT             _S_IFMT
+# define S_IFDIR            _S_IFDIR
+# define timezone           _timezone
+# if defined(_M_IX86)
+#  ifndef C_HACKED_APPLY
+#   define C_HACKED_APPLY
+#  endif
+# endif
+#else
+# ifdef C_HACKED_APPLY
+#  if defined(__MACH__) || defined(__MINGW32__) || defined(__CYGWIN__)
 extern void C_do_apply_hack(void *proc, C_word *args, int count) C_noret;
-# else
+#  else
 extern void _C_do_apply_hack(void *proc, C_word *args, int count) C_noret;
-#  define C_do_apply_hack _C_do_apply_hack
+#   define C_do_apply_hack _C_do_apply_hack
+#  endif
 # endif
 #endif
 
@@ -611,7 +622,7 @@ int CHICKEN_initialize(int heap, int stack, int symbols, 
void *toplevel)
   /*FIXME Should have C_tzset in chicken.h? */
 #ifdef C_NONUNIX
   C_startup_time_seconds = (time_t)0;
-# if defined(__MINGW32__)
+# if defined(_MSC_VER) || defined(__MINGW32__)
   /* Make sure _tzname, _timezone, and _daylight are set */
   _tzset();
 # endif
@@ -4310,7 +4321,11 @@ C_regparm C_word C_fcall C_fudge(C_word fudge_factor)
     return C_fix(C_trace_buffer_size);
 
   case C_fix(30):              /* unused */
+#ifdef _MSC_VER
+    return C_fix(_MSC_VER);
+#else
     return C_SCHEME_FALSE;
+#endif
 
   case C_fix(31):              /* GC time since last invocation */
     tgc = timer_accumulated_gc_ms;
@@ -6029,6 +6044,13 @@ void C_ccall C_apply(C_word c, C_word closure, C_word k, 
C_word fn, ...)
   buf[ 2 ] = k;
   C_memcpy(&buf[ 3 ], C_temporary_stack_limit, n * sizeof(C_word));
   proc = (void *)C_block_item(fn2, 0);
+# ifdef _MSC_VER
+  __asm { 
+    mov eax, proc
+    mov esp, buf
+    call eax
+  }
+# elif defined(__GNUC__)
   C_do_apply_hack(proc, buf, n + 3);
 #else
   C_do_apply(n, fn2, k);
@@ -9373,7 +9395,7 @@ C_i_file_exists_p(C_word name, C_word file, C_word dir)
   struct stat buf;
   int res;
 
-  res = stat(C_c_string(name), &buf);
+  res = C_stat(C_c_string(name), &buf);
 
   if(res != 0) {
     switch(errno) {

reply via email to

[Prev in Thread] Current Thread [Next in Thread]