[project @ 2000-03-13 14:10:24 by sewardj]
[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.10 $
14  * $Date: 2000/03/13 14:10:24 $
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 /* local = prefix for locally defined functions */
116 /* far   = prefix for far pointers              */
117 #if DOS
118 # define local near pascal
119 #else
120 # define local
121 # define far
122 #endif
123
124 #ifdef __GNUC__     /* Avoid spurious warnings                             */
125 #if __GNUC__ >= 2 && __GNUC_MINOR__ >= 7
126 #define HUGS_noreturn  __attribute__ ((noreturn))
127 #define HUGS_unused    __attribute__ ((unused))
128 #else
129 #define HUGS_noreturn  
130 #define HUGS_unused
131 #endif
132 #else
133 #define HUGS_noreturn  
134 #define HUGS_unused
135 #endif
136
137 /* result type of main function */
138 /* Hugs 1.01 could be configured to return void on Unix-like systems
139  * but I don't think this is necessary.  ADR
140  */
141 #define Main int
142 #define MainDone() return 0/*NOTUSED*/
143
144 /*---------------------------------------------------------------------------
145  * String operations:
146  *-------------------------------------------------------------------------*/
147
148 #if HAVE_STRING_H
149 # include <string.h>
150 #else
151 extern int      strcmp     Args((const char*, const char*));
152 extern int      strncmp    Args((const char*, const char*, int));
153 extern char     *strchr    Args((const char*, int));
154 extern char     *strrchr   Args((const char*, int));
155 extern size_t   strlen     Args((const char *));
156 extern char     *strcpy    Args((char *, const char*));
157 extern char     *strcat    Args((char *, const char*));
158 #endif
159 #if HAVE_STRCMP
160 #define strCompare strcmp
161 #else /* probably only used for DOS - ADR */
162 extern  int     stricmp    Args((const char *, const char*));
163 #define strCompare stricmp
164 #endif
165
166 #if HAVE_CTYPE_H
167 # include <ctype.h>
168 #endif
169 #ifndef isascii
170 #define  isascii(c)     (((unsigned)(c))<128)
171 #endif
172
173 /*---------------------------------------------------------------------------
174  * Memory allocation
175  *-------------------------------------------------------------------------*/
176
177 #if HAVE_FARCALLOC
178 # include <alloc.h>
179 # define farCalloc(n,s) farcalloc((unsigned long)n,(unsigned long)s)
180 #elif HAVE_VALLOC
181 # include <stdlib.h>
182 # include <malloc.h>
183 # define farCalloc(n,s) (Void *)valloc(((unsigned)n)*((unsigned)s))
184 #else
185 # define farCalloc(n,s) (Void *)calloc(((unsigned)n),((unsigned)s))
186 #endif
187
188 /* bison-generated parsers like to have alloca - so try to define it */
189 #if HAVE__ALLOCA
190 #include <malloc.h>
191 #ifndef alloca
192 #define alloca _alloca
193 #endif
194 #endif
195
196 /*---------------------------------------------------------------------------
197  * Interrupting execution (signals, allowBreak):
198  *-------------------------------------------------------------------------*/
199
200 #if !DOS && VOID_INT_SIGNALS
201 # define sigProto(nm)   void nm ( int )
202 # define sigRaise(nm)   nm(1)
203 # define sigHandler(nm) void nm ( sig_arg ) int sig_arg;
204 # define sigResume      return
205 #else
206 # define sigProto(nm)   int nm ( Void )
207 # define sigRaise(nm)   nm()
208 # define sigHandler(nm) int nm ( Void )
209 # define sigResume      return 1
210 #endif
211
212 /*---------------------------------------------------------------------------
213  * Assertions
214  *-------------------------------------------------------------------------*/
215
216 #if HAVE_ASSERT_H
217 #include <assert.h>
218 #else
219 #define assert(x) doNothing()
220 #endif
221
222 /*---------------------------------------------------------------------------
223  * General settings:
224  *-------------------------------------------------------------------------*/
225
226 #define Void     void   /* older compilers object to: typedef void Void;   */
227 typedef unsigned Bool;
228 #define TRUE     1
229 #define FALSE    0
230
231 typedef char           *String;
232 typedef int             Int;
233 typedef long            Long;
234 typedef int             Char;
235 typedef unsigned int    Unsigned; /* at least 32 bits */
236 typedef void*           Ptr;
237 typedef void*           Addr;
238 typedef void*           HpPtr;
239
240 #define FloatImpType       double
241 #define FloatPro           double
242 #define FloatFMT           "%.9g"
243
244
245 /* ToDo: this should probably go in dynamic.h - but then
246  * storage.h has to include dynamic.h!
247  */
248 #if HAVE_WINDOWS_H && !defined(__MSDOS__)
249 typedef HINSTANCE ObjectFile;
250 #elif HAVE_DLFCN_H /* eg LINUX, SOLARIS, ULTRIX */
251 typedef void* ObjectFile; 
252 #elif HAVE_DL_H /* eg HPUX */
253 typedef shl_t ObjectFile;
254 #else
255 #warning GHC file loading not available on this machine
256 #endif
257
258 #define doNothing() do { } while (0) /* Null statement */
259
260 #ifndef STD_PRELUDE
261 #if     RISCOS
262 #define STD_PRELUDE        "prelude"
263 #else
264 #define STD_PRELUDE        "Prelude.hs"
265 #endif
266 #endif
267
268 #if DYN_TABLES                          /* Tables may be alloc'd at runtime*/
269 #define DECTABLE(tab)      far *tab     /* macros for declaration & defn   */
270 #define DEFTABLE(tab,sz)   far *tab = 0
271 #else                                   /* or at compile-time:             */
272 #define DECTABLE(tab)      tab[]
273 #define DEFTABLE(tab,sz)   tab[sz]
274 #endif
275
276 /*---------------------------------------------------------------------------
277  * Printf-related operations:
278  *-------------------------------------------------------------------------*/
279
280 #ifdef HAVE_STDARG_H
281 #include <stdarg.h>
282 #else
283 #include <varargs.h>
284 #endif
285
286 #if !defined(HAVE_SNPRINTF)
287 extern int snprintf   ( char*, int, const char*, ... );
288 #endif
289
290 #if !defined(HAVE_VSNPRINTF)
291 extern int vsnprintf  ( char*, int, const char*, va_list );
292 #endif
293
294 /*---------------------------------------------------------------------------
295  * Compiler output
296  * Tweaking this lets us redirect prompts, error messages, etc - but has no
297  * effect on output of Haskell programs (which should use hPutStr and friends).
298  *-------------------------------------------------------------------------*/
299
300 #if REDIRECT_OUTPUT
301
302 extern Void   hugsPrintf            ( const char *, ... );
303 extern Void   hugsPutchar           ( int );
304 extern Void   hugsFlushStdout       ( Void );
305 extern Void   hugsEnableOutput      ( Bool );
306 extern String hugsClearOutputBuffer ( Void );
307                             
308 extern Void   hugsFFlush            ( FILE* );
309 extern Void   hugsFPrintf           ( FILE*, const char*, ... );
310 extern Void   hugsPutc              ( int, FILE* );
311
312 #define Printf               hugsPrintf
313 #define Putchar              hugsPutchar
314 #define FlushStdout          hugsFlushStdout
315 #define EnableOutput         hugsEnableOutput
316 #define ClearOutputBuffer    hugsClearOutputBuffer
317
318 #define FFlush               hugsFFlush
319 #define FPrintf              hugsFPrintf
320 #define Putc                 hugsPutc
321                              
322 #else                        
323                              
324 #define Printf               printf
325 #define Putchar              putchar
326 #define FlushStdout()        fflush(stdout)
327 #define EnableOutput(f)      doNothing()
328 #define ClearOutputBuffer()  0
329
330 #define FFlush               fflush
331 #define FPrintf              fprintf
332 #define Putc                 putc
333
334 #endif
335
336 /*-------------------------------------------------------------------------*/