/* -------------------------------------------------------------------------- * 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. * * $RCSfile: storage.h,v $ * $Revision: 1.8 $ * $Date: 1999/07/06 15:24:45 $ * ------------------------------------------------------------------------*/ /* -------------------------------------------------------------------------- * Typedefs for main data types: * Many of these type names are used to indicate the intended us of a data * item, rather than for type checking purposes. Sadly (although sometimes, * fortunately), the C compiler cannot distinguish between the use of two * different names defined to be synonyms for the same types. * ------------------------------------------------------------------------*/ typedef Int Text; /* text string */ typedef Unsigned Syntax; /* syntax (assoc,preced) */ typedef Int Cell; /* general cell value */ typedef Cell far *Heap; /* storage of heap */ typedef Cell Pair; /* pair cell */ typedef Int StackPtr; /* stack pointer */ typedef Cell Offset; /* offset/generic variable*/ typedef Int Script; /* script file number */ typedef Int Module; /* module */ typedef Cell Tycon; /* type constructor */ typedef Cell Type; /* type expression */ typedef Cell Kind; /* kind expression */ typedef Cell Kinds; /* list of kinds */ typedef Cell Constr; /* constructor expression */ typedef Cell Name; /* named value */ typedef Cell Class; /* type class */ typedef Cell Inst; /* instance of type class */ typedef Cell Triple; /* triple of cell values */ typedef Cell List; /* list of cells */ typedef Cell Bignum; /* bignum integer */ typedef Cell Float; /* floating pt literal */ #if TREX typedef Cell Ext; /* extension label */ #endif /* -------------------------------------------------------------------------- * 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)); /* Variants of textToStr and syntaxOf which work for idents, ops whether * qualified or unqualified. */ extern String identToStr Args((Cell)); extern Syntax identSyntax Args((Cell)); extern Syntax defaultSyntax Args((Text)); /* -------------------------------------------------------------------------- * Specification of syntax (i.e. default written form of application) * ------------------------------------------------------------------------*/ #define MIN_PREC 0 /* weakest binding operator */ #define MAX_PREC 9 /* strongest binding operator */ #define FUN_PREC (MAX_PREC+2) /* binding of function symbols */ #define DEF_PREC MAX_PREC #define APPLIC 0 /* written applicatively */ #define LEFT_ASS 1 /* left associative infix */ #define RIGHT_ASS 2 /* right associative infix */ #define NON_ASS 3 /* non associative infix */ #define DEF_ASS LEFT_ASS #define UMINUS_PREC 6 /* Change these settings at your */ #define UMINUS_ASSOC LEFT_ASS /* own risk; they may not work! */ #define assocOf(x) ((x)&NON_ASS) #define precOf(x) ((x)>>2) #define mkSyntax(a,p) ((a)|((p)<<2)) #define DEF_OPSYNTAX mkSyntax(DEF_ASS,DEF_PREC) #define NO_SYNTAX (-1) extern Void addSyntax Args((Int,Text,Syntax)); extern Syntax syntaxOf Args((Text)); /* -------------------------------------------------------------------------- * Heap storage: * Provides a garbage collectable heap for storage of expressions etc. * ------------------------------------------------------------------------*/ #define heapAlloc(s) (Heap)(farCalloc(s,sizeof(Cell))) #define heapBuilt() (heapFst) extern Int heapSize; extern Heap heapFst, heapSnd; extern Heap heapTopFst; extern Heap heapTopSnd; extern Bool consGC; /* Set to FALSE to turn off gc from*/ /* C stack; use with extreme care! */ extern Int cellsRecovered; /* cells recovered by last gc */ #define fst(c) heapTopFst[c] #define snd(c) heapTopSnd[c] extern Pair pair Args((Cell,Cell)); extern Void garbageCollect Args((Void)); extern Void overwrite Args((Pair,Pair)); extern Void overwrite2 Args((Pair,Cell,Cell)); extern Cell markExpr Args((Cell)); extern Void markWithoutMove Args((Cell)); #define mark(v) v=markExpr(v) #define isPair(c) ((c)<0) #define isGenPair(c) ((c)<0 && -heapSize<=(c)) extern Cell whatIs Args((Cell)); /* -------------------------------------------------------------------------- * Box cell tags are used as the fst element of a pair to indicate that * the snd element of the pair is to be treated in some special way, other * than as a Cell. Examples include holding integer values, variable name * and string text etc. * ------------------------------------------------------------------------*/ #define TAGMIN 1 /* Box and constructor cell tag values */ #define BCSTAG 20 /* Box=TAGMIN..BCSTAG-1 */ #define isTag(c) (TAGMIN<=(c) && (c)