2 /* --------------------------------------------------------------------------
3 * Basic data type definitions, prototypes and standard macros including
4 * machine dependent variations...
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.
12 * $RCSfile: prelude.h,v $
14 * $Date: 2000/03/13 11:37:16 $
15 * ------------------------------------------------------------------------*/
17 #define NON_POSIX_SOURCE
18 /* AJG: machdep.h needs this, for S_IREAD and S_IFREG in cygwin? */
24 /*---------------------------------------------------------------------------
25 * Most of the configuration code from earlier versions of Hugs has been moved
26 * into config.h (which is usually automatically generated).
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.
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 *-------------------------------------------------------------------------*/
40 #ifdef __RISCOS__ /* Acorn DesktopC running RISCOS2 or 3 */
46 #if defined __DJGPP__ && __DJGPP__==2
52 #if defined __MSDOS__ && __MSDOS__ && !DJGPP2
58 #if defined _WIN32 | defined __WIN32__
64 /*---------------------------------------------------------------------------
65 * Platform-dependent settings:
66 *-------------------------------------------------------------------------*/
68 /*---------------------------------------------------------------------------
69 * Include windows.h and friends:
70 *-------------------------------------------------------------------------*/
73 #include <windows.h> /* Misc. Windows hackery */
80 # define UNSIGNED unsigned
83 # define UCHAR UNSIGNED CHAR
84 # define ULONG unsigned long
85 # define APIENTRY PASCAL
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)))
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))
100 extern HWND hWndText; /* text output window handle */
101 extern HWND hWndMain; /* main window handle */
102 #include "win-text.h"
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 *-------------------------------------------------------------------------*/
115 /* local = prefix for locally defined functions */
116 /* far = prefix for far pointers */
118 # define local near pascal
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))
129 #define HUGS_noreturn
133 #define HUGS_noreturn
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
142 #define MainDone() return 0/*NOTUSED*/
144 /*---------------------------------------------------------------------------
146 *-------------------------------------------------------------------------*/
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*));
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
170 #define isascii(c) (((unsigned)(c))<128)
173 /*---------------------------------------------------------------------------
175 *-------------------------------------------------------------------------*/
179 # define farCalloc(n,s) farcalloc((unsigned long)n,(unsigned long)s)
183 # define farCalloc(n,s) (Void *)valloc(((unsigned)n)*((unsigned)s))
185 # define farCalloc(n,s) (Void *)calloc(((unsigned)n),((unsigned)s))
188 /* bison-generated parsers like to have alloca - so try to define it */
192 #define alloca _alloca
196 /*---------------------------------------------------------------------------
197 * Interrupting execution (signals, allowBreak):
198 *-------------------------------------------------------------------------*/
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
206 # define sigProto(nm) int nm ( Void )
207 # define sigRaise(nm) nm()
208 # define sigHandler(nm) int nm ( Void )
209 # define sigResume return 1
212 /*---------------------------------------------------------------------------
214 *-------------------------------------------------------------------------*/
219 #define assert(x) doNothing()
222 /*---------------------------------------------------------------------------
224 *-------------------------------------------------------------------------*/
226 #define Void void /* older compilers object to: typedef void Void; */
227 typedef unsigned Bool;
231 typedef char *String;
235 typedef unsigned int Unsigned; /* at least 32 bits */
240 #define FloatImpType double
241 #define FloatPro double
242 #define FloatFMT "%.9g"
245 /* ToDo: this should probably go in dynamic.h - but then
246 * storage.h has to include dynamic.h!
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;
255 #warning GHC file loading not available on this machine
258 #define doNothing() do { } while (0) /* Null statement */
262 #define STD_PRELUDE "prelude"
264 #define STD_PRELUDE "Prelude.hs"
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]
276 /*---------------------------------------------------------------------------
277 * Printf-related operations:
278 *-------------------------------------------------------------------------*/
286 #if !defined(HAVE_SNPRINTF)
287 extern int snprintf Args((char*, int, const char*, ...));
290 #if !defined(HAVE_VSNPRINTF)
291 extern int vsnprintf Args((char*, int, const char*, va_list));
294 /*---------------------------------------------------------------------------
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 *-------------------------------------------------------------------------*/
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 );
308 extern Void hugsFFlush ( FILE* );
309 extern Void hugsFPrintf ( FILE*, const char*, ... );
310 extern Void hugsPutc ( int, FILE* );
312 #define Printf hugsPrintf
313 #define Putchar hugsPutchar
314 #define FlushStdout hugsFlushStdout
315 #define EnableOutput hugsEnableOutput
316 #define ClearOutputBuffer hugsClearOutputBuffer
318 #define FFlush hugsFFlush
319 #define FPrintf hugsFPrintf
320 #define Putc hugsPutc
324 #define Printf printf
325 #define Putchar putchar
326 #define FlushStdout() fflush(stdout)
327 #define EnableOutput(f) doNothing()
328 #define ClearOutputBuffer() 0
330 #define FFlush fflush
331 #define FPrintf fprintf
336 /*-------------------------------------------------------------------------*/