[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / interpreter / prelude.h
1 /* -*- mode: hugs-c; -*- */
2 /* --------------------------------------------------------------------------
3  * Basic data type definitions, prototypes and standard macros including
4  * machine dependent variations...
5  *
6  * Copyright (c) The University of Nottingham and Yale University, 1994-1997.
7  * All rights reserved. See NOTICE for details and conditions of use etc...
8  * Hugs version 1.4, December 1997
9  *
10  * $RCSfile: prelude.h,v $
11  * $Revision: 1.2 $
12  * $Date: 1998/12/02 13:22:33 $
13  * ------------------------------------------------------------------------*/
14
15 #include "config.h"
16 #include "options.h"
17 #include <stdio.h>
18
19 /*---------------------------------------------------------------------------
20  * Most of the configuration code from earlier versions of Hugs has been moved
21  * into config.h (which is usually automatically generated).  
22  *
23  * Most of the configuration code is "feature based".  That is, the 
24  * configure script looks to see if a particular feature (or misfeature)
25  * is present on the compiler/OS.  
26  *
27  * A small amount of configuration code is still "system based": it tests
28  * flags to determine what kind of compiler/system it's running on - from
29  * which it infers what features the compiler/system has.  Use of system
30  * based tests generally indicates that we can't remember/figure out
31  * what the original problem was and so we can't add an appropriate feature
32  * test to the configure script.
33  *-------------------------------------------------------------------------*/
34
35 #ifdef __RISCOS__ /* Acorn DesktopC running RISCOS2 or 3 */
36 # define RISCOS 1
37 #else
38 # define RISCOS 0
39 #endif
40
41 #if defined __DJGPP__ && __DJGPP__==2
42 # define DJGPP2 1
43 #else
44 # define DJGPP2 0
45 #endif
46
47 #if defined __MSDOS__ && __MSDOS__ && !DJGPP2
48 # define DOS 1
49 #else
50 # define DOS 0
51 #endif
52
53 #if defined _WIN32 | defined __WIN32__
54 # define IS_WIN32 1
55 #else
56 # define IS_WIN32 0
57 #endif
58
59 /*---------------------------------------------------------------------------
60  * Platform-dependent settings:
61  *-------------------------------------------------------------------------*/
62
63 /*---------------------------------------------------------------------------
64  * Include windows.h and friends:
65  *-------------------------------------------------------------------------*/
66
67 #if HAVE_WINDOWS_H
68 #include <windows.h>                    /* Misc. Windows hackery           */
69 #endif
70
71 #if HUGS_FOR_WINDOWS
72
73 #if     __MSDOS__
74 # define INT           int
75 # define UNSIGNED      unsigned
76 # define CHAR          char
77 # define TCHAR         char
78 # define UCHAR         UNSIGNED CHAR
79 # define ULONG         unsigned long
80 # define APIENTRY      PASCAL
81 # define HUGE          huge
82 # define LPOFNHOOKPROC FARPROC
83 # define CMDdata(w,l)  (HIWORD(l))      /* decoding WM_COMMAND message     */
84 # define CMDitem(w,l)  (w)
85 # define CMDhwnd(w,l)  ((HWND)(LOWORD(l)))
86 #else
87 # define HUGE
88 # define CMDdata(w,l)  (HIWORD(w))      /* decoding WM_COMMAND message     */
89 # define CMDitem(w,l)  (LOWORD(w))
90 # define CMDhwnd(w,l)  ((HWND)(l))
91 #endif
92
93 #include "win-menu.h"
94 extern char *appName;
95 extern HWND             hWndText;       /* text output window handle       */
96 extern HWND             hWndMain;       /* main window handle              */
97 #include "win-text.h"
98 #endif
99
100
101 /*---------------------------------------------------------------------------
102  * Macros used in declarations:
103  *  function prototypes
104  *  local/far declarations
105  *  HUGS_noreturn/HUGS_unused (prevent spurious warnings)
106  *  result type of main
107  *  dynamic linking declarations
108  *-------------------------------------------------------------------------*/
109
110 #if HAVE_PROTOTYPES       /* To enable use of prototypes whenever possible */
111 #define Args(x) x
112 #else
113 #define Args(x) ()
114 #endif
115
116 /* local = prefix for locally defined functions */
117 /* far   = prefix for far pointers              */
118 #if DOS
119 # define local near pascal
120 #else
121 # define local
122 # define far
123 #endif
124
125 #ifdef __GNUC__     /* Avoid spurious warnings                             */
126 #if __GNUC__ >= 2 && __GNUC_MINOR__ >= 7
127 #define HUGS_noreturn  __attribute__ ((noreturn))
128 #define HUGS_unused    __attribute__ ((unused))
129 #else
130 #define HUGS_noreturn  
131 #define HUGS_unused
132 #endif
133 #else
134 #define HUGS_noreturn  
135 #define HUGS_unused
136 #endif
137
138 /* result type of main function */
139 /* Hugs 1.01 could be configured to return void on Unix-like systems
140  * but I don't think this is necessary.  ADR
141  */
142 #define Main int
143 #define MainDone() return 0/*NOTUSED*/
144
145 /*---------------------------------------------------------------------------
146  * String operations:
147  *-------------------------------------------------------------------------*/
148
149 #if HAVE_STRING_H
150 # include <string.h>
151 #else
152 extern int      strcmp     Args((const char*, const char*));
153 extern int      strncmp    Args((const char*, const char*, int));
154 extern char     *strchr    Args((const char*, int));
155 extern char     *strrchr   Args((const char*, int));
156 extern size_t   strlen     Args((const char *));
157 extern char     *strcpy    Args((char *, const char*));
158 extern char     *strcat    Args((char *, const char*));
159 #endif
160 #if HAVE_STRCMP
161 #define strCompare strcmp
162 #else /* probably only used for DOS - ADR */
163 extern  int     stricmp    Args((const char *, const char*));
164 #define strCompare stricmp
165 #endif
166
167 #if HAVE_CTYPE_H
168 # include <ctype.h>
169 #endif
170 #ifndef isascii
171 #define  isascii(c)     (((unsigned)(c))<128)
172 #endif
173
174 /*---------------------------------------------------------------------------
175  * Memory allocation
176  *-------------------------------------------------------------------------*/
177
178 #if HAVE_FARCALLOC
179 # include <alloc.h>
180 # define farCalloc(n,s) farcalloc((unsigned long)n,(unsigned long)s)
181 #elif HAVE_VALLOC
182 # include <stdlib.h>
183 # include <malloc.h>
184 # define farCalloc(n,s) (Void *)valloc(((unsigned)n)*((unsigned)s))
185 #else
186 # define farCalloc(n,s) (Void *)calloc(((unsigned)n),((unsigned)s))
187 #endif
188
189 /* bison-generated parsers like to have alloca - so try to define it */
190 #if HAVE__ALLOCA
191 #include <malloc.h>
192 #ifndef alloca
193 #define alloca _alloca
194 #endif
195 #endif
196
197 /*---------------------------------------------------------------------------
198  * Interrupting execution (signals, allowBreak):
199  *-------------------------------------------------------------------------*/
200
201 #if !DOS && VOID_INT_SIGNALS
202 # define sigProto(nm)   void nm Args((int))
203 # define sigRaise(nm)   nm(1)
204 # define sigHandler(nm) void nm(sig_arg) int sig_arg;
205 # define sigResume      return
206 #else
207 # define sigProto(nm)   int nm Args((Void))
208 # define sigRaise(nm)   nm()
209 # define sigHandler(nm) int nm(Void)
210 # define sigResume      return 1
211 #endif
212
213 /*---------------------------------------------------------------------------
214  * Assertions
215  *-------------------------------------------------------------------------*/
216
217 #if HAVE_ASSERT_H
218 #include <assert.h>
219 #else
220 #define assert(x) doNothing()
221 #endif
222
223 /*---------------------------------------------------------------------------
224  * General settings:
225  *-------------------------------------------------------------------------*/
226
227 #define Void     void   /* older compilers object to: typedef void Void;   */
228 typedef unsigned Bool;
229 #define TRUE     1
230 #define FALSE    0
231 typedef char    *String;
232 typedef int      Int;
233 typedef long     Long;
234 typedef int      Char;
235 typedef unsigned int Word; /* at least 32 bits */
236 typedef void*    Ptr;
237 typedef void*    Addr;
238 typedef Word*    HpPtr;
239
240 /* ToDo: this should probably go in dynamic.h - but then
241  * storage.h has to include dynamic.h!
242  */
243 #if HAVE_DLFCN_H /* eg LINUX, SOLARIS, ULTRIX */
244 typedef void* ObjectFile; 
245 #elif HAVE_DL_H /* eg HPUX */
246 typedef shl_t ObjectFile;
247 #elif HAVE_WINDOWS_H && !defined(__MSDOS__)
248 typedef HINSTANCE ObjectFile;
249 #else
250 #warning GHC file loading not available on this machine
251 #endif
252
253 #define doNothing() do { } while (0) /* Null statement */
254
255 #ifndef STD_PRELUDE
256 #if     RISCOS
257 #define STD_PRELUDE        "prelude"
258 #else
259 #define STD_PRELUDE        "Prelude.hs"
260 #endif
261 #endif
262
263 #if DYN_TABLES                          /* Tables may be alloc'd at runtime*/
264 #define DECTABLE(tab)      far *tab     /* macros for declaration & defn   */
265 #define DEFTABLE(tab,sz)   far *tab = 0
266 #else                                   /* or at compile-time:             */
267 #define DECTABLE(tab)      tab[]
268 #define DEFTABLE(tab,sz)   tab[sz]
269 #endif
270
271 /*---------------------------------------------------------------------------
272  * Printf-related operations:
273  *-------------------------------------------------------------------------*/
274
275 #ifdef HAVE_STDARG_H
276 #include <stdarg.h>
277 #else
278 #include <varargs.h>
279 #endif
280
281 #if !defined(HAVE_SNPRINTF)
282 extern int snprintf   Args((char*, int, const char*, ...));
283 #endif
284
285 #if !defined(HAVE_VSNPRINTF)
286 extern int vsnprintf  Args((char*, int, const char*, va_list));
287 #endif
288
289 /*---------------------------------------------------------------------------
290  * Compiler output
291  * Tweaking this lets us redirect prompts, error messages, etc - but has no
292  * effect on output of Haskell programs (which should use hPutStr and friends).
293  *-------------------------------------------------------------------------*/
294
295 #if REDIRECT_OUTPUT
296
297 extern Void   hugsPrintf            Args((const char *, ...));
298 extern Void   hugsPutchar           Args((int));
299 extern Void   hugsFlushStdout       Args((Void));
300 extern Void   hugsEnableOutput      Args((Bool));
301 extern String hugsClearOutputBuffer Args((Void));
302                             
303 extern Void   hugsFFlush            Args((FILE*));
304 extern Void   hugsFPrintf           Args((FILE*, const char*, ...));
305 extern Void   hugsPutc              Args((int, FILE*));
306
307 #define Printf               hugsPrintf
308 #define Putchar              hugsPutchar
309 #define FlushStdout          hugsFlushStdout
310 #define EnableOutput         hugsEnableOutput
311 #define ClearOutputBuffer    hugsClearOutputBuffer
312
313 #define FFlush               hugsFFlush
314 #define FPrintf              hugsFPrintf
315 #define Putc                 hugsPutc
316                              
317 #else                        
318                              
319 #define Printf               printf
320 #define Putchar              putchar
321 #define FlushStdout()        fflush(stdout)
322 #define EnableOutput(f)      doNothing()
323 #define ClearOutputBuffer()  0
324
325 #define FFlush               fflush
326 #define FPrintf              fprintf
327 #define Putc                 putc
328
329 #endif
330
331 /*-------------------------------------------------------------------------*/