2 /* --------------------------------------------------------------------------
3 * Basic data type definitions, prototypes and standard macros including
4 * machine dependent variations...
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
10 * $RCSfile: prelude.h,v $
12 * $Date: 1999/02/03 17:08:36 $
13 * ------------------------------------------------------------------------*/
19 /*---------------------------------------------------------------------------
20 * Most of the configuration code from earlier versions of Hugs has been moved
21 * into config.h (which is usually automatically generated).
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.
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 *-------------------------------------------------------------------------*/
35 #ifdef __RISCOS__ /* Acorn DesktopC running RISCOS2 or 3 */
41 #if defined __DJGPP__ && __DJGPP__==2
47 #if defined __MSDOS__ && __MSDOS__ && !DJGPP2
53 #if defined _WIN32 | defined __WIN32__
59 /*---------------------------------------------------------------------------
60 * Platform-dependent settings:
61 *-------------------------------------------------------------------------*/
63 /*---------------------------------------------------------------------------
64 * Include windows.h and friends:
65 *-------------------------------------------------------------------------*/
68 #include <windows.h> /* Misc. Windows hackery */
75 # define UNSIGNED unsigned
78 # define UCHAR UNSIGNED CHAR
79 # define ULONG unsigned long
80 # define APIENTRY PASCAL
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)))
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))
95 extern HWND hWndText; /* text output window handle */
96 extern HWND hWndMain; /* main window handle */
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 *-------------------------------------------------------------------------*/
110 #if HAVE_PROTOTYPES /* To enable use of prototypes whenever possible */
116 /* local = prefix for locally defined functions */
117 /* far = prefix for far pointers */
119 # define local near pascal
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))
130 #define HUGS_noreturn
134 #define HUGS_noreturn
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
143 #define MainDone() return 0/*NOTUSED*/
145 /*---------------------------------------------------------------------------
147 *-------------------------------------------------------------------------*/
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*));
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
171 #define isascii(c) (((unsigned)(c))<128)
174 /*---------------------------------------------------------------------------
176 *-------------------------------------------------------------------------*/
180 # define farCalloc(n,s) farcalloc((unsigned long)n,(unsigned long)s)
184 # define farCalloc(n,s) (Void *)valloc(((unsigned)n)*((unsigned)s))
186 # define farCalloc(n,s) (Void *)calloc(((unsigned)n),((unsigned)s))
189 /* bison-generated parsers like to have alloca - so try to define it */
193 #define alloca _alloca
197 /*---------------------------------------------------------------------------
198 * Interrupting execution (signals, allowBreak):
199 *-------------------------------------------------------------------------*/
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
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
213 /*---------------------------------------------------------------------------
215 *-------------------------------------------------------------------------*/
220 #define assert(x) doNothing()
223 /*---------------------------------------------------------------------------
225 *-------------------------------------------------------------------------*/
227 #define Void void /* older compilers object to: typedef void Void; */
228 typedef unsigned Bool;
232 typedef char *String;
236 typedef unsigned int Unsigned; /* at least 32 bits */
241 #define FloatImpType double
242 #define FloatPro double
243 #define FloatFMT "%.9g"
246 /* ToDo: this should probably go in dynamic.h - but then
247 * storage.h has to include dynamic.h!
249 #if HAVE_DLFCN_H /* eg LINUX, SOLARIS, ULTRIX */
250 typedef void* ObjectFile;
251 #elif HAVE_DL_H /* eg HPUX */
252 typedef shl_t ObjectFile;
253 #elif HAVE_WINDOWS_H && !defined(__MSDOS__)
254 typedef HINSTANCE ObjectFile;
256 #warning GHC file loading not available on this machine
259 #define doNothing() do { } while (0) /* Null statement */
263 #define STD_PRELUDE "prelude"
265 #define STD_PRELUDE "Prelude.hs"
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]
277 /*---------------------------------------------------------------------------
278 * Printf-related operations:
279 *-------------------------------------------------------------------------*/
287 #if !defined(HAVE_SNPRINTF)
288 extern int snprintf Args((char*, int, const char*, ...));
291 #if !defined(HAVE_VSNPRINTF)
292 extern int vsnprintf Args((char*, int, const char*, va_list));
295 /*---------------------------------------------------------------------------
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 *-------------------------------------------------------------------------*/
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));
309 extern Void hugsFFlush Args((FILE*));
310 extern Void hugsFPrintf Args((FILE*, const char*, ...));
311 extern Void hugsPutc Args((int, FILE*));
313 #define Printf hugsPrintf
314 #define Putchar hugsPutchar
315 #define FlushStdout hugsFlushStdout
316 #define EnableOutput hugsEnableOutput
317 #define ClearOutputBuffer hugsClearOutputBuffer
319 #define FFlush hugsFFlush
320 #define FPrintf hugsFPrintf
321 #define Putc hugsPutc
325 #define Printf printf
326 #define Putchar putchar
327 #define FlushStdout() fflush(stdout)
328 #define EnableOutput(f) doNothing()
329 #define ClearOutputBuffer() 0
331 #define FFlush fflush
332 #define FPrintf fprintf
337 /*-------------------------------------------------------------------------*/