replace sparc-specific Int64 code with calls to platform-independent macros
[ghc-hetmet.git] / includes / stg / Types.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2004
4  *
5  * Various C datatypes used in the run-time system.  This is the
6  * lowest-level include file, after ghcconfig.h and RtsConfig.h.
7  *
8  * This module should define types *only*, all beginning with "Stg".
9  *
10  * Specifically:
11
12         StgInt8,  16, 32, 64
13         StgWord8, 16, 32, 64
14         StgChar, StgFloat, StgDouble
15
16         ***** All the same size (i.e. sizeof(void *)): *****
17         StgPtr                  Basic pointer type
18         StgWord                 Unit of heap allocation
19         StgInt                  Signed version of StgWord
20         StgAddr                 Generic address type
21         
22         StgBool, StgVoid, StgPtr, StgOffset, 
23         StgCode, StgStablePtr, StgFunPtr,
24         StgUnion.
25
26  * WARNING: Keep this file, MachDeps.h, and HsFFI.h in synch!
27  *
28  * NOTE: assumes #include "ghcconfig.h"
29  * 
30  * Works with or without _POSIX_SOURCE.
31  *
32  * ---------------------------------------------------------------------------*/
33
34 #ifndef STGTYPES_H
35 #define STGTYPES_H
36
37 /*
38  * First, platform-dependent definitions of size-specific integers.
39  * Assume for now that the int type is 32 bits.
40  * NOTE: Synch the following definitions with MachDeps.h!
41  * ToDo: move these into a platform-dependent file.
42  */
43
44 typedef signed   char            StgInt8;
45 typedef unsigned char            StgWord8;
46
47 typedef signed   short           StgInt16;
48 typedef unsigned short           StgWord16;
49
50 #if SIZEOF_LONG == 4
51 typedef signed   long            StgInt32;
52 typedef unsigned long            StgWord32;
53 #elif SIZEOF_INT == 4
54 typedef signed   int             StgInt32;
55 typedef unsigned int             StgWord32;
56 #else
57 #error GHC untested on this architecture: sizeof(int) != 4
58 #endif
59
60 #if SIZEOF_LONG == 8
61 typedef signed   long          StgInt64;
62 typedef unsigned long          StgWord64;
63 #elif defined(__MSVC__)
64 typedef __int64                StgInt64;
65 typedef unsigned __int64       StgWord64;
66 #elif SIZEOF_LONG_LONG == 8
67 typedef signed long long int   StgInt64;
68 typedef unsigned long long int StgWord64;
69 #else
70 #error cannot find a way to define StgInt64
71 #endif
72
73 /*
74  * Define the standard word size we'll use on this machine: make it
75  * big enough to hold a pointer.
76  *
77  * It's useful if StgInt/StgWord are always the same as long, so that
78  * we can use a consistent printf format specifier without warnings on
79  * any platform.  Fortunately this works at the moement; if it breaks
80  * in the future we'll have to start using macros for format
81  * specifiers (c.f. FMT_StgWord64 in Rts.h).
82  */
83
84 #if SIZEOF_VOID_P == 8
85 typedef StgInt64           StgInt;
86 typedef StgWord64          StgWord;
87 typedef StgInt32           StgHalfInt;
88 typedef StgWord32          StgHalfWord;
89 #else
90 #if SIZEOF_VOID_P == 4
91 typedef StgInt32           StgInt; 
92 typedef StgWord32          StgWord;
93 typedef StgInt16           StgHalfInt;
94 typedef StgWord16          StgHalfWord;
95 #else
96 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
97 #endif
98 #endif
99
100 #define W_MASK  (sizeof(W_)-1)
101
102 /*
103  * Other commonly-used STG datatypes.
104  */
105
106 typedef void*              StgAddr;
107 typedef StgWord32          StgChar;
108 typedef int                StgBool;
109 typedef float              StgFloat;
110 typedef double             StgDouble;
111 typedef StgWord*           StgPtr;           /* heap or stack pointer */
112 typedef StgWord volatile*  StgVolatilePtr;   /* pointer to volatile word   */
113 typedef StgWord            StgOffset;        /* byte offset within closure */
114 typedef StgWord8           StgCode;          /* close enough */
115 typedef void*              StgStablePtr;
116 typedef StgWord8*          StgByteArray;
117
118 /*
119   Types for the generated C functions
120   take no arguments
121   return a pointer to the next function to be called
122   use: Ptr to Fun that returns a Ptr to Fun which returns Ptr to void
123
124   Note: Neither StgFunPtr not StgFun is quite right (that is, 
125   StgFunPtr != StgFun*).  So, the functions we define all have type
126   StgFun but we always have to cast them to StgFunPtr when we assign
127   them to something.
128   The only way round this would be to write a recursive type but
129   C only allows that if you're defining a struct or union.
130 */
131
132 typedef void  *(*(*StgFunPtr)(void))(void);
133 typedef StgFunPtr StgFun(void);
134
135 #endif /* STGTYPES_H */