StgTypes.h 4.32 KB
Newer Older
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 9
 *
 * This module should define types *only*, all beginning with "Stg".
 *
10 11
 * Specifically:

sof's avatar
sof committed
12 13
	StgInt8,  16, 32, 64
	StgWord8, 16, 32, 64
14 15
	StgChar, StgFloat, StgDouble

16
	***** All the same size (i.e. sizeof(void *)): *****
17 18 19 20 21
	StgPtr			Basic pointer type
	StgWord			Unit of heap allocation
	StgInt			Signed version of StgWord
	StgAddr			Generic address type
	
22 23 24 25 26
	StgBool, StgVoid, StgClosurePtr, StgPtr, StgOffset, 
	StgTSOPtr, StgForeignPtr, StgStackOffset, StgStackPtr,
	StgCode, StgArray, StgByteArray, StgStablePtr, StgFunPtr,
	StgUnion.

27
 * WARNING: Keep this file, MachDeps.h, and HsFFI.h in synch!
28
 *
29
 * NOTE: assumes #include "ghcconfig.h"
30 31 32
 * 
 * Works with or without _POSIX_SOURCE.
 *
33 34 35 36 37 38 39 40
 * ---------------------------------------------------------------------------*/

#ifndef STGTYPES_H
#define STGTYPES_H

/*
 * First, platform-dependent definitions of size-specific integers.
 * Assume for now that the int type is 32 bits.
41
 * NOTE: Synch the following definitions with MachDeps.h!
42 43 44 45
 * ToDo: move these into a platform-dependent file.
 */

typedef signed   char            StgInt8;
sof's avatar
sof committed
46
typedef unsigned char            StgWord8;
47 48

typedef signed   short           StgInt16;
sof's avatar
sof committed
49
typedef unsigned short           StgWord16;
50 51 52

#if SIZEOF_UNSIGNED_INT == 4
typedef signed   int             StgInt32;
sof's avatar
sof committed
53
typedef unsigned int             StgWord32;
54
#else
55
#error GHC untested on this architecture: sizeof(unsigned int) != 4
56 57 58 59
#endif

#ifdef SUPPORT_LONG_LONGS
/* assume long long is 64 bits */
sof's avatar
sof committed
60
# ifndef _MSC_VER
61
typedef signed long long int   StgInt64;
62
typedef unsigned long long int StgWord64;
sof's avatar
sof committed
63 64 65 66
# else
typedef __int64 StgInt64;
typedef unsigned __int64 StgWord64;
# endif
67 68
#elif SIZEOF_LONG == 8
typedef signed   long          StgInt64;
sof's avatar
sof committed
69
typedef unsigned long          StgWord64;
70 71 72
#elif defined(__MSVC__)
typedef __int64                StgInt64;
typedef unsigned __int64       StgWord64;
73 74 75 76 77 78 79 80 81 82 83
#else
#error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
#endif

/*
 * Define the standard word size we'll use on this machine: make it
 * big enough to hold a pointer.
 */

#if SIZEOF_VOID_P == 8
typedef StgInt64           StgInt;
sof's avatar
sof committed
84
typedef StgWord64          StgWord;
85
typedef StgInt32           StgHalfInt;
86
typedef StgWord32          StgHalfWord;
87 88 89
#else
#if SIZEOF_VOID_P == 4
typedef StgInt32           StgInt; 
sof's avatar
sof committed
90
typedef StgWord32          StgWord;
91
typedef StgInt16           StgHalfInt;
92
typedef StgWord16          StgHalfWord;
93 94 95 96 97
#else
#error GHC untested on this architecture: sizeof(void *) != 4 or 8
#endif
#endif

98 99
#define W_MASK  (sizeof(W_)-1)

100 101 102 103 104 105
typedef void*              StgAddr;

/*
 * Other commonly-used STG datatypes.
 */

106
typedef StgWord32          StgChar;
107
typedef int                StgBool;
108 109 110 111 112 113

typedef float		   StgFloat;
typedef double		   StgDouble;
                           
typedef void               StgVoid;
                           
114 115
typedef struct StgClosure_ StgClosure;
typedef StgClosure*        StgClosurePtr;
116 117 118 119 120
typedef StgWord*           StgPtr;           /* pointer into closure       */
typedef StgWord            StgOffset;        /* byte offset within closure */
                           
typedef struct StgTSO_*    StgTSOPtr;

121
typedef void*              StgForeignPtr;
122 123 124 125 126

typedef StgInt             StgStackOffset;   /* offset in words! */

typedef StgWord*           StgStackPtr;

sof's avatar
sof committed
127
typedef StgWord8 	   StgCode;  	    /* close enough */
128 129 130 131

typedef StgPtr*            StgArray;        /* the goods of an Array# */
typedef char*		   StgByteArray;    /* the goods of a ByteArray# */

132
typedef void*		   StgStablePtr;
133

134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
/*
  Types for the generated C functions
  take no arguments
  return a pointer to the next function to be called
  use: Ptr to Fun that returns a Ptr to Fun which returns Ptr to void

  Note: Neither StgFunPtr not StgFun is quite right (that is, 
  StgFunPtr != StgFun*).  So, the functions we define all have type
  StgFun but we always have to cast them to StgFunPtr when we assign
  them to something.
  The only way round this would be to write a recursive type but
  C only allows that if you're defining a struct or union.
*/

typedef void  *(*(*StgFunPtr)(void))(void);
typedef StgFunPtr StgFun(void);

151
#endif /* STGTYPES_H */