[MLton-commit] r4591

Stephen Weeks MLton@mlton.org
Wed, 24 May 2006 19:51:50 -0700


First cut at compiling the runtime on Cygwin.  Some problems remain.


----------------------------------------------------------------------

A   mlton/branches/on-20050822-x86_64-branch/basis-library/config/c/x86-cygwin/c-types.sml
U   mlton/branches/on-20050822-x86_64-branch/runtime/platform/cygwin.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/platform/cygwin.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/platform/windows.c

----------------------------------------------------------------------

Added: mlton/branches/on-20050822-x86_64-branch/basis-library/config/c/x86-cygwin/c-types.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/config/c/x86-cygwin/c-types.sml	2006-05-25 02:38:26 UTC (rev 4590)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/config/c/x86-cygwin/c-types.sml	2006-05-25 02:51:47 UTC (rev 4591)
@@ -0,0 +1,131 @@
+(* Copyright (C) 2004-2006 Henry Cejtin, Matthew Fluet, Suresh
+ *    Jagannathan, and Stephen Weeks.
+ *
+ * MLton is released under a BSD-style license.
+ * See the file MLton-LICENSE for details.
+ *)
+
+
+(* C *)
+structure C_Char = struct open Int8 type t = int end
+functor C_Char_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int8 (A)
+structure C_SChar = struct open Int8 type t = int end
+functor C_SChar_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int8 (A)
+structure C_UChar = struct open Word8 type t = word end
+functor C_UChar_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word8 (A)
+structure C_Short = struct open Int16 type t = int end
+functor C_Short_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int16 (A)
+structure C_SShort = struct open Int16 type t = int end
+functor C_SShort_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int16 (A)
+structure C_UShort = struct open Word16 type t = word end
+functor C_UShort_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word16 (A)
+structure C_Int = struct open Int32 type t = int end
+functor C_Int_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int32 (A)
+structure C_SInt = struct open Int32 type t = int end
+functor C_SInt_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int32 (A)
+structure C_UInt = struct open Word32 type t = word end
+functor C_UInt_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+structure C_Long = struct open Int32 type t = int end
+functor C_Long_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int32 (A)
+structure C_SLong = struct open Int32 type t = int end
+functor C_SLong_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int32 (A)
+structure C_ULong = struct open Word32 type t = word end
+functor C_ULong_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+structure C_LongLong = struct open Int64 type t = int end
+functor C_LongLong_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int64 (A)
+structure C_SLongLong = struct open Int64 type t = int end
+functor C_SLongLong_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int64 (A)
+structure C_ULongLong = struct open Word64 type t = word end
+functor C_ULongLong_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word64 (A)
+structure C_Float = struct open Real32 type t = real end
+functor C_Float_ChooseRealN (A: CHOOSE_REALN_ARG) = ChooseRealN_Real32 (A)
+structure C_Double = struct open Real64 type t = real end
+functor C_Double_ChooseRealN (A: CHOOSE_REALN_ARG) = ChooseRealN_Real64 (A)
+structure C_Size = struct open Word32 type t = word end
+functor C_Size_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+
+structure C_Pointer = struct open Word32 type t = word end
+functor C_Pointer_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+structure C_String = struct open Word32 type t = word end
+functor C_String_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+structure C_StringArray = struct open Word32 type t = word end
+functor C_StringArray_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+
+(* Generic integers *)
+structure C_Fd = C_Int
+functor C_Fd_ChooseIntN (A: CHOOSE_INTN_ARG) = C_Int_ChooseIntN (A)
+structure C_Signal = C_Int
+functor C_Signal_ChooseIntN (A: CHOOSE_INTN_ARG) = C_Int_ChooseIntN (A)
+structure C_Status = C_Int
+functor C_Status_ChooseIntN (A: CHOOSE_INTN_ARG) = C_Int_ChooseIntN (A)
+structure C_Sock = C_Int
+functor C_Sock_ChooseIntN (A: CHOOSE_INTN_ARG) = C_Int_ChooseIntN (A)
+
+(* C99 *)
+structure C_Ptrdiff = struct open Int32 type t = int end
+functor C_Ptrdiff_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int32 (A)
+structure C_Intmax = struct open Int64 type t = int end
+functor C_Intmax_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int64 (A)
+structure C_UIntmax = struct open Word64 type t = word end
+functor C_UIntmax_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word64 (A)
+structure C_Intptr = struct open Int32 type t = int end
+functor C_Intptr_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int32 (A)
+structure C_UIntptr = struct open Word32 type t = word end
+functor C_UIntptr_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+
+(* from <dirent.h> *)
+structure C_DirP = struct open Word32 type t = word end
+functor C_DirP_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+
+(* from <poll.h> *)
+structure C_NFds = struct open Word32 type t = word end
+functor C_NFds_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+
+(* from <resource.h> *)
+structure C_RLim = struct open Word32 type t = word end
+functor C_RLim_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+
+(* from <sys/types.h> *)
+structure C_Clock = struct open Word32 type t = word end
+functor C_Clock_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+structure C_Dev = struct open Word32 type t = word end
+functor C_Dev_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+structure C_GId = struct open Word32 type t = word end
+functor C_GId_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+structure C_Id = struct open Word32 type t = word end
+functor C_Id_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+structure C_INo = struct open Word64 type t = word end
+functor C_INo_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word64 (A)
+structure C_Mode = struct open Word32 type t = word end
+functor C_Mode_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+structure C_NLink = struct open Word16 type t = word end
+functor C_NLink_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word16 (A)
+structure C_Off = struct open Int64 type t = int end
+functor C_Off_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int64 (A)
+structure C_PId = struct open Int32 type t = int end
+functor C_PId_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int32 (A)
+structure C_SSize = struct open Int32 type t = int end
+functor C_SSize_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int32 (A)
+structure C_SUSeconds = struct open Int32 type t = int end
+functor C_SUSeconds_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int32 (A)
+structure C_Time = struct open Int32 type t = int end
+functor C_Time_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int32 (A)
+structure C_UId = struct open Word32 type t = word end
+functor C_UId_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+
+(* from <sys/socket.h> *)
+structure C_Socklen = struct open Int32 type t = int end
+functor C_Socklen_ChooseIntN (A: CHOOSE_INTN_ARG) = ChooseIntN_Int32 (A)
+
+(* from <termios.h> *)
+structure C_CC = struct open Word8 type t = word end
+functor C_CC_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word8 (A)
+structure C_Speed = struct open Word32 type t = word end
+functor C_Speed_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+structure C_TCFlag = struct open Word32 type t = word end
+functor C_TCFlag_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+
+(* from "gmp.h" *)
+structure C_MPLimb = struct open Word32 type t = word end
+functor C_MPLimb_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word32 (A)
+

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/platform/cygwin.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/platform/cygwin.c	2006-05-25 02:38:26 UTC (rev 4590)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/platform/cygwin.c	2006-05-25 02:51:47 UTC (rev 4591)
@@ -48,12 +48,12 @@
 /*                       Posix                       */
 /* ------------------------------------------------- */
 
-void Posix_IO_setbin (Fd fd) {
+void Posix_IO_setbin (C_Fd_t fd) {
         /* cygwin has a different method for working with its fds */
         setmode (fd, O_BINARY);
 }
 
-void Posix_IO_settext (Fd fd) {
+void Posix_IO_settext (C_Fd_t fd) {
         /* cygwin has a different method for working with its fds */
         setmode (fd, O_TEXT);
 }
@@ -67,7 +67,7 @@
  * is a secret magical pipe for sending signals and exit statuses over.
  * Screw that. We implement our own cwait using pure win32.
  */
-Pid MLton_Process_cwait (Pid pid, Pointer status) {
+C_Errno_t(C_PId_t) MLton_Process_cwait(C_PId_t pid, Ref(C_Status_t) status) {
         HANDLE h;
         
         h = (HANDLE)pid;

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/platform/cygwin.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/platform/cygwin.h	2006-05-25 02:38:26 UTC (rev 4590)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/platform/cygwin.h	2006-05-25 02:51:47 UTC (rev 4591)
@@ -36,4 +36,20 @@
 #define MSG_DONTWAIT 0x1000000
 #define PF_INET6 0
 
-struct sockaddr_in6 {};
+struct sockaddr_in6 {
+  int dummy; // quell gcc warnings about "struct has no members"
+};
+
+typedef unsigned int nfds_t;
+typedef long suseconds_t; // type of timeval.tv_usec in sys/time.h
+
+// /usr/include/cygwin/socket.h has this ifdef'd out for now.
+#define AF_INET6 23
+
+// Unimplemented on Cygwin
+#define MSG_WAITALL 0
+#define MSG_EOR 0
+
+
+
+

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/platform/windows.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/platform/windows.c	2006-05-25 02:38:26 UTC (rev 4590)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/platform/windows.c	2006-05-25 02:51:47 UTC (rev 4591)
@@ -1,6 +1,31 @@
 HANDLE fileDesHandle (int fd);
 
+#define BUFSIZE 65536
 
+int tempFileDes (void) {
+  /* Based on http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/creating_and_using_a_temporary_file.asp
+   */  
+  HANDLE hTempFile; 
+  DWORD dwRetVal;
+  DWORD dwBufSize=BUFSIZE;
+  UINT uRetVal;
+  char szTempName[BUFSIZE];  
+  char lpPathBuffer[BUFSIZE];
+
+  dwRetVal = GetTempPath(dwBufSize, lpPathBuffer);
+  if (dwRetVal > dwBufSize)
+    diee ("GetTempPath failed with error %ld.\n", GetLastError());
+  uRetVal = GetTempFileName(lpPathBuffer, "TempFile", 0, szTempName);
+  if (0 == uRetVal)
+    diee ("GetTempFileName failed with error %ld.\n", GetLastError());
+  hTempFile = CreateFile((LPTSTR) szTempName, GENERIC_READ | GENERIC_WRITE,
+    0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE,
+    NULL);                
+  if (hTempFile == INVALID_HANDLE_VALUE)
+    diee ("CreateFile failed with error %ld.\n", GetLastError());
+  return hTempFile;
+}
+
 static void displayMaps (void) {
         MEMORY_BASIC_INFORMATION buf;
         LPVOID lpAddress;
@@ -108,7 +133,8 @@
                 die ("VirtualFree decommit failed");
 }
 
-static inline void *Windows_mmapAnon (void *start, size_t length) {
+static inline void *Windows_mmapAnon (__atribute__ ((unused)) void *start,
+                                        size_t length) {
         void *res;
 
         /* Use "0" instead of "start" as the first argument to VirtualAlloc