[project @ 2000-03-10 14:53:00 by sewardj]
[ghc-hetmet.git] / ghc / interpreter / storage.h
index 7cb8c41..7285f50 100644 (file)
@@ -3,14 +3,15 @@
  * Defines storage datatypes: Text, Name, Module, Tycon, Cell, List, Pair,
  * Triple, ...
  *
- * Hugs 98 is Copyright (c) Mark P Jones, Alastair Reid and the Yale
- * Haskell Group 1994-99, and is distributed as Open Source software
- * under the Artistic License; see the file "Artistic" that is included
- * in the distribution for details.
+ * The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the
+ * Yale Haskell Group, and the Oregon Graduate Institute of Science and
+ * Technology, 1994-1999, All rights reserved.  It is distributed as
+ * free software under the license in the file "License", which is
+ * included in the distribution.
  *
  * $RCSfile: storage.h,v $
- * $Revision: 1.6 $
- * $Date: 1999/04/27 10:07:06 $
+ * $Revision: 1.32 $
+ * $Date: 2000/03/10 14:53:00 $
  * ------------------------------------------------------------------------*/
 
 /* --------------------------------------------------------------------------
@@ -46,22 +47,30 @@ typedef Cell         Float;                      /* floating pt literal    */
 typedef Cell         Ext;                        /* extension label        */
 #endif
 
+typedef Cell         ConId;
+typedef Cell         VarId;
+typedef Cell         QualId;
+typedef Cell         ConVarId;
+
 /* --------------------------------------------------------------------------
  * Text storage:
  * provides storage for the characters making up identifier and symbol
  * names, string literals, character constants etc...
  * ------------------------------------------------------------------------*/
 
-extern  String       textToStr          Args((Text));
-extern  Text         findText           Args((String));
-extern  Text         inventText         Args((Void));
-extern  Text         inventDictText     Args((Void));
-extern  Bool         inventedText       Args((Text));
+extern  String       textToStr            Args((Text));
+extern  Text         findText             Args((String));
+extern  Text         inventText           Args((Void));
+extern  Text         inventDictText       Args((Void));
+extern  Bool         inventedText         Args((Text));
+extern  Text         enZcodeThenFindText  Args((String));
+extern  Text         unZcodeThenFindText  Args((String));
 
 /* Variants of textToStr and syntaxOf which work for idents, ops whether
  * qualified or unqualified.
  */
 extern  String       identToStr         Args((Cell));
+extern Text         fixLitText         Args((Text));
 extern  Syntax       identSyntax        Args((Cell));
 extern  Syntax       defaultSyntax      Args((Text));
 
@@ -131,8 +140,12 @@ extern  Cell         whatIs    Args((Cell));
  * and string text etc.
  * ------------------------------------------------------------------------*/
 
+#if !defined(SIZEOF_VOID_P) || !defined(SIZEOF_INT)
+#error SIZEOF_VOID_P or SIZEOF_INT is not defined
+#endif
+
 #define TAGMIN       1            /* Box and constructor cell tag values   */
-#define BCSTAG       20           /* Box=TAGMIN..BCSTAG-1                  */
+#define BCSTAG       30           /* Box=TAGMIN..BCSTAG-1                  */
 #define isTag(c)     (TAGMIN<=(c) && (c)<SPECMIN) /* Tag cell values       */
 #define isBoxTag(c)  (TAGMIN<=(c) && (c)<BCSTAG)  /* Box cell tag values   */
 #define isConTag(c)  (BCSTAG<=(c) && (c)<SPECMIN) /* Constr cell tag values*/
@@ -148,14 +161,18 @@ extern  Cell         whatIs    Args((Cell));
 #define ADDPAT       11           /* (_+k) pattern discr:     snd :: Int   */
 #define FLOATCELL    15           /* Floating Pt literal:     snd :: Text  */
 #define BIGCELL      16           /* Integer literal:         snd :: Text  */
-#if PTR_ON_HEAP
 #define PTRCELL      17           /* C Heap Pointer           snd :: Ptr   */
+#define CPTRCELL     21           /* Native code pointer      snd :: Ptr   */
+
+#if IPARAM
+#define IPCELL       19                  /* Imp Param Cell:          snd :: Text  */
+#define IPVAR       20           /* ?x:                      snd :: Text  */
 #endif
+
 #if TREX
-#define EXTCOPY      18           /* Copy of an Ext:          snd :: Text  */
+#define EXTCOPY      22           /* Copy of an Ext:          snd :: Text  */
 #endif
 
-#define textOf(c)       ((Text)(snd(c)))         /* c ::  (VAR|CON)(ID|OP) */
 #define qmodOf(c)       (textOf(fst(snd(c))))    /* c ::  QUALIDENT        */
 #define qtextOf(c)      (textOf(snd(snd(c))))    /* c ::  QUALIDENT        */
 #define mkVar(t)        ap(VARIDCELL,t)
@@ -166,19 +183,30 @@ extern  Cell         whatIs    Args((Cell));
 #define mkQCon(m,t)     ap(QUALIDENT,pair(mkCon(m),mkCon(t)))
 #define mkQVarOp(m,t)   ap(QUALIDENT,pair(mkCon(m),mkVarop(t)))
 #define mkQConOp(m,t)   ap(QUALIDENT,pair(mkCon(m),mkConop(t)))
+#define mkQualId(m,t)   ap(QUALIDENT,pair(m,t))
 #define intValOf(c)     (snd(c))
 #define inventVar()     mkVar(inventText())
 #define mkDictVar(t)    ap(DICTVAR,t)
 #define inventDictVar() mkDictVar(inventDictText())
 #define mkStr(t)        ap(STRCELL,t)
-extern  Bool            isVar       Args((Cell));
-extern  Bool            isCon       Args((Cell));
-extern  Bool            isQVar      Args((Cell));
-extern  Bool            isQCon      Args((Cell));
-extern  Bool            isQualIdent Args((Cell));
-extern  Bool            isIdent     Args((Cell));
+#if IPARAM
+#define mkIParam(c)    ap(IPCELL,snd(c))
+#define isIP(p)                (whatIs(p) == IPCELL)
+#define ipMatch(pi, t) (isIP(fun(pi)) && textOf(fun(pi)) == t)
+#define ipVar(pi)      textOf(fun(pi))
+#else
+#define isIP(p)                FALSE
+#endif
 
-extern  String           stringNegate Args((String));
+extern  Bool            isVar        Args((Cell));
+extern  Bool            isCon        Args((Cell));
+extern  Bool            isQVar       Args((Cell));
+extern  Bool            isQCon       Args((Cell));
+extern  Bool            isQualIdent  Args((Cell));
+extern  Bool            eqQualIdent ( QualId c1, QualId c2 );
+extern  Bool            isIdent      Args((Cell));
+extern  String          stringNegate Args((String));
+extern  Text            textOf       Args((Cell));
 
 #define isFloat(c)       (isPair(c) && fst(c)==FLOATCELL)
 #define stringToFloat(s) pair(FLOATCELL,findText(s))
@@ -190,12 +218,12 @@ extern  String           stringNegate Args((String));
 #define stringToBignum(s) pair(BIGCELL,findText(s))
 #define bignumToString(b) textToStr(snd(b))
 
-
-#if PTR_ON_HEAP
 #define isPtr(c)        (isPair(c) && fst(c)==PTRCELL)
 extern  Cell            mkPtr           Args((Ptr));
 extern  Ptr             ptrOf           Args((Cell));
-#endif
+#define isCPtr(c)       (isPair(c) && fst(c)==CPTRCELL)
+extern  Cell            mkCPtr          Args((Ptr));
+extern  Ptr             cptrOf          Args((Cell));
 
 /* --------------------------------------------------------------------------
  * Constructor cell tags are used as the fst element of a pair to indicate
@@ -206,69 +234,70 @@ extern  Ptr             ptrOf           Args((Cell));
  * element is a special cell will be treated as an application node.
  * ------------------------------------------------------------------------*/
 
-#define LETREC       20           /* LETREC     snd :: ([Decl],Exp)        */
-#define COND         21           /* COND       snd :: (Exp,Exp,Exp)       */
-#define LAMBDA       22           /* LAMBDA     snd :: Alt                 */
-#define FINLIST      23           /* FINLIST    snd :: [Exp]               */
-#define DOCOMP       24           /* DOCOMP     snd :: (Exp,[Qual])        */
-#define BANG         25           /* BANG       snd :: Type                */
-#define COMP         26           /* COMP       snd :: (Exp,[Qual])        */
-#define ASPAT        27           /* ASPAT      snd :: (Var,Exp)           */
-#define ESIGN        28           /* ESIGN      snd :: (Exp,Type)          */
-#define RSIGN        29           /* RSIGN      snd :: (Rhs,Type)          */
-#define CASE         30           /* CASE       snd :: (Exp,[Alt])         */
-#define NUMCASE      31           /* NUMCASE    snd :: (Exp,Disc,Rhs)      */
-#define FATBAR       32           /* FATBAR     snd :: (Exp,Exp)           */
-#define LAZYPAT      33           /* LAZYPAT    snd :: Exp                 */
-#define DERIVE       35           /* DERIVE     snd :: Cell                */
-#if BREAK_FLOATS
-#define FLOATCELL    36           /* FLOATCELL  snd :: (Int,Int)           */
+#define LETREC       30           /* LETREC     snd :: ([Decl],Exp)        */
+#define COND         31           /* COND       snd :: (Exp,Exp,Exp)       */
+#define LAMBDA       32           /* LAMBDA     snd :: Alt                 */
+#define FINLIST      33           /* FINLIST    snd :: [Exp]               */
+#define DOCOMP       34           /* DOCOMP     snd :: (Exp,[Qual])        */
+#define BANG         35           /* BANG       snd :: Type                */
+#define COMP         36           /* COMP       snd :: (Exp,[Qual])        */
+#define ASPAT        37           /* ASPAT      snd :: (Var,Exp)           */
+#define ESIGN        38           /* ESIGN      snd :: (Exp,Type)          */
+#define RSIGN        39           /* RSIGN      snd :: (Rhs,Type)          */
+#define CASE         40           /* CASE       snd :: (Exp,[Alt])         */
+#define NUMCASE      41           /* NUMCASE    snd :: (Exp,Disc,Rhs)      */
+#define FATBAR       42           /* FATBAR     snd :: (Exp,Exp)           */
+#define LAZYPAT      43           /* LAZYPAT    snd :: Exp                 */
+#define DERIVE       45           /* DERIVE     snd :: Cell                */
+#define BOOLQUAL     49           /* BOOLQUAL   snd :: Exp                 */
+#define QWHERE       50           /* QWHERE     snd :: [Decl]              */
+#define FROMQUAL     51           /* FROMQUAL   snd :: (Exp,Exp)           */
+#define DOQUAL       52           /* DOQUAL     snd :: Exp                 */
+#define MONADCOMP    53           /* MONADCOMP  snd :: ((m,m0),(Exp,[Qual])*/
+#define GUARDED      54           /* GUARDED    snd :: [guarded exprs]     */
+#define ARRAY        55           /* Array      snd :: (Bounds,[Values])   */
+#define MUTVAR       56           /* Mutvar     snd :: Cell                */
+#define HUGSOBJECT   57           /* HUGSOBJECT snd :: Cell                */
+
+#if IPARAM
+#define WITHEXP      58          /* WITHEXP    snd :: [(Var,Exp)]         */
 #endif
 
-#define BOOLQUAL     39           /* BOOLQUAL   snd :: Exp                 */
-#define QWHERE       40           /* QWHERE     snd :: [Decl]              */
-#define FROMQUAL     41           /* FROMQUAL   snd :: (Exp,Exp)           */
-#define DOQUAL       42           /* DOQUAL     snd :: Exp                 */
-#define MONADCOMP    43           /* MONADCOMP  snd :: ((m,m0),(Exp,[Qual])*/
-
-#define GUARDED      44           /* GUARDED    snd :: [guarded exprs]     */
-
-#define ARRAY        45           /* Array      snd :: (Bounds,[Values])   */
-#define MUTVAR       46           /* Mutvar     snd :: Cell                */
-#if INTERNAL_PRIMS
-#define HUGSOBJECT   47           /* HUGSOBJECT snd :: Cell                */
-#endif
-
-#define POLYTYPE     50           /* POLYTYPE   snd :: (Kind,Type)         */
-#define QUAL         51           /* QUAL       snd :: ([Classes],Type)    */
-#define RANK2        52           /* RANK2      snd :: (Int,Type)          */
-#define EXIST        53           /* EXIST      snd :: (Int,Type)          */
-#define POLYREC      54           /* POLYREC    snd :: (Int,Type)          */
-#define BIGLAM       55           /* BIGLAM     snd :: (vars,patterns)     */
-#define CDICTS       56           /* CDICTS     snd :: ([Pred],Type)       */
-
-#define LABC         60           /* LABC       snd :: (con,[(Vars,Type)]) */
-#define CONFLDS      61           /* CONFLDS    snd :: (con,[Field])       */
-#define UPDFLDS      62           /* UPDFLDS    snd :: (Exp,[con],[Field]) */
+#define POLYTYPE     60           /* POLYTYPE   snd :: (Kind,Type)         */
+#define QUAL         61           /* QUAL       snd :: ([Classes],Type)    */
+#define RANK2        62           /* RANK2      snd :: (Int,Type)          */
+#define EXIST        63           /* EXIST      snd :: (Int,Type)          */
+#define POLYREC      64           /* POLYREC    snd :: (Int,Type)          */
+#define BIGLAM       65           /* BIGLAM     snd :: (vars,patterns)     */
+#define CDICTS       66           /* CDICTS     snd :: ([Pred],Type)       */
+
+#define LABC         67           /* LABC       snd :: (con,[(Vars,Type)]) */
+#define CONFLDS      68           /* CONFLDS    snd :: (con,[Field])       */
+#define UPDFLDS      69           /* UPDFLDS    snd :: (Exp,[con],[Field]) */
 #if TREX
-#define RECORD       63           /* RECORD     snd :: [Val]               */
-#define EXTCASE      64           /* EXTCASE    snd :: (Exp,Disc,Rhs)      */
-#define RECSEL       65           /* RECSEL     snd :: Ext                 */
+#define RECORD       70           /* RECORD     snd :: [Val]               */
+#define EXTCASE      71           /* EXTCASE    snd :: (Exp,Disc,Rhs)      */
+#define RECSEL       72           /* RECSEL     snd :: Ext                 */
 #endif
-#define IMPDEPS      68           /* IMPDEPS    snd :: [Binding]           */
+#define IMPDEPS      73           /* IMPDEPS    snd :: [Binding]           */
+
+#define QUALIDENT    74           /* Qualified identifier  snd :: (Id,Id)  */
+#define HIDDEN       75           /* hiding import list    snd :: [Entity] */
+#define MODULEENT    76           /* module in export list snd :: con      */
 
-#define QUALIDENT    70           /* Qualified identifier  snd :: (Id,Id)  */
-#define HIDDEN       71           /* hiding import list    snd :: [Entity] */
-#define MODULEENT    72           /* module in export list snd :: con      */
+#define INFIX        77           /* INFIX      snd :: (see tidyInfix)     */
+#define ONLY         78           /* ONLY       snd :: Exp                 */
+#define NEG          79           /* NEG        snd :: Exp                 */
 
-#define INFIX        80           /* INFIX      snd :: (see tidyInfix)     */
-#define ONLY         81           /* ONLY       snd :: Exp                 */
-#define NEG          82           /* NEG        snd :: Exp                 */
+/* Used when parsing GHC interface files */
+#define DICTAP       80           /* DICTAP     snd :: (QClassId,[Type])   */
+#define UNBOXEDTUP   81           /* UNBOXEDTUP snd :: [Type]              */
 
-#if SIZEOF_INTP != SIZEOF_INT
-#define PTRCELL      90           /* C Heap Pointer snd :: (Int,Int)       */
+#if SIZEOF_VOID_P != SIZEOF_INT
+#define PTRCELL      82           /* C Heap Pointer snd :: (Int,Int)       */
 #endif
 
+/* STG syntax */
 #define STGVAR       92           /* STGVAR     snd :: (StgRhs,info)       */
 #define STGAPP       93           /* STGAPP     snd :: (StgVar,[Arg])      */
 #define STGPRIM      94           /* STGPRIM    snd :: (PrimOp,[Arg])      */
@@ -277,66 +306,139 @@ extern  Ptr             ptrOf           Args((Cell));
 #define DEEFALT      97           /* DEEFALT    snd :: (Var,Expr)          */
 #define CASEALT      98           /* CASEALT    snd :: (Con,[Var],Expr)    */
 #define PRIMALT      99           /* PRIMALT    snd :: ([Var],Expr)        */
+
+
+/* 
+   Top-level interface entities 
+   type Line             = Int  -- a line number 
+   type ConVarId         = CONIDCELL | VARIDCELL
+   type <a>              = ZList a
+   type ExportListEntry  = ConVarId | (ConId, <ConVarId>) 
+   type Associativity    = mkInt of LEFT_ASS | RIGHT_ASS | NON_ASS
+   type Constr           = ((ConId, [((Type,VarId,Int))]))
+               ((constr name, [((type, field name if any, strictness))]))
+               strictness: 0 => none, 1 => !, 2 => !! (unpacked)
+   All 2/3/4/5 tuples in the interface abstract syntax are done with
+   z-tuples.
+*/
+
+#define I_INTERFACE  109  /* snd :: ((ConId, [I_IMPORT..I_VALUE])) 
+                                    interface name, list of iface entities */
+
+#define I_IMPORT     110  /* snd :: ((ConId, [ConVarId]))
+                                    module name, list of entities          */
+
+#define I_INSTIMPORT 111  /* snd :: NIL    -- not used at present          */
+
+#define I_EXPORT     112  /* snd :: ((ConId, [ExportListEntry]))
+                                    this module name?, entities to export  */
+
+#define I_FIXDECL    113  /* snd :: ((NIL|Int, Associativity, ConVarId))   
+                                    fixity, associativity, name            */
+
+#define I_INSTANCE   114 /* snd :: ((Line, 
+                                     [((VarId,Kind))], 
+                                     Type, VarId, Inst))
+                   lineno, 
+                   forall-y bit (eg __forall [a b] =>),
+                   other bit, eg { C a1 } -> { C2 a2 } -> ... -> { Cn an },
+                   name of dictionary builder,
+                   (after startGHCInstance) the instance table location    */
+
+#define I_TYPE       115 /* snd :: ((Line, ConId, [((VarId,Kind))], Type))
+                            lineno, tycon, kinded tyvars, the type expr    */
+
+#define I_DATA       116 /* snd :: ((Line, [((QConId,VarId))], ConId, 
+                                          [((VarId,Kind))], [Constr]) 
+                            lineno, context, tycon, kinded tyvars, constrs 
+                           An empty constr list means exported abstractly. */
+
+#define I_NEWTYPE    117 /* snd :: ((Line, [((QConId,VarId))], ConId,
+                                    [((VarId,Kind))], ((ConId,Type)) ))
+                             lineno, context, tycon, kinded tyvars, constr 
+                                    constr==NIL means exported abstractly. */
+
+#define I_CLASS      118 /* snd :: ((Line, [((QConId,VarId))], ConId,
+                                    [((VarId,Kind))], [((VarId,Type))]))
+                            lineno, context, classname, 
+                                      kinded tyvars, method sigs           */
+
+#define I_VALUE      119 /* snd :: ((Line, VarId, Type))                   */
+
+
+
+/* Generic syntax */
+#if 0
+#define ZCONS        190          /* snd :: (Cell,Cell)                    */
+#endif
+
+
+#define ZTUP2        192          /* snd :: (Cell,Cell)                    */
+#define ZTUP3        193          /* snd :: (Cell,(Cell,Cell))             */
+#define ZTUP4        194          /* snd :: (Cell,(Cell,(Cell,Cell)))      */
+#define ZTUP5        195       /* snd :: (Cell,(Cell,(Cell,(Cell,Cell))))  */
+
 /* Last constructor tag must be less than SPECMIN */
 
 /* --------------------------------------------------------------------------
  * Special cell values:
  * ------------------------------------------------------------------------*/
 
-#define SPECMIN      101
-#define isSpec(c)    (SPECMIN<=(c) && (c)<TUPMIN)/* Special cell values    */
+#define SPECMIN      201
+
+#if TREX
+#define isSpec(c)    (SPECMIN<=(c) && (c)<EXTMIN)/* Special cell values    */
+#else
+#define isSpec(c)    (SPECMIN<=(c) && (c)<OFFMIN)
+#endif
 
-#define NONE         101          /* Dummy stub                            */
-#define STAR         102          /* Representing the kind of types        */
+#define NONE         201          /* Dummy stub                            */
+#define STAR         202          /* Representing the kind of types        */
 #if TREX
-#define ROW          103          /* Representing the kind of rows         */
+#define ROW          203          /* Representing the kind of rows         */
 #endif
-#define WILDCARD     104          /* Wildcard pattern                      */
-#define SKOLEM       105          /* Skolem constant                       */
-
-#define DOTDOT       106          /* ".." in import/export list            */
-
-#define NAME         110          /* whatIs code for isName                */
-#define TYCON        111          /* whatIs code for isTycon               */
-#define CLASS        112          /* whatIs code for isClass               */
-#define MODULE       113          /* whatIs code for isModule              */
-#define INSTANCE     114          /* whatIs code for isInst                */
-#define TUPLE        115          /* whatIs code for tuple constructor     */
-#define OFFSET       116          /* whatis code for offset                */
-#define AP           117          /* whatIs code for application node      */
-#define CHARCELL     118          /* whatIs code for isChar                */
+#define WILDCARD     204          /* Wildcard pattern                      */
+#define SKOLEM       205          /* Skolem constant                       */
+
+#define DOTDOT       206          /* ".." in import/export list            */
+
+#define NAME         210          /* whatIs code for isName                */
+#define TYCON        211          /* whatIs code for isTycon               */
+#define CLASS        212          /* whatIs code for isClass               */
+#define MODULE       213          /* whatIs code for isModule              */
+#define INSTANCE     214          /* whatIs code for isInst                */
+#define TUPLE        215          /* whatIs code for tuple constructor     */
+#define OFFSET       216          /* whatis code for offset                */
+#define AP           217          /* whatIs code for application node      */
+#define CHARCELL     218          /* whatIs code for isChar                */
 #if TREX
-#define EXT          119          /* whatIs code for isExt                 */
+#define EXT          219          /* whatIs code for isExt                 */
 #endif
 
-#define SIGDECL      120          /* Signature declaration                 */
-#define FIXDECL      121          /* Fixity declaration                    */
-#define FUNBIND      122          /* Function binding                      */
-#define PATBIND      123          /* Pattern binding                       */
+#define SIGDECL      220          /* Signature declaration                 */
+#define FIXDECL      221          /* Fixity declaration                    */
+#define FUNBIND      222          /* Function binding                      */
+#define PATBIND      223          /* Pattern binding                       */
 
-#define DATATYPE     130          /* Datatype type constructor             */
-#define NEWTYPE      131          /* Newtype type constructor              */
-#define SYNONYM      132          /* Synonym type constructor              */
-#define RESTRICTSYN  133          /* Synonym with restricted scope         */
+#define DATATYPE     230          /* Datatype type constructor             */
+#define NEWTYPE      231          /* Newtype type constructor              */
+#define SYNONYM      232          /* Synonym type constructor              */
+#define RESTRICTSYN  233          /* Synonym with restricted scope         */
 
-#define NODEPENDS    135          /* Stop calculation of deps in type check*/
-#define PREDEFINED   136          /* Predefined name, not yet filled       */
+#define NODEPENDS    235          /* Stop calculation of deps in type check*/
+#define PREDEFINED   236          /* Predefined name, not yet filled       */
 
 /* --------------------------------------------------------------------------
  * Tuple data/type constructors:
  * ------------------------------------------------------------------------*/
 
-#define TUPMIN       201
-#if TREX
-#define isTuple(c)   (TUPMIN<=(c) && (c)<EXTMIN)
-#else
-#define isTuple(c)   (TUPMIN<=(c) && (c)<OFFMIN)
-#endif
-#define mkTuple(n)   (TUPMIN+(n))
-#define tupleOf(n)   ((Int)((n)-TUPMIN))
+extern Text ghcTupleText    Args((Tycon));
+extern Text ghcTupleText_n  Args((Int));
+
+
 
 #if TREX
-#define EXTMIN       (TUPMIN+NUM_TUPLES)
+#define EXTMIN       301
 #define isExt(c)     (EXTMIN<=(c) && (c)<OFFMIN)
 #define extText(e)   tabExt[(e)-EXTMIN]
 #define extField(c)  arg(fun(c))
@@ -348,6 +450,14 @@ extern Ext           mkExt Args((Text));
 #define mkExt(t) NIL
 #endif
 
+extern Module findFakeModule ( Text t );
+extern Tycon addTupleTycon ( Int n );
+extern Name addWiredInBoxingTycon
+               ( String modNm, String typeNm, String constrNm,
+                 Int rep, Kind kind );
+Tycon addWiredInEnumTycon ( String modNm, String typeNm, 
+                            List /*of Text*/ constrs );
+
 /* --------------------------------------------------------------------------
  * Offsets: (generic types/stack offsets)
  * ------------------------------------------------------------------------*/
@@ -355,12 +465,13 @@ extern Ext           mkExt Args((Text));
 #if TREX
 #define OFFMIN       (EXTMIN+NUM_EXT)
 #else
-#define OFFMIN       (TUPMIN+NUM_TUPLES)
+#define OFFMIN       301
 #endif
 #define isOffset(c)  (OFFMIN<=(c) && (c)<MODMIN)
 #define offsetOf(c)  ((c)-OFFMIN)
 #define mkOffset(o)  (OFFMIN+(o))
 
+
 /* --------------------------------------------------------------------------
  * Modules:
  * ------------------------------------------------------------------------*/
@@ -371,6 +482,9 @@ extern Ext           mkExt Args((Text));
 #define mkModule(n)   (MODMIN+(n))
 #define module(n)     tabModule[(n)-MODMIN]
 
+/* Import defns for the ObjectCode struct in Module. */
+#include "object.h"
+
 /* Under Haskell 1.3, the list of qualified imports is always a subset
  * of the list of unqualified imports.  For simplicity and flexibility,
  * we do not attempt to exploit this fact - when a module is imported
@@ -392,9 +506,19 @@ struct Module {
      * evaluating an expression in the context of the current module.
      */
     List  qualImports;
-    ObjectFile objectFile; /* usually unused */
+
+    /* TRUE if module exists only via GHC primop defn; usually FALSE */
+    Bool  fake; 
+
+    /* The primary object file for this module. */
+    ObjectCode* object;
+
+    /* And any extras it might need. */
+    ObjectCode* objectExtras;
+    List        objectExtraNames;   /* :: [Text] -- names of extras */
 };
 
+
 extern Module currentModule;           /* Module currently being processed */
 extern struct Module DECTABLE(tabModule);
 
@@ -404,28 +528,44 @@ extern Module findModule    Args((Text));
 extern Module findModid     Args((Cell));
 extern Void   setCurrModule Args((Module));
 
+extern void      addOTabName     Args((Module,char*,void*));
+extern void*     lookupOTabName  Args((Module,char*));
+extern char*     nameFromOPtr    Args((void*));
+
+extern void          addSection    Args((Module,void*,void*,OSectionKind));
+extern OSectionKind  lookupSection Args((void*));
+extern void* lookupOExtraTabName ( char* sym );
+
 #define isPrelude(m) (m==modulePrelude)
 
+#define N_PRELUDE_SCRIPTS (combined ? 32 : 1)
+
 /* --------------------------------------------------------------------------
  * Type constructor names:
  * ------------------------------------------------------------------------*/
 
 #define TYCMIN       (MODMIN+NUM_MODULE)
-#define isTycon(c)   (TYCMIN<=(c) && (c)<NAMEMIN)
-#define mkTycon(n)   (TCMIN+(n))
+#define isTycon(c)   (TYCMIN<=(c) && (c)<NAMEMIN && tabTycon[(c)-TYCMIN].tuple==-1)
 #define tycon(n)     tabTycon[(n)-TYCMIN]
 
+#define isTuple(c)   (TYCMIN<=(c) && (c)<NAMEMIN && tabTycon[(c)-TYCMIN].tuple>=0)
+#define tupleOf(n)   (tabTycon[(n)-TYCMIN].tuple)
+extern Tycon mkTuple ( Int );
+
+
 struct strTycon {
-    Text  text;
-    Int   line;
+    Text   text;
+    Int    line;
     Module mod;                         /* module that defines it          */
-    Int   arity;
-    Kind  kind;                         /* kind (includes arity) of Tycon  */
-    Cell  what;                         /* DATATYPE/SYNONYM/RESTRICTSYN... */
-    Cell  defn;
-    Name  conToTag;                     /* used in derived code            */
-    Name  tagToCon;
-    Tycon nextTyconHash;
+    Int    tuple;                      /* tuple number, or -1 if not tuple */
+    Int    arity;
+    Kind   kind;                        /* kind (includes arity) of Tycon  */
+    Cell   what;                        /* DATATYPE/SYNONYM/RESTRICTSYN... */
+    Cell   defn;
+    Name   conToTag;                    /* used in derived code            */
+    Name   tagToCon;
+    void*  itbl;                       /* For tuples, the info tbl pointer */
+    Tycon  nextTyconHash;
 };
 
 extern struct strTycon DECTABLE(tabTycon);
@@ -437,11 +577,16 @@ extern Tycon findQualTycon Args((Cell));
 extern Tycon addPrimTycon Args((Text,Kind,Int,Cell,Cell));
 
 #define isSynonym(h)    (isTycon(h) && tycon(h).what==SYNONYM)
+#define isQualType(t)  (isPair(t) && fst(t)==QUAL)
 #define mkPolyType(n,t) pair(POLYTYPE,pair(n,t))
 #define isPolyType(t)   (isPair(t) && fst(t)==POLYTYPE)
+#define isPolyOrQualType(t) (isPair(t) && (fst(t)==POLYTYPE || fst(t)==QUAL))
 #define polySigOf(t)    fst(snd(t))
 #define monotypeOf(t)   snd(snd(t))
 
+#define bang(t)         ap(BANG,t)
+extern Tycon findQualTyconWithoutConsultingExportList ( QualId q );
+
 /* --------------------------------------------------------------------------
  * Globally defined name values:
  * ------------------------------------------------------------------------*/
@@ -461,12 +606,10 @@ struct strName {
     Int    number;
     Cell   type;
     Cell   defn;
-    Cell   stgVar;        /* really StgVar   */
-    Int    stgSize;       /* == stgSize(stgVarBody(.stgVar)) */
-    Bool   inlineMe;      /* self-evident    */
-    Bool   simplified;    /* TRUE => already simplified */
-    Bool   isDBuilder;    /* TRUE => is a dictionary builder */
-    const void*  primop;  /* really StgPrim* */
+    Cell   stgVar;                                      /* really StgVar   */
+    Text   callconv;                          /* for foreign import/export */
+    void*  primop;                                      /* really StgPrim* */
+    void*  itbl;                 /* For constructors, the info tbl pointer */
     Name   nextNameHash;
 };
 
@@ -511,6 +654,9 @@ extern Name   addPrimCfun     Args((Text,Int,Int,Cell));
 extern Name   addPrimCfunREP  Args((Text,Int,Int,Int));
 extern Int    sfunPos         Args((Name,Name));
 extern Name   nameFromStgVar  Args((Cell));
+extern Name   jrsFindQualName Args((Text,Text));
+
+extern Name findQualNameWithoutConsultingExportList ( QualId q );
 
 /* --------------------------------------------------------------------------
  * Type class values:
@@ -523,15 +669,15 @@ extern Name   nameFromStgVar  Args((Cell));
 #define inst(in)     tabInst[(in)-INSTMIN]
 
 struct strInst {
-    Class c;                            /* class C                         */
-    Int   line;
-  //Module mod;                         /* module that defines it          */
-    Kinds kinds;                        /* Kinds of variables in head      */
-    Cell  head;                         /* :: Pred                         */
-    List  specifics;                    /* :: [Pred]                       */
-    Int   numSpecifics;                 /* length(specifics)               */
-    List  implements;
-    Name  builder;                      /* Dictionary constructor function */
+    Class  c;                           /* class C                         */
+    Int    line;
+    Module mod;                         /* module that defines it          */
+    Kinds  kinds;                       /* Kinds of variables in head      */
+    Cell   head;                        /* :: Pred                         */
+    List   specifics;                   /* :: [Pred]                       */
+    Int    numSpecifics;                /* length(specifics)               */
+    List   implements;
+    Name   builder;                     /* Dictionary constructor function */
 };
 
 /* a predicate (an element :: Pred) is an application of a Class to one or
@@ -550,6 +696,8 @@ struct strClass {
     Int    level;                       /* Level in class hierarchy        */
     Int    arity;                       /* Number of arguments             */
     Kinds  kinds;                       /* Kinds of constructors in class  */
+    List   fds;                                /* Functional Dependencies         */
+    List   xfds;                       /* Xpanded Functional Dependencies */
     Cell   head;                        /* Head of class                   */
     Name   dcon;                        /* Dictionary constructor function */
     List   supers;                      /* :: [Pred]                       */
@@ -557,7 +705,6 @@ struct strClass {
     List   dsels;                       /* Superclass dictionary selectors */
     List   members;                     /* :: [Name]                       */
     Int    numMembers;                  /* length(members)                 */
-    Name   dbuild;                      /* Default dictionary builder      */
     List   defaults;                    /* :: [Name]                       */
     List   instances;                   /* :: [Inst]                       */
 };
@@ -573,6 +720,8 @@ extern Class findQualClass Args((Cell));
 extern Inst  newInst       Args((Void));
 extern Inst  findFirstInst Args((Tycon));
 extern Inst  findNextInst  Args((Tycon,Inst));
+extern List getAllKnownTyconsAndClasses ( void );
+extern Class findQualClassWithoutConsultingExportList ( QualId q );
 
 /* --------------------------------------------------------------------------
  * Character values:
@@ -637,6 +786,7 @@ extern  Cell         cellRevAssoc Args((Cell,List));
 extern  Bool         eqList       Args((List,List));
 extern  Cell         varIsMember  Args((Text,List));
 extern  Name         nameIsMember Args((Text,List));
+extern  QualId       qualidIsMember ( QualId, List );
 extern  Cell         intIsMember  Args((Int,List));
 extern  List         replicate    Args((Int,Cell));
 extern  List         diffList     Args((List,List));    /* destructive     */
@@ -646,6 +796,7 @@ extern  List         splitAt      Args((Int,List));     /* non-destructive */
 extern  Cell         nth          Args((Int,List));
 extern  List         removeCell   Args((Cell,List));    /* destructive     */
 extern  List         dupListOnto  Args((List,List));    /* non-destructive */ 
+extern  List         nubList      Args((List));         /* non-destructive */
 
 /* The following macros provide `inline expansion' of some common ways of
  * traversing, using and modifying lists:
@@ -677,6 +828,52 @@ extern  List         dupListOnto  Args((List,List));    /* non-destructive */
 #define map2Accum(_f,_acc,_a,_b,_xs)    mapBasic(_xs,_acc=_f(_acc,_a,_b,hd(Zs)))
 #define map3Accum(_f,_acc,_a,_b,_c,_xs) mapBasic(_xs,_acc=_f(_acc,_a,_b,_c,hd(Zs)))
 
+
+/* --------------------------------------------------------------------------
+ * Strongly-typed lists (z-lists) and tuples (experimental)
+ * ------------------------------------------------------------------------*/
+
+typedef Cell ZPair;
+typedef Cell ZTriple;
+typedef Cell Z4Ble;
+typedef Cell Z5Ble;
+
+#if 0
+typedef Cell ZList;
+extern Cell  zcons ( Cell x, Cell xs );
+extern Cell  zhd ( Cell xs );
+extern Cell  ztl ( Cell xs );
+extern Cell  zsingleton ( Cell x );
+extern Cell  zdoubleton ( Cell x, Cell y );
+extern Int   zlength ( ZList xs );
+extern ZList zreverse ( ZList xs );
+#endif
+
+extern Cell zpair ( Cell x1, Cell x2 );
+extern Cell zfst ( Cell zpair );
+extern Cell zsnd ( Cell zpair );
+
+extern Cell ztriple ( Cell x1, Cell x2, Cell x3 );
+extern Cell zfst3 ( Cell zpair );
+extern Cell zsnd3 ( Cell zpair );
+extern Cell zthd3 ( Cell zpair );
+
+extern Cell z4ble ( Cell x1, Cell x2, Cell x3, Cell x4 );
+extern Cell zsel14 ( Cell zpair );
+extern Cell zsel24 ( Cell zpair );
+extern Cell zsel34 ( Cell zpair );
+extern Cell zsel44 ( Cell zpair );
+
+extern Cell z5ble ( Cell x1, Cell x2, Cell x3, Cell x4, Cell x5 );
+extern Cell zsel15 ( Cell zpair );
+extern Cell zsel25 ( Cell zpair );
+extern Cell zsel35 ( Cell zpair );
+extern Cell zsel45 ( Cell zpair );
+extern Cell zsel55 ( Cell zpair );
+
+extern Cell unap ( int tag, Cell c );
+#define isZPair(c) (whatIs((c))==ZTUP2)
+
 /* --------------------------------------------------------------------------
  * Implementation of function application nodes:
  * ------------------------------------------------------------------------*/
@@ -714,7 +911,7 @@ extern  StackPtr sp;
     chkStack(1);     \
     onto(c);         \
   } while (0)
-#define onto(c)      stack(++sp)=(c)
+#define onto(c)      stack(++sp)=(c);
 #define pop()        stack(sp--)
 #define drop()       sp--
 #define top()        stack(sp)
@@ -724,6 +921,15 @@ extern  StackPtr sp;
 
 extern  Void hugsStackOverflow Args((Void));
 
+#if SYMANTEC_C
+#include <Memory.h>
+#define STACK_HEADROOM 16384
+#define STACK_CHECK if (StackSpace() <= STACK_HEADROOM) \
+                     internal("Macintosh function parameter stack overflow.");
+#else
+#define STACK_CHECK
+#endif
+
 /* --------------------------------------------------------------------------
  * Script file control:
  * The implementation of script file storage is hidden.
@@ -856,4 +1062,22 @@ extern  Cell   getLastExpr       Args((Void));
 extern  List   addTyconsMatching Args((String,List));
 extern  List   addNamesMatching  Args((String,List));
 
+extern Tycon findTyconInAnyModule ( Text t );
+extern Class findClassInAnyModule ( Text t );
+extern Name  findNameInAnyModule ( Text t );
+extern Void  print Args((Cell, Int));
+extern void dumpTycon ( Int t );
+extern void dumpName ( Int n );
+extern void dumpClass ( Int c );
+extern void dumpInst ( Int i );
+extern void locateSymbolByName ( Text t );
+
+#if LEADING_UNDERSCORE
+#define MAYBE_LEADING_UNDERSCORE(sss)     _##sss
+#define MAYBE_LEADING_UNDERSCORE_STR(sss) "_" sss
+#else
+#define MAYBE_LEADING_UNDERSCORE(sss)     sss
+#define MAYBE_LEADING_UNDERSCORE_STR(sss) sss
+#endif
+
 /*-------------------------------------------------------------------------*/