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