[project @ 1999-10-15 19:11:54 by andy]
[ghc-hetmet.git] / ghc / interpreter / prelude.h
1
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.4 $
12  * $Date: 1999/10/15 19:11:55 $
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
232 typedef char           *String;
233 typedef int             Int;
234 typedef long            Long;
235 typedef int             Char;
236 typedef unsigned int    Unsigned; /* at least 32 bits */
237 typedef void*           Ptr;
238 typedef void*           Addr;
239 typedef void*           HpPtr;
240
241 #define FloatImpType       double
242 #define FloatPro           double
243 #define FloatFMT           "%.9g"
244
245
246 /* ToDo: this should probably go in dynamic.h - but then
247  * storage.h has to include dynamic.h!
248  */
249 #if HAVE_WINDOWS_H && !defined(__MSDOS__)
250 typedef HINSTANCE ObjectFile;
251 #elif HAVE_DLFCN_H /* eg LINUX, SOLARIS, ULTRIX */
252 typedef void* ObjectFile; 
253 #elif HAVE_DL_H /* eg HPUX */
254 typedef shl_t ObjectFile;
255 #else
256 #warning GHC file loading not available on this machine
257 #endif
258
259 #define doNothing() do { } while (0) /* Null statement */
260
261 #ifndef STD_PRELUDE
262 #if     RISCOS
263 #define STD_PRELUDE        "prelude"
264 #else
265 #define STD_PRELUDE        "Prelude.hs"
266 #endif
267 #endif
268
269 #if DYN_TABLES                          /* Tables may be alloc'd at runtime*/
270 #define DECTABLE(tab)      far *tab     /* macros for declaration & defn   */
271 #define DEFTABLE(tab,sz)   far *tab = 0
272 #else                                   /* or at compile-time:             */
273 #define DECTABLE(tab)      tab[]
274 #define DEFTABLE(tab,sz)   tab[sz]
275 #endif
276
277 /*---------------------------------------------------------------------------
278  * Printf-related operations:
279  *-------------------------------------------------------------------------*/
280
281 #ifdef HAVE_STDARG_H
282 #include <stdarg.h>
283 #else
284 #include <varargs.h>
285 #endif
286
287 #if !defined(HAVE_SNPRINTF)
288 extern int snprintf   Args((char*, int, const char*, ...));
289 #endif
290
291 #if !defined(HAVE_VSNPRINTF)
292 extern int vsnprintf  Args((char*, int, const char*, va_list));
293 #endif
294
295 /*---------------------------------------------------------------------------
296  * Compiler output
297  * Tweaking this lets us redirect prompts, error messages, etc - but has no
298  * effect on output of Haskell programs (which should use hPutStr and friends).
299  *-------------------------------------------------------------------------*/
300
301 #if REDIRECT_OUTPUT
302
303 extern Void   hugsPrintf            Args((const char *, ...));
304 extern Void   hugsPutchar           Args((int));
305 extern Void   hugsFlushStdout       Args((Void));
306 extern Void   hugsEnableOutput      Args((Bool));
307 extern String hugsClearOutputBuffer Args((Void));
308                             
309 extern Void   hugsFFlush            Args((FILE*));
310 extern Void   hugsFPrintf           Args((FILE*, const char*, ...));
311 extern Void   hugsPutc              Args((int, FILE*));
312
313 #define Printf               hugsPrintf
314 #define Putchar              hugsPutchar
315 #define FlushStdout          hugsFlushStdout
316 #define EnableOutput         hugsEnableOutput
317 #define ClearOutputBuffer    hugsClearOutputBuffer
318
319 #define FFlush               hugsFFlush
320 #define FPrintf              hugsFPrintf
321 #define Putc                 hugsPutc
322                              
323 #else                        
324                              
325 #define Printf               printf
326 #define Putchar              putchar
327 #define FlushStdout()        fflush(stdout)
328 #define EnableOutput(f)      doNothing()
329 #define ClearOutputBuffer()  0
330
331 #define FFlush               fflush
332 #define FPrintf              fprintf
333 #define Putc                 putc
334
335 #endif
336
337 /*-------------------------------------------------------------------------*/