/* -----------------------------------------------------------------------------
 *
 * (c) The GHC Team, 1998-2009
 *
 * RTS-specific types.
 *
 * Do not #include this file directly: #include "Rts.h" instead.
 *
 * To understand the structure of the RTS headers, see the wiki:
 *   http://hackage.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
 *
 * ---------------------------------------------------------------------------*/

#ifndef RTS_TYPES_H
#define RTS_TYPES_H

typedef unsigned int  nat;           /* at least 32 bits (like int) */
typedef unsigned long lnat;          /* at least 32 bits            */
#ifndef _MSC_VER
typedef unsigned long long ullong;   /* at least 32 bits            */
typedef long long llong;
#else
typedef unsigned __int64   ullong;   /* at least 32 bits            */
typedef __int64 llong;
#endif

/* ullong (64|128-bit) type: only include if needed (not ANSI) */
#if defined(__GNUC__) 
#define LL(x) (x##LL)
#else
#define LL(x) (x##L)
#endif
  
typedef enum { 
    rtsFalse = 0, 
    rtsTrue 
} rtsBool;

typedef struct StgClosure_   StgClosure;
typedef struct StgInfoTable_ StgInfoTable;
typedef struct StgTSO_       StgTSO;

/* 
   Types specific to the parallel runtime system.
*/

/* 
   Types specific to the PARALLEL_RTS runtime system.
   but types are defined in the sequential base system as well
*/

// aliases
typedef int           OpCode;

// a port type, stands for an inport (pe, proc,inport->id), an outport
// (pe,proc,tso->id) and processes (pe, proc, NULL)
typedef struct Port_ {
  nat machine;
  StgWord process;
  StgWord id;
} Port;
typedef Port Proc;

typedef ullong        rtsTime;

// for GALA tables management
typedef unsigned int  rtsWeight;

/* global address: a globally unique identifier for a closure */
typedef struct {
  rtsWeight weight;
  nat pe;
  nat slot;
} globalAddr;

/* (GA, LA) pairs; needed in GALA and LAGA tables */
typedef struct gala {
  globalAddr ga;     // global address (as struct)
  StgClosure *la;    // local address (as ptr)
  rtsBool preferred; // is this the preferred GA
  StgWord tag;       // tag of the ptr to the local address 
  struct gala *next; // link to the next GALA record
} GALA;

#endif /* RTS_TYPES_H */
