#include "Rts.h"   

#define Node    1 
#define Cycle   2 
#define Thunk   3 
#define Char    4 
#define Int     5 
#define SmallInteger 6 
#define LargeInteger 7 
#define Float   8 
#define Double  9 
#define EncodedFunction 10 
#define Exception 11 
#define Ap_Upd 12 
#define Fun 13 
#define Unknown 14 

#define FUNCTION_ENCODER "F0"

#define IO_ENCODER "Eio"

#define TERMINAL_FILE "/dev/tty"

typedef struct _graphNode GraphNode; 
typedef union  _val Val;
typedef char Tag;

union _val
{
   char         character;
   int          machineInt;
   float        machineFloat;
   char *       descriptor;
   StgStablePtr largeIntegerSPtr;
   double       machineDouble;
};

struct _graphNode
{
   unsigned int unique;          /* unique number for this node */
   Val          val;             /* value at this node */
   Tag          tag;             /* node type  */
   short int    numChildren;     /* the number of children, 16 bits should be plenty */
   GraphNode    **children;      /* children arcs, zero or more */
};

typedef struct _listNode List; 

struct _listNode
{
   unsigned int val;
   List *next;
};

typedef enum {False=0, True=1} Bool;

GraphNode *makeGraphNode (int unique, Tag tag, char *descriptor, int numChildren);
void freeGraph (GraphNode *node);
void printGraph (GraphNode *node);

List *cons (int val, List *l);
List *freeListNode (List *l);

void showHeapGraphC (StgStablePtr objPtr);
Bool isIOC (StgStablePtr objPtr);
Bool isThunkC (StgStablePtr objPtr);
int reEvalC (StgStablePtr old, StgStablePtr new);
GraphNode *makeHeapGraph (StgStablePtr obj);
void printLitChar (FILE *ttyFP, char c);
