787e1ae084f26c00514f15da3d6cac345128ffe1
[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.11 $
14  * $Date: 2000/03/22 18:14:23 $
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
77 /*---------------------------------------------------------------------------
78  * Macros used in declarations:
79  *  function prototypes
80  *  local/far declarations
81  *  HUGS_noreturn/HUGS_unused (prevent spurious warnings)
82  *  result type of main
83  *  dynamic linking declarations
84  *-------------------------------------------------------------------------*/
85
86 /* local = prefix for locally defined functions */
87 /* far   = prefix for far pointers              */
88 #if DOS
89 # define local near pascal
90 #else
91 # define local
92 # define far
93 #endif
94
95 #ifdef __GNUC__     /* Avoid spurious warnings                             */
96 #if __GNUC__ >= 2 && __GNUC_MINOR__ >= 7
97 #define HUGS_noreturn  __attribute__ ((noreturn))
98 #define HUGS_unused    __attribute__ ((unused))
99 #else
100 #define HUGS_noreturn  
101 #define HUGS_unused
102 #endif
103 #else
104 #define HUGS_noreturn  
105 #define HUGS_unused
106 #endif
107
108 /* result type of main function */
109 /* Hugs 1.01 could be configured to return void on Unix-like systems
110  * but I don't think this is necessary.  ADR
111  */
112 #define Main int
113 #define MainDone() return 0/*NOTUSED*/
114
115 /*---------------------------------------------------------------------------
116  * String operations:
117  *-------------------------------------------------------------------------*/
118
119 #if HAVE_STRING_H
120 # include <string.h>
121 #else
122 extern int      strcmp     Args((const char*, const char*));
123 extern int      strncmp    Args((const char*, const char*, int));
124 extern char     *strchr    Args((const char*, int));
125 extern char     *strrchr   Args((const char*, int));
126 extern size_t   strlen     Args((const char *));
127 extern char     *strcpy    Args((char *, const char*));
128 extern char     *strcat    Args((char *, const char*));
129 #endif
130 #if HAVE_STRCMP
131 #define strCompare strcmp
132 #else /* probably only used for DOS - ADR */
133 extern  int     stricmp    Args((const char *, const char*));
134 #define strCompare stricmp
135 #endif
136
137 #if HAVE_CTYPE_H
138 # include <ctype.h>
139 #endif
140 #ifndef isascii
141 #define  isascii(c)     (((unsigned)(c))<128)
142 #endif
143
144 /*---------------------------------------------------------------------------
145  * Memory allocation
146  *-------------------------------------------------------------------------*/
147
148 #if HAVE_FARCALLOC
149 # include <alloc.h>
150 # define farCalloc(n,s) farcalloc((unsigned long)n,(unsigned long)s)
151 #elif HAVE_VALLOC
152 # include <stdlib.h>
153 # include <malloc.h>
154 # define farCalloc(n,s) (Void *)valloc(((unsigned)n)*((unsigned)s))
155 #else
156 # define farCalloc(n,s) (Void *)calloc(((unsigned)n),((unsigned)s))
157 #endif
158
159 /* bison-generated parsers like to have alloca - so try to define it */
160 #if HAVE__ALLOCA
161 #include <malloc.h>
162 #ifndef alloca
163 #define alloca _alloca
164 #endif
165 #endif
166
167 /*---------------------------------------------------------------------------
168  * Interrupting execution (signals, allowBreak):
169  *-------------------------------------------------------------------------*/
170
171 #if !DOS && VOID_INT_SIGNALS
172 # define sigProto(nm)   void nm ( int )
173 # define sigRaise(nm)   nm(1)
174 # define sigHandler(nm) void nm ( sig_arg ) int sig_arg;
175 # define sigResume      return
176 #else
177 # define sigProto(nm)   int nm ( Void )
178 # define sigRaise(nm)   nm()
179 # define sigHandler(nm) int nm ( Void )
180 # define sigResume      return 1
181 #endif
182
183 /*---------------------------------------------------------------------------
184  * Assertions
185  *-------------------------------------------------------------------------*/
186
187 #if HAVE_ASSERT_H
188 #include <assert.h>
189 #else
190 #define assert(x) doNothing()
191 #endif
192
193 /*---------------------------------------------------------------------------
194  * General settings:
195  *-------------------------------------------------------------------------*/
196
197 #define Void     void   /* older compilers object to: typedef void Void;   */
198 typedef unsigned Bool;
199 #define TRUE     1
200 #define FALSE    0
201
202 typedef char           *String;
203 typedef int             Int;
204 typedef long            Long;
205 typedef int             Char;
206 typedef unsigned int    Unsigned; /* at least 32 bits */
207 typedef void*           Ptr;
208 typedef void*           Addr;
209 typedef void*           HpPtr;
210
211 #define FloatImpType       double
212 #define FloatPro           double
213 #define FloatFMT           "%.9g"
214
215
216 /* ToDo: this should probably go in dynamic.h - but then
217  * storage.h has to include dynamic.h!
218  */
219 #if HAVE_WINDOWS_H && !defined(__MSDOS__)
220 typedef HINSTANCE ObjectFile;
221 #elif HAVE_DLFCN_H /* eg LINUX, SOLARIS, ULTRIX */
222 typedef void* ObjectFile; 
223 #elif HAVE_DL_H /* eg HPUX */
224 typedef shl_t ObjectFile;
225 #else
226 #warning GHC file loading not available on this machine
227 #endif
228
229 #define doNothing() do { } while (0) /* Null statement */
230
231 #ifndef STD_PRELUDE
232 #if     RISCOS
233 #define STD_PRELUDE        "prelude"
234 #else
235 #define STD_PRELUDE        "Prelude.hs"
236 #endif
237 #endif
238
239 /*---------------------------------------------------------------------------
240  * Printf-related operations:
241  *-------------------------------------------------------------------------*/
242
243 #ifdef HAVE_STDARG_H
244 #include <stdarg.h>
245 #else
246 #include <varargs.h>
247 #endif
248
249 #if !defined(HAVE_SNPRINTF)
250 extern int snprintf ( char*, int, const char*, ... );
251 #endif
252
253 #if !defined(HAVE_VSNPRINTF)
254 extern int vsnprintf ( char*, int, const char*, va_list );
255 #endif
256
257 /*---------------------------------------------------------------------------
258  * Compiler output
259  * Tweaking this lets us redirect prompts, error messages, etc - but has no
260  * effect on output of Haskell programs (which should use hPutStr and friends).
261  *-------------------------------------------------------------------------*/
262                              
263 #define Printf               printf
264 #define Putchar              putchar
265 #define FlushStdout()        fflush(stdout)
266 #define EnableOutput(f)      doNothing()
267 #define ClearOutputBuffer()  0
268
269 #define FFlush               fflush
270 #define FPrintf              fprintf
271 #define Putc                 putc
272
273 /*-------------------------------------------------------------------------*/