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: 1999/10/20 02:16:04 $
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 #if HAVE_PROTOTYPES /* To enable use of prototypes whenever possible */
121 /* local = prefix for locally defined functions */
122 /* far = prefix for far pointers */
124 # define local near pascal
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))
135 #define HUGS_noreturn
139 #define HUGS_noreturn
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
148 #define MainDone() return 0/*NOTUSED*/
150 /*---------------------------------------------------------------------------
152 *-------------------------------------------------------------------------*/
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*));
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
176 #define isascii(c) (((unsigned)(c))<128)
179 /*---------------------------------------------------------------------------
181 *-------------------------------------------------------------------------*/
185 # define farCalloc(n,s) farcalloc((unsigned long)n,(unsigned long)s)
189 # define farCalloc(n,s) (Void *)valloc(((unsigned)n)*((unsigned)s))
191 # define farCalloc(n,s) (Void *)calloc(((unsigned)n),((unsigned)s))
194 /* bison-generated parsers like to have alloca - so try to define it */
198 #define alloca _alloca
202 /*---------------------------------------------------------------------------
203 * Interrupting execution (signals, allowBreak):
204 *-------------------------------------------------------------------------*/
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
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
218 /*---------------------------------------------------------------------------
220 *-------------------------------------------------------------------------*/
225 #define assert(x) doNothing()
228 /*---------------------------------------------------------------------------
230 *-------------------------------------------------------------------------*/
232 #define Void void /* older compilers object to: typedef void Void; */
233 typedef unsigned Bool;
237 typedef char *String;
241 typedef unsigned int Unsigned; /* at least 32 bits */
246 #define FloatImpType double
247 #define FloatPro double
248 #define FloatFMT "%.9g"
251 /* ToDo: this should probably go in dynamic.h - but then
252 * storage.h has to include dynamic.h!
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;
261 #warning GHC file loading not available on this machine
264 #define doNothing() do { } while (0) /* Null statement */
268 #define STD_PRELUDE "prelude"
270 #define STD_PRELUDE "Prelude.hs"
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]
282 /*---------------------------------------------------------------------------
283 * Printf-related operations:
284 *-------------------------------------------------------------------------*/
292 #if !defined(HAVE_SNPRINTF)
293 extern int snprintf Args((char*, int, const char*, ...));
296 #if !defined(HAVE_VSNPRINTF)
297 extern int vsnprintf Args((char*, int, const char*, va_list));
300 /*---------------------------------------------------------------------------
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 *-------------------------------------------------------------------------*/
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));
314 extern Void hugsFFlush Args((FILE*));
315 extern Void hugsFPrintf Args((FILE*, const char*, ...));
316 extern Void hugsPutc Args((int, FILE*));
318 #define Printf hugsPrintf
319 #define Putchar hugsPutchar
320 #define FlushStdout hugsFlushStdout
321 #define EnableOutput hugsEnableOutput
322 #define ClearOutputBuffer hugsClearOutputBuffer
324 #define FFlush hugsFFlush
325 #define FPrintf hugsFPrintf
326 #define Putc hugsPutc
330 #define Printf printf
331 #define Putchar putchar
332 #define FlushStdout() fflush(stdout)
333 #define EnableOutput(f) doNothing()
334 #define ClearOutputBuffer() 0
336 #define FFlush fflush
337 #define FPrintf fprintf
342 /*-------------------------------------------------------------------------*/
343 /* AJG: This needs moved to a more appropreate location
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.
353 /*-------------------------------------------------------------------------*/