1 /* -*- mode: hugs-c; -*- */
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: 1998/12/02 13:22:33 $
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;
231 typedef char *String;
235 typedef unsigned int Word; /* at least 32 bits */
240 /* ToDo: this should probably go in dynamic.h - but then
241 * storage.h has to include dynamic.h!
243 #if HAVE_DLFCN_H /* eg LINUX, SOLARIS, ULTRIX */
244 typedef void* ObjectFile;
245 #elif HAVE_DL_H /* eg HPUX */
246 typedef shl_t ObjectFile;
247 #elif HAVE_WINDOWS_H && !defined(__MSDOS__)
248 typedef HINSTANCE ObjectFile;
250 #warning GHC file loading not available on this machine
253 #define doNothing() do { } while (0) /* Null statement */
257 #define STD_PRELUDE "prelude"
259 #define STD_PRELUDE "Prelude.hs"
263 #if DYN_TABLES /* Tables may be alloc'd at runtime*/
264 #define DECTABLE(tab) far *tab /* macros for declaration & defn */
265 #define DEFTABLE(tab,sz) far *tab = 0
266 #else /* or at compile-time: */
267 #define DECTABLE(tab) tab[]
268 #define DEFTABLE(tab,sz) tab[sz]
271 /*---------------------------------------------------------------------------
272 * Printf-related operations:
273 *-------------------------------------------------------------------------*/
281 #if !defined(HAVE_SNPRINTF)
282 extern int snprintf Args((char*, int, const char*, ...));
285 #if !defined(HAVE_VSNPRINTF)
286 extern int vsnprintf Args((char*, int, const char*, va_list));
289 /*---------------------------------------------------------------------------
291 * Tweaking this lets us redirect prompts, error messages, etc - but has no
292 * effect on output of Haskell programs (which should use hPutStr and friends).
293 *-------------------------------------------------------------------------*/
297 extern Void hugsPrintf Args((const char *, ...));
298 extern Void hugsPutchar Args((int));
299 extern Void hugsFlushStdout Args((Void));
300 extern Void hugsEnableOutput Args((Bool));
301 extern String hugsClearOutputBuffer Args((Void));
303 extern Void hugsFFlush Args((FILE*));
304 extern Void hugsFPrintf Args((FILE*, const char*, ...));
305 extern Void hugsPutc Args((int, FILE*));
307 #define Printf hugsPrintf
308 #define Putchar hugsPutchar
309 #define FlushStdout hugsFlushStdout
310 #define EnableOutput hugsEnableOutput
311 #define ClearOutputBuffer hugsClearOutputBuffer
313 #define FFlush hugsFFlush
314 #define FPrintf hugsFPrintf
315 #define Putc hugsPutc
319 #define Printf printf
320 #define Putchar putchar
321 #define FlushStdout() fflush(stdout)
322 #define EnableOutput(f) doNothing()
323 #define ClearOutputBuffer() 0
325 #define FFlush fflush
326 #define FPrintf fprintf
331 /*-------------------------------------------------------------------------*/