2 /* --------------------------------------------------------------------------
3 * Primitives for manipulating global data structures
5 * The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the
6 * Yale Haskell Group, and the Oregon Graduate Institute of Science and
7 * Technology, 1994-1999, All rights reserved. It is distributed as
8 * free software under the license in the file "License", which is
9 * included in the distribution.
11 * $RCSfile: storage.c,v $
13 * $Date: 1999/12/17 16:34:08 $
14 * ------------------------------------------------------------------------*/
24 /*#define DEBUG_SHOWUSE*/
26 /* --------------------------------------------------------------------------
27 * local function prototypes:
28 * ------------------------------------------------------------------------*/
30 static Int local hash Args((String));
31 static Int local saveText Args((Text));
32 static Module local findQualifier Args((Text));
33 static Void local hashTycon Args((Tycon));
34 static List local insertTycon Args((Tycon,List));
35 static Void local hashName Args((Name));
36 static List local insertName Args((Name,List));
37 static Void local patternError Args((String));
38 static Bool local stringMatch Args((String,String));
39 static Bool local typeInvolves Args((Type,Type));
40 static Cell local markCell Args((Cell));
41 static Void local markSnd Args((Cell));
42 static Cell local lowLevelLastIn Args((Cell));
43 static Cell local lowLevelLastOut Args((Cell));
44 Module local moduleOfScript Args((Script));
45 Script local scriptThisFile Args((Text));
47 /* --------------------------------------------------------------------------
50 * provides storage for the characters making up identifier and symbol
51 * names, string literals, character constants etc...
53 * All character strings are stored in a large character array, with textHw
54 * pointing to the next free position. Lookup in the array is improved using
55 * a hash table. Internally, text strings are represented by integer offsets
56 * from the beginning of the array to the string in question.
58 * Where memory permits, the use of multiple hashtables gives a significant
59 * increase in performance, particularly when large source files are used.
61 * Each string in the array is terminated by a zero byte. No string is
62 * stored more than once, so that it is safe to test equality of strings by
63 * comparing the corresponding offsets.
65 * Special text values (beyond the range of the text array table) are used
66 * to generate unique `new variable names' as required.
68 * The same text storage is also used to hold text values stored in a saved
69 * expression. This grows downwards from the top of the text table (and is
70 * not included in the hash table).
71 * ------------------------------------------------------------------------*/
73 #define TEXTHSZ 512 /* Size of Text hash table */
74 #define NOTEXT ((Text)(~0)) /* Empty bucket in Text hash table */
75 static Text textHw; /* Next unused position */
76 static Text savedText = NUM_TEXT; /* Start of saved portion of text */
77 static Text nextNewText; /* Next new text value */
78 static Text nextNewDText; /* Next new dict text value */
79 static char DEFTABLE(text,NUM_TEXT);/* Storage of character strings */
80 static Text textHash[TEXTHSZ][NUM_TEXTH]; /* Hash table storage */
82 String textToStr(t) /* find string corresp to given Text*/
84 static char newVar[16];
86 if (0<=t && t<NUM_TEXT) /* standard char string */
89 sprintf(newVar,"d%d",-t); /* dictionary variable */
91 sprintf(newVar,"v%d",t-NUM_TEXT); /* normal variable */
95 String identToStr(v) /*find string corresp to given ident or qualified name*/
98 internal("identToStr");
104 case CONOPCELL : return text+textOf(v);
106 case QUALIDENT : { Text pos = textHw;
108 while (pos+1 < savedText && text[t]!=0) {
109 text[pos++] = text[t++];
111 if (pos+1 < savedText) {
115 while (pos+1 < savedText && text[t]!=0) {
116 text[pos++] = text[t++];
122 internal("identToStr2");
123 return 0; /* NOTREACHED */
126 Text inventText() { /* return new unused variable name */
127 return nextNewText++;
130 Text inventDictText() { /* return new unused dictvar name */
131 return nextNewDText--;
134 Bool inventedText(t) /* Signal TRUE if text has been */
135 Text t; { /* generated internally */
136 return (t<0 || t>=NUM_TEXT);
139 #define MAX_FIXLIT 100
140 Text fixLitText(t) /* fix literal text that might include \ */
142 String s = textToStr(t);
145 for(i = 0;i < MAX_FIXLIT-2 && *s;s++) {
151 if (i < MAX_FIXLIT-2) {
154 ERRMSG(0) "storage space exhausted for internal literal string"
157 return (findText(p));
161 static Int local hash(s) /* Simple hash function on strings */
165 for (v=((int)(*s))*8; *s; s++)
166 v += ((int)(*s))*(j++);
172 Text findText(s) /* Locate string in Text array */
176 Text textPos = textHash[h][hashno];
178 #define TryMatch { Text originalTextPos = textPos; \
180 for (t=s; *t==text[textPos]; textPos++,t++) \
182 return originalTextPos; \
184 #define Skip while (text[textPos++]) ;
186 while (textPos!=NOTEXT) {
188 if (++hashno<NUM_TEXTH) /* look in next hashtable entry */
189 textPos = textHash[h][hashno];
192 while (textPos < textHw) {
203 textPos = textHw; /* if not found, save in array */
204 if (textHw + (Int)strlen(s) + 1 > savedText) {
205 ERRMSG(0) "Character string storage space exhausted"
208 while ((text[textHw++] = *s++) != 0) {
210 if (hashno<NUM_TEXTH) { /* updating hash table as necessary */
211 textHash[h][hashno] = textPos;
212 if (hashno<NUM_TEXTH-1)
213 textHash[h][hashno+1] = NOTEXT;
219 static Int local saveText(t) /* Save text value in buffer */
220 Text t; { /* at top of text table */
221 String s = textToStr(t);
224 if (textHw + l + 1 > savedText) {
225 ERRMSG(0) "Character string storage space exhausted"
229 strcpy(text+savedText,s);
234 static int fromHexDigit ( char c )
237 case '0': case '1': case '2': case '3': case '4':
238 case '5': case '6': case '7': case '8': case '9':
240 case 'a': case 'A': return 10;
241 case 'b': case 'B': return 11;
242 case 'c': case 'C': return 12;
243 case 'd': case 'D': return 13;
244 case 'e': case 'E': return 14;
245 case 'f': case 'F': return 15;
251 /* returns findText (unZencode s) */
252 Text unZcodeThenFindText ( String s )
259 nn = 100 + 10 * strlen(s);
261 if (!p) internal ("unZcodeThenFindText: malloc failed");
266 if (n > nn-90) internal ("unZcodeThenFindText: result is too big");
267 if (*s != 'z' && *s != 'Z') {
272 if (!(*s)) goto parse_error;
274 case 'Z': p[n++] = 'Z'; break;
275 case 'C': p[n++] = ':'; break;
276 case 'L': p[n++] = '('; break;
277 case 'R': p[n++] = ')'; break;
278 case 'M': p[n++] = '['; break;
279 case 'N': p[n++] = ']'; break;
280 case 'z': p[n++] = 'z'; break;
281 case 'a': p[n++] = '&'; break;
282 case 'b': p[n++] = '|'; break;
283 case 'd': p[n++] = '$'; break;
284 case 'e': p[n++] = '='; break;
285 case 'g': p[n++] = '>'; break;
286 case 'h': p[n++] = '#'; break;
287 case 'i': p[n++] = '.'; break;
288 case 'l': p[n++] = '<'; break;
289 case 'm': p[n++] = '-'; break;
290 case 'n': p[n++] = '!'; break;
291 case 'p': p[n++] = '+'; break;
292 case 'q': p[n++] = '\\'; break;
293 case 'r': p[n++] = '\''; break;
294 case 's': p[n++] = '/'; break;
295 case 't': p[n++] = '*'; break;
296 case 'u': p[n++] = '^'; break;
297 case 'v': p[n++] = '%'; break;
299 if (!s[0] || !s[1]) goto parse_error;
300 if (fromHexDigit(s[0]) < 0 || fromHexDigit(s[1]) < 0) goto parse_error;
301 p[n++] = 16 * fromHexDigit(s[0]) + fromHexDigit(s[1]);
304 case '0': case '1': case '2': case '3': case '4':
305 case '5': case '6': case '7': case '8': case '9':
308 while (*s && isdigit((int)(*s))) {
309 i = 10 * i + (*s - '0');
312 if (*s != 'T') goto parse_error;
315 while (i > 0) { p[n++] = ','; i--; };
329 fprintf ( stderr, "\nstring = `%s'\n", s );
330 internal ( "unZcodeThenFindText: parse error on above string");
331 return NIL; /*notreached*/
335 Text enZcodeThenFindText ( String s )
340 char toHex[16] = "0123456789ABCDEF";
343 nn = 100 + 10 * strlen(s);
345 if (!p) internal ("enZcodeThenFindText: malloc failed");
349 if (n > nn-90) internal ("enZcodeThenFindText: result is too big");
352 && (isalnum((int)(*s)) || *s == '_')) {
357 case '(': p[n++] = 'Z'; p[n++] = 'L'; break;
358 case ')': p[n++] = 'Z'; p[n++] = 'R'; break;
359 case '[': p[n++] = 'Z'; p[n++] = 'M'; break;
360 case ']': p[n++] = 'Z'; p[n++] = 'N'; break;
361 case ':': p[n++] = 'Z'; p[n++] = 'C'; break;
362 case 'Z': p[n++] = 'Z'; p[n++] = 'Z'; break;
363 case 'z': p[n++] = 'z'; p[n++] = 'z'; break;
364 case '&': p[n++] = 'z'; p[n++] = 'a'; break;
365 case '|': p[n++] = 'z'; p[n++] = 'b'; break;
366 case '$': p[n++] = 'z'; p[n++] = 'd'; break;
367 case '=': p[n++] = 'z'; p[n++] = 'e'; break;
368 case '>': p[n++] = 'z'; p[n++] = 'g'; break;
369 case '#': p[n++] = 'z'; p[n++] = 'h'; break;
370 case '.': p[n++] = 'z'; p[n++] = 'i'; break;
371 case '<': p[n++] = 'z'; p[n++] = 'l'; break;
372 case '-': p[n++] = 'z'; p[n++] = 'm'; break;
373 case '!': p[n++] = 'z'; p[n++] = 'n'; break;
374 case '+': p[n++] = 'z'; p[n++] = 'p'; break;
375 case '\'': p[n++] = 'z'; p[n++] = 'q'; break;
376 case '\\': p[n++] = 'z'; p[n++] = 'r'; break;
377 case '/': p[n++] = 'z'; p[n++] = 's'; break;
378 case '*': p[n++] = 'z'; p[n++] = 't'; break;
379 case '^': p[n++] = 'z'; p[n++] = 'u'; break;
380 case '%': p[n++] = 'z'; p[n++] = 'v'; break;
381 default: s--; p[n++] = 'z'; p[n++] = 'x';
382 p[n++] = toHex[(int)(*s)/16];
383 p[n++] = toHex[(int)(*s)%16];
394 Text textOf ( Cell c )
397 (whatIs(c)==VARIDCELL
398 || whatIs(c)==CONIDCELL
399 || whatIs(c)==VAROPCELL
400 || whatIs(c)==CONOPCELL
401 || whatIs(c)==STRCELL
402 || whatIs(c)==DICTVAR
405 fprintf(stderr, "\ntextOf: bad tag %d\n",whatIs(c) );
406 internal("textOf: bad tag");
411 /* --------------------------------------------------------------------------
414 * Currently, the only attributes that we store for each Ext value is the
415 * corresponding Text label. At some later stage, we may decide to cache
416 * types, predicates, etc. here as a space saving gesture. Given that Text
417 * comparison is cheap, and that this is an experimental implementation, we
418 * will use a straightforward linear search to locate Ext values from their
419 * corresponding Text labels; a hashing scheme can be introduced later if
420 * this turns out to be a problem.
421 * ------------------------------------------------------------------------*/
424 Text DEFTABLE(tabExt,NUM_EXT); /* Storage for Ext names */
427 Ext mkExt(t) /* Allocate or find an Ext value */
433 if (extHw-EXTMIN >= NUM_EXT) {
434 ERRMSG(0) "Ext storage space exhausted"
442 /* --------------------------------------------------------------------------
445 * A Tycon represents a user defined type constructor. Tycons are indexed
446 * by Text values ... a very simple hash function is used to improve lookup
447 * times. Tycon entries with the same hash code are chained together, with
448 * the most recent entry at the front of the list.
449 * ------------------------------------------------------------------------*/
451 #define TYCONHSZ 256 /* Size of Tycon hash table*/
452 #define tHash(x) ((x)%TYCONHSZ) /* Tycon hash function */
453 static Tycon tyconHw; /* next unused Tycon */
454 static Tycon DEFTABLE(tyconHash,TYCONHSZ); /* Hash table storage */
455 struct strTycon DEFTABLE(tabTycon,NUM_TYCON); /* Tycon storage */
457 Tycon newTycon(t) /* add new tycon to tycon table */
460 if (tyconHw-TYCMIN >= NUM_TYCON) {
461 ERRMSG(0) "Type constructor storage space exhausted"
464 tycon(tyconHw).text = t; /* clear new tycon record */
465 tycon(tyconHw).kind = NIL;
466 tycon(tyconHw).defn = NIL;
467 tycon(tyconHw).what = NIL;
468 tycon(tyconHw).conToTag = NIL;
469 tycon(tyconHw).tagToCon = NIL;
470 tycon(tyconHw).tuple = -1;
471 tycon(tyconHw).mod = currentModule;
472 tycon(tyconHw).itbl = NULL;
473 module(currentModule).tycons = cons(tyconHw,module(currentModule).tycons);
474 tycon(tyconHw).nextTyconHash = tyconHash[h];
475 tyconHash[h] = tyconHw;
480 Tycon findTycon(t) /* locate Tycon in tycon table */
482 Tycon tc = tyconHash[tHash(t)];
484 while (nonNull(tc) && tycon(tc).text!=t)
485 tc = tycon(tc).nextTyconHash;
489 Tycon addTycon(tc) /* Insert Tycon in tycon table - if no clash is caused */
491 Tycon oldtc = findTycon(tycon(tc).text);
494 module(currentModule).tycons=cons(tc,module(currentModule).tycons);
500 static Void local hashTycon(tc) /* Insert Tycon into hash table */
502 assert(isTycon(tc) || isTuple(tc));
504 Text t = tycon(tc).text;
506 tycon(tc).nextTyconHash = tyconHash[h];
511 Tycon findQualTycon(id) /*locate (possibly qualified) Tycon in tycon table */
513 if (!isPair(id)) internal("findQualTycon");
517 return findTycon(textOf(id));
519 Text t = qtextOf(id);
520 Module m = findQualifier(qmodOf(id));
522 if (isNull(m)) return NIL;
523 for(es=module(m).exports; nonNull(es); es=tl(es)) {
525 if (isPair(e) && isTycon(fst(e)) && tycon(fst(e)).text==t)
530 default : internal("findQualTycon2");
532 return NIL; /* NOTREACHED */
535 Tycon addPrimTycon(t,kind,ar,what,defn) /* add new primitive type constr */
541 Tycon tc = newTycon(t);
543 tycon(tc).kind = kind;
544 tycon(tc).what = what;
545 tycon(tc).defn = defn;
546 tycon(tc).arity = ar;
550 static List local insertTycon(tc,ts) /* insert tycon tc into sorted list*/
555 String s = textToStr(tycon(tc).text);
557 while (nonNull(curr) && strCompare(s,textToStr(tycon(hd(curr)).text))>=0) {
558 if (hd(curr)==tc) /* just in case we get duplicates! */
564 tl(prev) = cons(tc,curr);
568 return cons(tc,curr);
571 List addTyconsMatching(pat,ts) /* Add tycons matching pattern pat */
572 String pat; /* to list of Tycons ts */
573 List ts; { /* Null pattern matches every tycon*/
574 Tycon tc; /* (Tycons with NIL kind excluded) */
575 for (tc=TYCMIN; tc<tyconHw; ++tc)
576 if (!pat || stringMatch(pat,textToStr(tycon(tc).text)))
577 if (nonNull(tycon(tc).kind))
578 ts = insertTycon(tc,ts);
582 Text ghcTupleText_n ( Int n )
586 if (n < 0 || n >= 100) internal("ghcTupleText_n");
588 for (i = 1; i <= n; i++) buf[i] = ',';
591 return findText(buf);
594 Text ghcTupleText(tup)
597 assert(isTuple(tup));
599 return ghcTupleText_n ( tupleOf(tup) );
603 Tycon mkTuple ( Int n )
607 internal("mkTuple: request for tuple of unsupported size");
608 for (i = TYCMIN; i < tyconHw; i++)
609 if (tycon(i).tuple == n) return i;
610 internal("mkTuple: request for non-existent tuple");
614 /* --------------------------------------------------------------------------
617 * A Name represents a top level binding of a value to an identifier.
618 * Such values may be a constructor function, a member function in a
619 * class, a user-defined or primitive value/function.
621 * Names are indexed by Text values ... a very simple hash functions speeds
622 * access to the table of Names and Name entries with the same hash value
623 * are chained together, with the most recent entry at the front of the
625 * ------------------------------------------------------------------------*/
627 #define NAMEHSZ 256 /* Size of Name hash table */
628 #define nHash(x) ((x)%NAMEHSZ) /* hash fn :: Text->Int */
629 Name nameHw; /* next unused name */
630 static Name DEFTABLE(nameHash,NAMEHSZ); /* Hash table storage */
631 struct strName DEFTABLE(tabName,NUM_NAME); /* Name table storage */
633 Name newName(t,parent) /* Add new name to name table */
637 if (nameHw-NAMEMIN >= NUM_NAME) {
638 ERRMSG(0) "Name storage space exhausted"
641 name(nameHw).text = t; /* clear new name record */
642 name(nameHw).line = 0;
643 name(nameHw).syntax = NO_SYNTAX;
644 name(nameHw).parent = parent;
645 name(nameHw).arity = 0;
646 name(nameHw).number = EXECNAME;
647 name(nameHw).defn = NIL;
648 name(nameHw).stgVar = NIL;
649 name(nameHw).callconv = NIL;
650 name(nameHw).type = NIL;
651 name(nameHw).primop = 0;
652 name(nameHw).mod = currentModule;
653 name(nameHw).itbl = NULL;
654 module(currentModule).names=cons(nameHw,module(currentModule).names);
655 name(nameHw).nextNameHash = nameHash[h];
656 nameHash[h] = nameHw;
660 Name findName(t) /* Locate name in name table */
662 Name n = nameHash[nHash(t)];
664 while (nonNull(n) && name(n).text!=t)
665 n = name(n).nextNameHash;
669 Name addName(nm) /* Insert Name in name table - if */
670 Name nm; { /* no clash is caused */
671 Name oldnm = findName(name(nm).text);
674 module(currentModule).names=cons(nm,module(currentModule).names);
680 static Void local hashName(nm) /* Insert Name into hash table */
687 name(nm).nextNameHash = nameHash[h];
691 Name findQualName(id) /* Locate (possibly qualified) name*/
692 Cell id; { /* in name table */
694 internal("findQualName");
700 return findName(textOf(id));
702 Text t = qtextOf(id);
703 Module m = findQualifier(qmodOf(id));
705 if (isNull(m)) return NIL;
706 for(es=module(m).exports; nonNull(es); es=tl(es)) {
708 if (isName(e) && name(e).text==t)
710 else if (isPair(e) && DOTDOT==snd(e)) {
711 List subentities = NIL;
714 && (tycon(c).what==DATATYPE || tycon(c).what==NEWTYPE))
715 subentities = tycon(c).defn;
717 subentities = cclass(c).members;
718 for(; nonNull(subentities); subentities=tl(subentities)) {
719 if (!isName(hd(subentities)))
720 internal("findQualName3");
721 if (name(hd(subentities)).text == t)
722 return hd(subentities);
728 default : internal("findQualName2");
730 return 0; /* NOTREACHED */
734 Name nameFromStgVar ( StgVar v )
737 for (n = NAMEMIN; n < nameHw; n++)
738 if (name(n).stgVar == v) return n;
742 void* getHugs_AsmObject_for ( char* s )
745 Text t = findText(s);
747 for (n = NAMEMIN; n < nameHw; n++)
748 if (name(n).text == t) break;
749 if (n == nameHw) internal("getHugs_AsmObject_for(1)");
751 if (!isStgVar(v) || !isPtr(stgVarInfo(v)))
752 internal("getHugs_AsmObject_for(2)");
753 return ptrOf(stgVarInfo(v));
756 /* --------------------------------------------------------------------------
757 * Primitive functions:
758 * ------------------------------------------------------------------------*/
760 Module findFakeModule ( Text t )
762 Module m = findModule(t);
764 if (!module(m).fake) internal("findFakeModule");
767 module(m).fake = TRUE;
773 Name addWiredInBoxingTycon
774 ( String modNm, String typeNm, String constrNm,
775 Int arity, Int no, Int rep )
779 Text modT = findText(modNm);
780 Text typeT = findText(typeNm);
781 Text conT = findText(constrNm);
782 Module m = findFakeModule(modT);
785 n = newName(conT,NIL);
786 name(n).arity = arity;
787 name(n).number = cfunNo(no);
789 name(n).primop = (void*)rep;
792 tycon(t).what = DATATYPE;
797 Tycon addTupleTycon ( Int n )
804 for (i = TYCMIN; i < tyconHw; i++)
805 if (tycon(i).tuple == n) return i;
808 m = findFakeModule(findText(n==0 ? "PrelBase" : "PrelTup")); else
809 m = findModule(findText("Prelude"));
813 for (i = 0; i < n; i++) k = ap(STAR,k);
814 t = newTycon(ghcTupleText_n(n));
817 tycon(t).what = DATATYPE;
822 Tycon addWiredInEnumTycon ( String modNm, String typeNm,
823 List /*of Text*/ constrs )
827 Text modT = findText(modNm);
828 Text typeT = findText(typeNm);
829 Module m = findFakeModule(modT);
833 tycon(t).kind = STAR;
834 tycon(t).what = DATATYPE;
836 constrs = reverse(constrs);
838 for (; nonNull(constrs); constrs=tl(constrs),i--) {
839 Text conT = hd(constrs);
840 Name con = newName(conT,t);
841 name(con).number = cfunNo(i);
843 tycon(t).defn = cons(con, tycon(t).defn);
849 Name addPrimCfunREP(t,arity,no,rep) /* add primitive constructor func */
850 Text t; /* sets rep, not type */
853 Int rep; { /* Really AsmRep */
854 Name n = newName(t,NIL);
855 name(n).arity = arity;
856 name(n).number = cfunNo(no);
858 name(n).primop = (void*)rep;
863 Name addPrimCfun(t,arity,no,type) /* add primitive constructor func */
868 Name n = newName(t,NIL);
869 name(n).arity = arity;
870 name(n).number = cfunNo(no);
876 Int sfunPos(s,c) /* Find position of field with */
877 Name s; /* selector s in constructor c. */
881 for (; nonNull(cns); cns=tl(cns))
883 return intOf(snd(hd(cns)));
885 return 0;/* NOTREACHED */
888 static List local insertName(nm,ns) /* insert name nm into sorted list */
893 String s = textToStr(name(nm).text);
895 while (nonNull(curr) && strCompare(s,textToStr(name(hd(curr)).text))>=0) {
896 if (hd(curr)==nm) /* just in case we get duplicates! */
902 tl(prev) = cons(nm,curr);
906 return cons(nm,curr);
909 List addNamesMatching(pat,ns) /* Add names matching pattern pat */
910 String pat; /* to list of names ns */
911 List ns; { /* Null pattern matches every name */
912 Name nm; /* (Names with NIL type, or hidden */
914 for (nm=NAMEMIN; nm<nameHw; ++nm) /* or invented names are excluded) */
915 if (!inventedText(name(nm).text) && nonNull(name(nm).type)) {
916 String str = textToStr(name(nm).text);
917 if (str[0]!='_' && (!pat || stringMatch(pat,str)))
918 ns = insertName(nm,ns);
922 List mns = module(currentModule).names;
923 for(; nonNull(mns); mns=tl(mns)) {
925 if (!inventedText(name(nm).text)) {
926 String str = textToStr(name(nm).text);
927 if (str[0]!='_' && (!pat || stringMatch(pat,str)))
928 ns = insertName(nm,ns);
935 /* --------------------------------------------------------------------------
936 * A simple string matching routine
937 * `*' matches any sequence of zero or more characters
938 * `?' matches any single character exactly
939 * `@str' matches the string str exactly (ignoring any special chars)
940 * `\c' matches the character c only (ignoring special chars)
941 * c matches the character c only
942 * ------------------------------------------------------------------------*/
944 static Void local patternError(s) /* report error in pattern */
946 ERRMSG(0) "%s in pattern", s
950 static Bool local stringMatch(pat,str) /* match string against pattern */
956 case '\0' : return (*str=='\0');
959 if (stringMatch(pat+1,str))
964 case '?' : if (*str++=='\0')
969 case '[' : { Bool found = FALSE;
970 while (*++pat!='\0' && *pat!=']')
971 if (!found && ( pat[0] == *str ||
980 patternError("missing `]'");
988 case '\\' : if (*++pat == '\0')
989 patternError("extra trailing `\\'");
991 default : if (*pat++ != *str++)
997 /* --------------------------------------------------------------------------
998 * Storage of type classes, instances etc...:
999 * ------------------------------------------------------------------------*/
1001 static Class classHw; /* next unused class */
1002 static List classes; /* list of classes in current scope */
1003 static Inst instHw; /* next unused instance record */
1005 struct strClass DEFTABLE(tabClass,NUM_CLASSES); /* table of class records */
1006 struct strInst far *tabInst; /* (pointer to) table of instances */
1008 Class newClass(t) /* add new class to class table */
1010 if (classHw-CLASSMIN >= NUM_CLASSES) {
1011 ERRMSG(0) "Class storage space exhausted"
1014 cclass(classHw).text = t;
1015 cclass(classHw).arity = 0;
1016 cclass(classHw).kinds = NIL;
1017 cclass(classHw).head = NIL;
1018 cclass(classHw).fds = NIL;
1019 cclass(classHw).xfds = NIL;
1020 cclass(classHw).dcon = NIL;
1021 cclass(classHw).supers = NIL;
1022 cclass(classHw).dsels = NIL;
1023 cclass(classHw).members = NIL;
1024 cclass(classHw).defaults = NIL;
1025 cclass(classHw).instances = NIL;
1026 classes=cons(classHw,classes);
1027 cclass(classHw).mod = currentModule;
1028 module(currentModule).classes=cons(classHw,module(currentModule).classes);
1032 Class classMax() { /* Return max Class in use ... */
1033 return classHw; /* This is a bit ugly, but it's not*/
1034 } /* worth a lot of effort right now */
1036 Class findClass(t) /* look for named class in table */
1040 for (cs=classes; nonNull(cs); cs=tl(cs)) {
1042 if (cclass(cl).text==t)
1048 Class addClass(c) /* Insert Class in class list */
1049 Class c; { /* - if no clash caused */
1050 Class oldc = findClass(cclass(c).text);
1052 classes=cons(c,classes);
1053 module(currentModule).classes=cons(c,module(currentModule).classes);
1060 Class findQualClass(c) /* Look for (possibly qualified) */
1061 Cell c; { /* class in class list */
1062 if (!isQualIdent(c)) {
1063 return findClass(textOf(c));
1065 Text t = qtextOf(c);
1066 Module m = findQualifier(qmodOf(c));
1070 for (es=module(m).exports; nonNull(es); es=tl(es)) {
1072 if (isPair(e) && isClass(fst(e)) && cclass(fst(e)).text==t)
1079 Inst newInst() { /* Add new instance to table */
1080 if (instHw-INSTMIN >= NUM_INSTS) {
1081 ERRMSG(0) "Instance storage space exhausted"
1084 inst(instHw).kinds = NIL;
1085 inst(instHw).head = NIL;
1086 inst(instHw).specifics = NIL;
1087 inst(instHw).implements = NIL;
1088 inst(instHw).builder = NIL;
1089 inst(instHw).mod = currentModule;
1095 extern Void printInst Args((Inst));
1099 Class cl = inst(in).c;
1100 Printf("%s-", textToStr(cclass(cl).text));
1101 printType(stdout,inst(in).t);
1103 #endif /* DEBUG_DICTS */
1105 Inst findFirstInst(tc) /* look for 1st instance involving */
1106 Tycon tc; { /* the type constructor tc */
1107 return findNextInst(tc,INSTMIN-1);
1110 Inst findNextInst(tc,in) /* look for next instance involving*/
1111 Tycon tc; /* the type constructor tc */
1112 Inst in; { /* starting after instance in */
1113 while (++in < instHw) {
1114 Cell pi = inst(in).head;
1115 for (; isAp(pi); pi=fun(pi))
1116 if (typeInvolves(arg(pi),tc))
1122 static Bool local typeInvolves(ty,tc) /* Test to see if type ty involves */
1123 Type ty; /* type constructor/tuple tc. */
1126 || (isAp(ty) && (typeInvolves(fun(ty),tc)
1127 || typeInvolves(arg(ty),tc)));
1131 /* Needed by finishGHCInstance to find classes, before the
1132 export list has been built -- so we can't use
1135 Class findQualClassWithoutConsultingExportList ( QualId q )
1145 t_class = textOf(q);
1148 t_class = qtextOf(q);
1151 for (cl = CLASSMIN; cl < classHw; cl++) {
1152 if (cclass(cl).text == t_class) {
1153 /* Class name is ok, but is this the right module? */
1154 if (isNull(t_mod) /* no module name specified */
1156 && t_mod == module(cclass(cl).mod).text)
1165 /* Same deal, except for Tycons. */
1166 Tycon findQualTyconWithoutConsultingExportList ( QualId q )
1176 t_tycon = textOf(q);
1179 t_tycon = qtextOf(q);
1182 for (tc = TYCMIN; tc < tyconHw; tc++) {
1183 if (tycon(tc).text == t_tycon) {
1184 /* Tycon name is ok, but is this the right module? */
1185 if (isNull(t_mod) /* no module name specified */
1187 && t_mod == module(tycon(tc).mod).text)
1196 /* Same deal, except for Names. */
1197 Name findQualNameWithoutConsultingExportList ( QualId q )
1203 assert(isQVar(q) || isQCon(q));
1205 if (isCon(q) || isVar(q)) {
1210 t_name = qtextOf(q);
1213 for (nm = NAMEMIN; nm < nameHw; nm++) {
1214 if (name(nm).text == t_name) {
1215 /* Name is ok, but is this the right module? */
1216 if (isNull(t_mod) /* no module name specified */
1218 && t_mod == module(name(nm).mod).text)
1227 /* returns List of QualId */
1228 List getAllKnownTyconsAndClasses ( void )
1233 for (tc = TYCMIN; tc < tyconHw; tc++) {
1234 /* almost certainly undue paranoia about duplicate avoidance, but .. */
1235 QualId q = mkQCon( module(tycon(tc).mod).text, tycon(tc).text );
1236 if (!qualidIsMember(q,xs))
1237 xs = cons ( q, xs );
1239 for (nw = CLASSMIN; nw < classHw; nw++) {
1240 QualId q = mkQCon( module(cclass(nw).mod).text, cclass(nw).text );
1241 if (!qualidIsMember(q,xs))
1242 xs = cons ( q, xs );
1247 /* --------------------------------------------------------------------------
1250 * Various parts of the system use a stack of cells. Most of the stack
1251 * operations are defined as macros, expanded inline.
1252 * ------------------------------------------------------------------------*/
1254 Cell DEFTABLE(cellStack,NUM_STACK); /* Storage for cells on stack */
1255 StackPtr sp; /* stack pointer */
1257 #if GIMME_STACK_DUMPS
1259 #define UPPER_DISP 5 /* # display entries on top of stack */
1260 #define LOWER_DISP 5 /* # display entries on bottom of stack*/
1262 Void hugsStackOverflow() { /* Report stack overflow */
1264 extern Cell evalRoots[];
1266 ERRMSG(0) "Control stack overflow" ETHEN
1269 if (rootsp>=UPPER_DISP+LOWER_DISP) {
1270 for (i=0; i<UPPER_DISP; i++) {
1271 ERRTEXT "\nwhile evaluating: " ETHEN
1272 ERREXPR(evalRoots[rootsp-i]);
1274 ERRTEXT "\n..." ETHEN
1275 for (i=LOWER_DISP-1; i>=0; i--) {
1276 ERRTEXT "\nwhile evaluating: " ETHEN
1277 ERREXPR(evalRoots[i]);
1281 for (i=rootsp; i>=0; i--) {
1282 ERRTEXT "\nwhile evaluating: " ETHEN
1283 ERREXPR(evalRoots[i]);
1291 #else /* !GIMME_STACK_DUMPS */
1293 Void hugsStackOverflow() { /* Report stack overflow */
1294 ERRMSG(0) "Control stack overflow"
1298 #endif /* !GIMME_STACK_DUMPS */
1300 /* --------------------------------------------------------------------------
1303 * A Module represents a user defined module.
1305 * Note: there are now two lookup mechanisms in the system:
1307 * 1) The exports from a module are stored in a big list.
1308 * We resolve qualified names, and import lists by linearly scanning
1309 * through this list.
1311 * 2) Unqualified imports and local definitions for the current module
1312 * are stored in hash tables (tyconHash and nameHash) or linear lists
1315 * ------------------------------------------------------------------------*/
1317 static Module moduleHw; /* next unused Module */
1318 struct Module DEFTABLE(tabModule,NUM_MODULE); /* Module storage */
1319 Module currentModule; /* Module currently being processed*/
1321 Bool isValidModule(m) /* is m a legitimate module id? */
1323 return (MODMIN <= m && m < moduleHw);
1326 Module newModule(t) /* add new module to module table */
1328 if (moduleHw-MODMIN >= NUM_MODULE) {
1329 ERRMSG(0) "Module storage space exhausted"
1332 module(moduleHw).text = t; /* clear new module record */
1333 module(moduleHw).qualImports = NIL;
1334 module(moduleHw).fake = FALSE;
1335 module(moduleHw).exports = NIL;
1336 module(moduleHw).tycons = NIL;
1337 module(moduleHw).names = NIL;
1338 module(moduleHw).classes = NIL;
1339 module(moduleHw).object = NULL;
1343 void ppModules ( void )
1346 fflush(stderr); fflush(stdout);
1347 printf ( "begin MODULES\n" );
1348 for (i = moduleHw-1; i >= MODMIN; i--)
1349 printf ( " %2d: %16s\n",
1350 i-MODMIN, textToStr(module(i).text)
1352 printf ( "end MODULES\n" );
1353 fflush(stderr); fflush(stdout);
1357 Module findModule(t) /* locate Module in module table */
1360 for(m=MODMIN; m<moduleHw; ++m) {
1361 if (module(m).text==t)
1367 Module findModid(c) /* Find module by name or filename */
1369 switch (whatIs(c)) {
1370 case STRCELL : { Script s = scriptThisFile(snd(c));
1371 return (s==-1) ? NIL : moduleOfScript(s);
1373 case CONIDCELL : return findModule(textOf(c));
1374 default : internal("findModid");
1376 return NIL;/*NOTUSED*/
1379 static local Module findQualifier(t) /* locate Module in import list */
1382 for (ms=module(currentModule).qualImports; nonNull(ms); ms=tl(ms)) {
1383 if (textOf(fst(hd(ms)))==t)
1387 if (module(currentModule).text==t)
1388 return currentModule;
1393 Void setCurrModule(m) /* set lookup tables for current module */
1396 assert(isModule(m));
1397 if (m!=currentModule) {
1398 currentModule = m; /* This is the only assignment to currentModule */
1399 for (i=0; i<TYCONHSZ; ++i)
1401 mapProc(hashTycon,module(m).tycons);
1402 for (i=0; i<NAMEHSZ; ++i)
1404 mapProc(hashName,module(m).names);
1405 classes = module(m).classes;
1409 Name jrsFindQualName ( Text mn, Text sn )
1414 for (m=MODMIN; m<moduleHw; m++)
1415 if (module(m).text == mn) break;
1416 if (m == moduleHw) return NIL;
1418 for (ns = module(m).names; nonNull(ns); ns=tl(ns))
1419 if (name(hd(ns)).text == sn) return hd(ns);
1425 char* nameFromOPtr ( void* p )
1429 for (m=MODMIN; m<moduleHw; m++) {
1430 char* nm = ocLookupAddr ( module(m).object, p );
1437 void* lookupOTabName ( Module m, char* sym )
1439 return ocLookupSym ( module(m).object, sym );
1443 OSectionKind lookupSection ( void* ad )
1447 for (m=MODMIN; m<moduleHw; m++) {
1449 = ocLookupSection ( module(m).object, ad );
1450 if (sect != HUGS_SECTIONKIND_NOINFOAVAIL)
1453 return HUGS_SECTIONKIND_OTHER;
1457 /* --------------------------------------------------------------------------
1458 * Script file storage:
1460 * script files are read into the system one after another. The state of
1461 * the stored data structures (except the garbage-collected heap) is recorded
1462 * before reading a new script. In the event of being unable to read the
1463 * script, or if otherwise requested, the system can be restored to its
1464 * original state immediately before the file was read.
1465 * ------------------------------------------------------------------------*/
1467 typedef struct { /* record of storage state prior to */
1468 Text file; /* reading script/module */
1482 #ifdef DEBUG_SHOWUSE
1483 static Void local showUse(msg,val,mx)
1486 Printf("%6s : %5d of %5d (%2d%%)\n",msg,val,mx,(100*val)/mx);
1490 static Script scriptHw; /* next unused script number */
1491 static script scripts[NUM_SCRIPTS]; /* storage for script records */
1494 void ppScripts ( void )
1497 fflush(stderr); fflush(stdout);
1498 printf ( "begin SCRIPTS\n" );
1499 for (i = scriptHw-1; i >= 0; i--)
1500 printf ( " %2d: %16s tH=%d mH=%d yH=%d "
1501 "nH=%d cH=%d iH=%d nnS=%d,%d\n",
1502 i, textToStr(scripts[i].file),
1503 scripts[i].textHw, scripts[i].moduleHw,
1504 scripts[i].tyconHw, scripts[i].nameHw,
1505 scripts[i].classHw, scripts[i].instHw,
1506 scripts[i].nextNewText, scripts[i].nextNewDText
1508 printf ( "end SCRIPTS\n" );
1509 fflush(stderr); fflush(stdout);
1512 Script startNewScript(f) /* start new script, keeping record */
1513 String f; { /* of status for later restoration */
1514 if (scriptHw >= NUM_SCRIPTS) {
1515 ERRMSG(0) "Too many script files in use"
1518 #ifdef DEBUG_SHOWUSE
1519 showUse("Text", textHw, NUM_TEXT);
1520 showUse("Module", moduleHw-MODMIN, NUM_MODULE);
1521 showUse("Tycon", tyconHw-TYCMIN, NUM_TYCON);
1522 showUse("Name", nameHw-NAMEMIN, NUM_NAME);
1523 showUse("Class", classHw-CLASSMIN, NUM_CLASSES);
1524 showUse("Inst", instHw-INSTMIN, NUM_INSTS);
1526 showUse("Ext", extHw-EXTMIN, NUM_EXT);
1529 scripts[scriptHw].file = findText( f ? f : "<nofile>" );
1530 scripts[scriptHw].textHw = textHw;
1531 scripts[scriptHw].nextNewText = nextNewText;
1532 scripts[scriptHw].nextNewDText = nextNewDText;
1533 scripts[scriptHw].moduleHw = moduleHw;
1534 scripts[scriptHw].tyconHw = tyconHw;
1535 scripts[scriptHw].nameHw = nameHw;
1536 scripts[scriptHw].classHw = classHw;
1537 scripts[scriptHw].instHw = instHw;
1539 scripts[scriptHw].extHw = extHw;
1544 Bool isPreludeScript() { /* Test whether this is the Prelude*/
1545 return (scriptHw==0);
1548 Bool moduleThisScript(m) /* Test if given module is defined */
1549 Module m; { /* in current script file */
1550 return scriptHw<1 || m>=scripts[scriptHw-1].moduleHw;
1553 Module lastModule() { /* Return module in current script file */
1554 return (moduleHw>MODMIN ? moduleHw-1 : modulePrelude);
1557 #define scriptThis(nm,t,tag) Script nm(x) \
1561 && x>=scripts[s].tag) \
1565 scriptThis(scriptThisName,Name,nameHw)
1566 scriptThis(scriptThisTycon,Tycon,tyconHw)
1567 scriptThis(scriptThisInst,Inst,instHw)
1568 scriptThis(scriptThisClass,Class,classHw)
1571 Module moduleOfScript(s)
1573 return (s==0) ? modulePrelude : scripts[s-1].moduleHw;
1576 String fileOfModule(m)
1579 if (m == modulePrelude) {
1582 for(s=0; s<scriptHw; ++s) {
1583 if (scripts[s].moduleHw == m) {
1584 return textToStr(scripts[s].file);
1590 Script scriptThisFile(f)
1593 for (s=0; s < scriptHw; ++s) {
1594 if (scripts[s].file == f) {
1598 if (f == findText(STD_PRELUDE)) {
1604 Void dropScriptsFrom(sno) /* Restore storage to state prior */
1605 Script sno; { /* to reading script sno */
1606 if (sno<scriptHw) { /* is there anything to restore? */
1608 textHw = scripts[sno].textHw;
1609 nextNewText = scripts[sno].nextNewText;
1610 nextNewDText = scripts[sno].nextNewDText;
1611 moduleHw = scripts[sno].moduleHw;
1612 tyconHw = scripts[sno].tyconHw;
1613 nameHw = scripts[sno].nameHw;
1614 classHw = scripts[sno].classHw;
1615 instHw = scripts[sno].instHw;
1617 dictHw = scripts[sno].dictHw;
1620 extHw = scripts[sno].extHw;
1624 for (i=moduleHw; i >= scripts[sno].moduleHw; --i) {
1625 if (module(i).objectFile) {
1626 printf("[bogus] closing objectFile for module %d\n",i);
1627 /*dlclose(module(i).objectFile);*/
1630 moduleHw = scripts[sno].moduleHw;
1632 for (i=0; i<TEXTHSZ; ++i) {
1634 while (j<NUM_TEXTH && textHash[i][j]!=NOTEXT
1635 && textHash[i][j]<textHw)
1638 textHash[i][j] = NOTEXT;
1642 for (i=0; i<TYCONHSZ; ++i) {
1645 for (i=0; i<NAMEHSZ; ++i) {
1649 for (i=CLASSMIN; i<classHw; i++) {
1650 List ins = cclass(i).instances;
1653 while (nonNull(ins)) {
1654 List temp = tl(ins);
1655 if (hd(ins)<instHw) {
1661 cclass(i).instances = rev(is);
1668 /* --------------------------------------------------------------------------
1671 * Provides a garbage collectable heap for storage of expressions etc.
1673 * Now incorporates a flat resource: A two-space collected extension of
1674 * the heap that provides storage for contiguous arrays of Cell storage,
1675 * cooperating with the garbage collection mechanisms for the main heap.
1676 * ------------------------------------------------------------------------*/
1678 Int heapSize = DEFAULTHEAP; /* number of cells in heap */
1679 Heap heapFst; /* array of fst component of pairs */
1680 Heap heapSnd; /* array of snd component of pairs */
1687 Bool consGC = TRUE; /* Set to FALSE to turn off gc from*/
1688 /* C stack; use with extreme care! */
1690 Int numGcs; /* number of garbage collections */
1691 Int cellsRecovered; /* number of cells recovered */
1693 static Cell freeList; /* free list of unused cells */
1694 static Cell lsave, rsave; /* save components of pair */
1698 static Int markCount, stackRoots;
1700 #define initStackRoots() stackRoots = 0
1701 #define recordStackRoot() stackRoots++
1714 #define start() markCount = 0
1715 #define end(thing,rs) \
1717 Printf("GC: %-18s: %4d cells, %4d roots.\n", thing, markCount, rs); \
1720 #define recordMark() markCount++
1722 #else /* !GC_STATISTICS */
1727 #define initStackRoots()
1728 #define recordStackRoot()
1731 #define end(thing,root)
1732 #define recordMark()
1734 #endif /* !GC_STATISTICS */
1736 Cell pair(l,r) /* Allocate pair (l, r) from */
1737 Cell l, r; { /* heap, garbage collecting first */
1738 Cell c = freeList; /* if necessary ... */
1750 freeList = snd(freeList);
1757 Void overwrite(dst,src) /* overwrite dst cell with src cell*/
1758 Cell dst, src; { /* both *MUST* be pairs */
1759 if (isPair(dst) && isPair(src)) {
1760 fst(dst) = fst(src);
1761 snd(dst) = snd(src);
1764 internal("overwrite");
1768 static Int marksSize;
1770 Cell markExpr(c) /* External interface to markCell */
1772 return isGenPair(c) ? markCell(c) : c;
1775 static Cell local markCell(c) /* Traverse part of graph marking */
1776 Cell c; { /* cells reachable from given root */
1777 /* markCell(c) is only called if c */
1779 { register int place = placeInSet(c);
1780 register int mask = maskInSet(c);
1781 if (marks[place]&mask)
1784 marks[place] |= mask;
1789 /* STACK_CHECK: Avoid stack overflows during recursive marking. */
1790 if (isGenPair(fst(c))) {
1792 fst(c) = markCell(fst(c));
1795 else if (isNull(fst(c)) || fst(c)>=BCSTAG) {
1803 static Void local markSnd(c) /* Variant of markCell used to */
1804 Cell c; { /* update snd component of cell */
1805 Cell t; /* using tail recursion */
1807 ma: t = c; /* Keep pointer to original pair */
1812 { register int place = placeInSet(c);
1813 register int mask = maskInSet(c);
1814 if (marks[place]&mask)
1817 marks[place] |= mask;
1822 if (isGenPair(fst(c))) {
1823 fst(c) = markCell(fst(c));
1826 else if (isNull(fst(c)) || fst(c)>=BCSTAG)
1831 Void markWithoutMove(n) /* Garbage collect cell at n, as if*/
1832 Cell n; { /* it was a cell ref, but don't */
1833 /* move cell so we don't have */
1834 /* to modify the stored value of n */
1841 Void garbageCollect() { /* Run garbage collector ... */
1842 Bool breakStat = breakOn(FALSE); /* disable break checking */
1848 jmp_buf regs; /* save registers on stack */
1852 for (i=0; i<marksSize; ++i) /* initialise mark set to empty */
1855 everybody(MARK); /* Mark all components of system */
1857 gcScanning(); /* scan mark set */
1864 for (i=1; i<=heapSize; i++) {
1865 if ((marks[place] & mask) == 0) {
1872 if (++j == bitsPerWord) {
1879 gcRecovered(recovered);
1880 breakOn(breakStat); /* restore break trapping if nec. */
1884 /* can only return if freeList is nonempty on return. */
1885 if (recovered<minRecovery || isNull(freeList)) {
1886 ERRMSG(0) "Garbage collection fails to reclaim sufficient space"
1889 cellsRecovered = recovered;
1892 /* --------------------------------------------------------------------------
1893 * Code for saving last expression entered:
1895 * This is a little tricky because some text values (e.g. strings or variable
1896 * names) may not be defined or have the same value when the expression is
1897 * recalled. These text values are therefore saved in the top portion of
1899 * ------------------------------------------------------------------------*/
1901 static Cell lastExprSaved; /* last expression to be saved */
1903 Void setLastExpr(e) /* save expression for later recall*/
1905 lastExprSaved = NIL; /* in case attempt to save fails */
1906 savedText = NUM_TEXT;
1907 lastExprSaved = lowLevelLastIn(e);
1910 static Cell local lowLevelLastIn(c) /* Duplicate expression tree (i.e. */
1911 Cell c; { /* acyclic graph) for later recall */
1912 if (isPair(c)) { /* Duplicating any text strings */
1913 if (isBoxTag(fst(c))) /* in case these are lost at some */
1914 switch (fst(c)) { /* point before the expr is reused */
1920 case STRCELL : return pair(fst(c),saveText(textOf(c)));
1921 default : return pair(fst(c),snd(c));
1924 return pair(lowLevelLastIn(fst(c)),lowLevelLastIn(snd(c)));
1928 return pair(EXTCOPY,saveText(extText(c)));
1934 Cell getLastExpr() { /* recover previously saved expr */
1935 return lowLevelLastOut(lastExprSaved);
1938 static Cell local lowLevelLastOut(c) /* As with lowLevelLastIn() above */
1939 Cell c; { /* except that Cells refering to */
1940 if (isPair(c)) { /* Text values are restored to */
1941 if (isBoxTag(fst(c))) /* appropriate values */
1948 case STRCELL : return pair(fst(c),
1949 findText(text+intValOf(c)));
1951 case EXTCOPY : return mkExt(findText(text+intValOf(c)));
1953 default : return pair(fst(c),snd(c));
1956 return pair(lowLevelLastOut(fst(c)),lowLevelLastOut(snd(c)));
1962 /* --------------------------------------------------------------------------
1963 * Miscellaneous operations on heap cells:
1964 * ------------------------------------------------------------------------*/
1966 /* Profiling suggests that the number of calls to whatIs() is typically */
1967 /* rather high. The recoded version below attempts to improve the average */
1968 /* performance for whatIs() using a binary search for part of the analysis */
1970 Cell whatIs(c) /* identify type of cell */
1973 register Cell fstc = fst(c);
1974 return isTag(fstc) ? fstc : AP;
1976 if (c<OFFMIN) return c;
1978 if (isExt(c)) return EXT;
1980 if (c>=INTMIN) return INTCELL;
1982 if (c>=NAMEMIN){if (c>=CLASSMIN) {if (c>=CHARMIN) return CHARCELL;
1984 else if (c>=INSTMIN) return INSTANCE;
1986 else if (c>=MODMIN) {if (c>=TYCMIN) return isTuple(c) ? TUPLE : TYCON;
1987 else return MODULE;}
1988 else if (c>=OFFMIN) return OFFSET;
1990 else return (c>=EXTMIN) ?
1997 register Cell fstc = fst(c);
1998 return isTag(fstc) ? fstc : AP;
2000 if (c>=INTMIN) return INTCELL;
2001 if (c>=CHARMIN) return CHARCELL;
2002 if (c>=CLASSMIN) return CLASS;
2003 if (c>=INSTMIN) return INSTANCE;
2004 if (c>=NAMEMIN) return NAME;
2005 if (c>=TYCMIN) return TYCON;
2006 if (c>=MODMIN) return MODULE;
2007 if (c>=OFFMIN) return OFFSET;
2009 if (c>=EXTMIN) return EXT;
2011 if (c>=TUPMIN) return TUPLE;
2016 /* A very, very simple printer.
2017 * Output is uglier than from printExp - but the printer is more
2018 * robust and can be used on any data structure irrespective of
2021 Void print Args((Cell, Int));
2022 Void print(c, depth)
2027 #if 0 /* Not in this version of Hugs */
2028 } else if (isPair(c) && !isGenPair(c)) {
2029 extern Void printEvalCell Args((Cell, Int));
2030 printEvalCell(c,depth);
2033 Int tag = whatIs(c);
2037 print(fst(c), depth-1);
2039 print(snd(c), depth-1);
2043 Printf("free(%d)", c);
2046 Printf("int(%d)", intOf(c));
2049 Printf("bignum(%s)", bignumToString(c));
2052 Printf("char('%c')", charOf(c));
2055 Printf("ptr(%p)",ptrOf(c));
2058 Printf("class(%d)", c-CLASSMIN);
2059 if (CLASSMIN <= c && c < classHw) {
2060 Printf("=\"%s\"", textToStr(cclass(c).text));
2064 Printf("instance(%d)", c - INSTMIN);
2067 Printf("name(%d)", c-NAMEMIN);
2068 if (NAMEMIN <= c && c < nameHw) {
2069 Printf("=\"%s\"", textToStr(name(c).text));
2073 Printf("tycon(%d)", c-TYCMIN);
2074 if (TYCMIN <= c && c < tyconHw)
2075 Printf("=\"%s\"", textToStr(tycon(c).text));
2078 Printf("module(%d)", c - MODMIN);
2081 Printf("Offset %d", offsetOf(c));
2084 Printf("%s", textToStr(ghcTupleText(c)));
2088 print(snd(c),depth-1);
2092 print(snd(c),depth-1);
2096 if (isPair(snd(c)) && isInt(fst(snd(c)))) {
2097 Printf("%d ", intOf(fst(snd(c))));
2098 print(snd(snd(c)),depth-1);
2100 print(snd(c),depth-1);
2117 Printf("{dict %d}",textOf(c));
2123 Printf("{id %s}",textToStr(textOf(c)));
2127 Printf("{ip %s}",textToStr(textOf(c)));
2130 Printf("?%s",textToStr(textOf(c)));
2134 Printf("{qid %s.%s}",textToStr(qmodOf(c)),textToStr(qtextOf(c)));
2138 print(fst(snd(c)),depth-1);
2140 print(snd(snd(c)),depth-1);
2145 print(snd(c),depth-1);
2150 print(snd(c),depth-1);
2155 print(fst(snd(c)),depth-1);
2157 print(snd(snd(c)),depth-1);
2162 print(fst(snd(c)),depth-1);
2164 print(snd(snd(c)),depth-1);
2168 Printf("FromQual(");
2169 print(fst(snd(c)),depth-1);
2171 print(snd(snd(c)),depth-1);
2175 Printf("StgVar%d=",-c);
2176 print(snd(c), depth-1);
2180 print(fst(snd(c)),depth-1);
2182 print(snd(snd(c)),depth-1);
2187 print(fst(snd(c)),depth-1);
2189 print(snd(snd(c)),depth-1);
2194 print(fst(snd(c)),depth-1);
2196 print(snd(snd(c)),depth-1);
2200 Printf("PrimCase(");
2201 print(fst(snd(c)),depth-1);
2203 print(snd(snd(c)),depth-1);
2208 print(snd(c),depth-1);
2212 Printf("(UNBOXEDTUP,");
2213 print(snd(c),depth-1);
2218 print(zfst(c),depth-1);
2220 print(zsnd(c),depth-1);
2224 Printf("<ZTriple ");
2225 print(zfst3(c),depth-1);
2227 print(zsnd3(c),depth-1);
2229 print(zthd3(c),depth-1);
2234 print(snd(c),depth-1);
2238 if (isBoxTag(tag)) {
2239 Printf("Tag(%d)=%d", c, tag);
2240 } else if (isConTag(tag)) {
2241 Printf("%d@(%d,",c,tag);
2242 print(snd(c), depth-1);
2245 } else if (c == tag) {
2246 Printf("Tag(%d)", c);
2248 Printf("Tag(%d)=%d", c, tag);
2257 Bool isVar(c) /* is cell a VARIDCELL/VAROPCELL ? */
2258 Cell c; { /* also recognises DICTVAR cells */
2260 (fst(c)==VARIDCELL || fst(c)==VAROPCELL || fst(c)==DICTVAR);
2263 Bool isCon(c) /* is cell a CONIDCELL/CONOPCELL ? */
2265 return isPair(c) && (fst(c)==CONIDCELL || fst(c)==CONOPCELL);
2268 Bool isQVar(c) /* is cell a [un]qualified varop/id? */
2270 if (!isPair(c)) return FALSE;
2273 case VAROPCELL : return TRUE;
2275 case QUALIDENT : return isVar(snd(snd(c)));
2277 default : return FALSE;
2281 Bool isQCon(c) /*is cell a [un]qualified conop/id? */
2283 if (!isPair(c)) return FALSE;
2286 case CONOPCELL : return TRUE;
2288 case QUALIDENT : return isCon(snd(snd(c)));
2290 default : return FALSE;
2294 Bool isQualIdent(c) /* is cell a qualified identifier? */
2296 return isPair(c) && (fst(c)==QUALIDENT);
2299 Bool eqQualIdent ( QualId c1, QualId c2 )
2301 assert(isQualIdent(c1));
2302 if (!isQualIdent(c2)) {
2303 assert(isQualIdent(c2));
2305 return qmodOf(c1)==qmodOf(c2) &&
2306 qtextOf(c1)==qtextOf(c2);
2309 Bool isIdent(c) /* is cell an identifier? */
2311 if (!isPair(c)) return FALSE;
2316 case CONOPCELL : return TRUE;
2318 case QUALIDENT : return TRUE;
2320 default : return FALSE;
2324 Bool isInt(c) /* cell holds integer value? */
2326 return isSmall(c) || (isPair(c) && fst(c)==INTCELL);
2329 Int intOf(c) /* find integer value of cell? */
2333 return isPair(c) ? (Int)(snd(c)) : (Int)(c-INTZERO);
2336 Cell mkInt(n) /* make cell representing integer */
2338 return (MINSMALLINT <= n && n <= MAXSMALLINT)
2343 #if SIZEOF_INTP == SIZEOF_INT
2344 typedef union {Int i; Ptr p;} IntOrPtr;
2350 return pair(PTRCELL,x.i);
2357 assert(fst(c) == PTRCELL);
2366 return pair(CPTRCELL,x.i);
2373 assert(fst(c) == CPTRCELL);
2377 #elif SIZEOF_INTP == 2*SIZEOF_INT
2378 typedef union {struct {Int i1; Int i2;} i; Ptr p;} IntOrPtr;
2384 return pair(PTRCELL,pair(mkInt(x.i.i1),mkInt(x.i.i2)));
2391 assert(fst(c) == PTRCELL);
2392 x.i.i1 = intOf(fst(snd(c)));
2393 x.i.i2 = intOf(snd(snd(c)));
2397 #warning "type Addr not supported on this architecture - don't use it"
2401 ERRMSG(0) "mkPtr: type Addr not supported on this architecture"
2408 ERRMSG(0) "ptrOf: type Addr not supported on this architecture"
2413 String stringNegate( s )
2421 strcpy(&t[1],s); /* ToDo: use strncpy instead */
2426 /* --------------------------------------------------------------------------
2428 * ------------------------------------------------------------------------*/
2430 Int length(xs) /* calculate length of list xs */
2433 for (; nonNull(xs); ++n)
2438 List appendOnto(xs,ys) /* Destructively prepend xs onto */
2439 List xs, ys; { /* ys by modifying xs ... */
2444 while (nonNull(tl(zs)))
2451 List dupOnto(xs,ys) /* non-destructively prepend xs backwards onto ys */
2454 for (; nonNull(xs); xs=tl(xs))
2455 ys = cons(hd(xs),ys);
2459 List dupListOnto(xs,ys) /* Duplicate spine of list xs onto ys */
2462 return revOnto(dupOnto(xs,NIL),ys);
2465 List dupList(xs) /* Duplicate spine of list xs */
2468 for (; nonNull(xs); xs=tl(xs))
2469 ys = cons(hd(xs),ys);
2473 List revOnto(xs,ys) /* Destructively reverse elements of*/
2474 List xs, ys; { /* list xs onto list ys... */
2477 while (nonNull(xs)) {
2486 QualId qualidIsMember ( QualId q, List xs )
2488 for (; nonNull(xs); xs=tl(xs)) {
2489 if (eqQualIdent(q, hd(xs)))
2495 Cell varIsMember(t,xs) /* Test if variable is a member of */
2496 Text t; /* given list of variables */
2498 for (; nonNull(xs); xs=tl(xs))
2499 if (t==textOf(hd(xs)))
2504 Name nameIsMember(t,ns) /* Test if name with text t is a */
2505 Text t; /* member of list of names xs */
2507 for (; nonNull(ns); ns=tl(ns))
2508 if (t==name(hd(ns)).text)
2513 Cell intIsMember(n,xs) /* Test if integer n is member of */
2514 Int n; /* given list of integers */
2516 for (; nonNull(xs); xs=tl(xs))
2517 if (n==intOf(hd(xs)))
2522 Cell cellIsMember(x,xs) /* Test for membership of specific */
2523 Cell x; /* cell x in list xs */
2525 for (; nonNull(xs); xs=tl(xs))
2531 Cell cellAssoc(c,xs) /* Lookup cell in association list */
2534 for (; nonNull(xs); xs=tl(xs))
2540 Cell cellRevAssoc(c,xs) /* Lookup cell in range of */
2541 Cell c; /* association lists */
2543 for (; nonNull(xs); xs=tl(xs))
2549 List replicate(n,x) /* create list of n copies of x */
2558 List diffList(from,take) /* list difference: from\take */
2559 List from, take; { /* result contains all elements of */
2560 List result = NIL; /* `from' not appearing in `take' */
2562 while (nonNull(from)) {
2563 List next = tl(from);
2564 if (!cellIsMember(hd(from),take)) {
2573 List deleteCell(xs, y) /* copy xs deleting pointers to y */
2577 for(;nonNull(xs);xs=tl(xs)) {
2580 result=cons(x,result);
2586 List take(n,xs) /* destructively truncate list to */
2587 Int n; /* specified length */
2593 while (1<n-- && nonNull(xs))
2600 List splitAt(n,xs) /* drop n things from front of list*/
2609 Cell nth(n,xs) /* extract n'th element of list */
2612 for(; n>0 && nonNull(xs); --n, xs=tl(xs)) {
2619 List removeCell(x,xs) /* destructively remove cell from */
2624 return tl(xs); /* element at front of list */
2628 for (; nonNull(curr); prev=curr, curr=tl(prev))
2630 tl(prev) = tl(curr);
2631 return xs; /* element in middle of list */
2635 return xs; /* here if element not found */
2638 List nubList(xs) /* nuke dups in list */
2639 List xs; { /* non destructive */
2641 for (; nonNull(xs); xs=tl(xs))
2642 if (isNull(cellIsMember(hd(xs),outs)))
2643 outs = cons(hd(xs),outs);
2649 /* --------------------------------------------------------------------------
2650 * Strongly-typed lists (z-lists) and tuples (experimental)
2651 * ------------------------------------------------------------------------*/
2653 static void z_tag_check ( Cell x, int tag, char* caller )
2657 sprintf(buf,"z_tag_check(%s): null\n", caller);
2660 if (whatIs(x) != tag) {
2662 "z_tag_check(%s): tag was %d, expected %d\n",
2663 caller, whatIs(x), tag );
2669 Cell zcons ( Cell x, Cell xs )
2671 if (!(isNull(xs) || whatIs(xs)==ZCONS))
2672 internal("zcons: ill typed tail");
2673 return ap(ZCONS,ap(x,xs));
2676 Cell zhd ( Cell xs )
2678 if (isNull(xs)) internal("zhd: empty list");
2679 z_tag_check(xs,ZCONS,"zhd");
2680 return fst( snd(xs) );
2683 Cell ztl ( Cell xs )
2685 if (isNull(xs)) internal("ztl: empty list");
2686 z_tag_check(xs,ZCONS,"zhd");
2687 return snd( snd(xs) );
2690 Int zlength ( ZList xs )
2693 while (nonNull(xs)) {
2694 z_tag_check(xs,ZCONS,"zlength");
2696 xs = snd( snd(xs) );
2701 ZList zreverse ( ZList xs )
2704 while (nonNull(xs)) {
2705 z_tag_check(xs,ZCONS,"zreverse");
2706 rev = zcons(zhd(xs),rev);
2712 Cell zsingleton ( Cell x )
2714 return zcons (x,NIL);
2717 Cell zdoubleton ( Cell x, Cell y )
2719 return zcons(x,zcons(y,NIL));
2723 Cell zpair ( Cell x1, Cell x2 )
2724 { return ap(ZTUP2,ap(x1,x2)); }
2725 Cell zfst ( Cell zpair )
2726 { z_tag_check(zpair,ZTUP2,"zfst"); return fst( snd(zpair) ); }
2727 Cell zsnd ( Cell zpair )
2728 { z_tag_check(zpair,ZTUP2,"zsnd"); return snd( snd(zpair) ); }
2730 Cell ztriple ( Cell x1, Cell x2, Cell x3 )
2731 { return ap(ZTUP3,ap(x1,ap(x2,x3))); }
2732 Cell zfst3 ( Cell zpair )
2733 { z_tag_check(zpair,ZTUP3,"zfst3"); return fst( snd(zpair) ); }
2734 Cell zsnd3 ( Cell zpair )
2735 { z_tag_check(zpair,ZTUP3,"zsnd3"); return fst(snd( snd(zpair) )); }
2736 Cell zthd3 ( Cell zpair )
2737 { z_tag_check(zpair,ZTUP3,"zthd3"); return snd(snd( snd(zpair) )); }
2739 Cell z4ble ( Cell x1, Cell x2, Cell x3, Cell x4 )
2740 { return ap(ZTUP4,ap(x1,ap(x2,ap(x3,x4)))); }
2741 Cell zsel14 ( Cell zpair )
2742 { z_tag_check(zpair,ZTUP4,"zsel14"); return fst( snd(zpair) ); }
2743 Cell zsel24 ( Cell zpair )
2744 { z_tag_check(zpair,ZTUP4,"zsel24"); return fst(snd( snd(zpair) )); }
2745 Cell zsel34 ( Cell zpair )
2746 { z_tag_check(zpair,ZTUP4,"zsel34"); return fst(snd(snd( snd(zpair) ))); }
2747 Cell zsel44 ( Cell zpair )
2748 { z_tag_check(zpair,ZTUP4,"zsel44"); return snd(snd(snd( snd(zpair) ))); }
2750 Cell z5ble ( Cell x1, Cell x2, Cell x3, Cell x4, Cell x5 )
2751 { return ap(ZTUP5,ap(x1,ap(x2,ap(x3,ap(x4,x5))))); }
2752 Cell zsel15 ( Cell zpair )
2753 { z_tag_check(zpair,ZTUP5,"zsel15"); return fst( snd(zpair) ); }
2754 Cell zsel25 ( Cell zpair )
2755 { z_tag_check(zpair,ZTUP5,"zsel25"); return fst(snd( snd(zpair) )); }
2756 Cell zsel35 ( Cell zpair )
2757 { z_tag_check(zpair,ZTUP5,"zsel35"); return fst(snd(snd( snd(zpair) ))); }
2758 Cell zsel45 ( Cell zpair )
2759 { z_tag_check(zpair,ZTUP5,"zsel45"); return fst(snd(snd(snd( snd(zpair) )))); }
2760 Cell zsel55 ( Cell zpair )
2761 { z_tag_check(zpair,ZTUP5,"zsel55"); return snd(snd(snd(snd( snd(zpair) )))); }
2764 Cell unap ( int tag, Cell c )
2767 if (whatIs(c) != tag) {
2768 sprintf(buf, "unap: specified %d, actual %d\n",
2775 /* --------------------------------------------------------------------------
2776 * Operations on applications:
2777 * ------------------------------------------------------------------------*/
2779 Int argCount; /* number of args in application */
2781 Cell getHead(e) /* get head cell of application */
2782 Cell e; { /* set number of args in argCount */
2783 for (argCount=0; isAp(e); e=fun(e))
2788 List getArgs(e) /* get list of arguments in function*/
2789 Cell e; { /* application: */
2790 List as; /* getArgs(f e1 .. en) = [e1,..,en] */
2792 for (as=NIL; isAp(e); e=fun(e))
2793 as = cons(arg(e),as);
2797 Cell nthArg(n,e) /* return nth arg in application */
2798 Int n; /* of function to m args (m>=n) */
2799 Cell e; { /* nthArg n (f x0 x1 ... xm) = xn */
2800 for (n=numArgs(e)-n-1; n>0; n--)
2805 Int numArgs(e) /* find number of arguments to expr */
2808 for (n=0; isAp(e); e=fun(e))
2813 Cell applyToArgs(f,args) /* destructively apply list of args */
2814 Cell f; /* to function f */
2816 while (nonNull(args)) {
2817 Cell temp = tl(args);
2818 tl(args) = hd(args);
2827 /* --------------------------------------------------------------------------
2829 * ------------------------------------------------------------------------*/
2831 /*---------------------------------------------------------------------------
2832 * GreenCard entry points
2834 * GreenCard generated code accesses Hugs data structures and functions
2835 * (only) via these functions (which are stored in the virtual function
2837 *-------------------------------------------------------------------------*/
2841 static Cell makeTuple Args((Int));
2842 static Cell makeInt Args((Int));
2843 static Cell makeChar Args((Char));
2844 static Char CharOf Args((Cell));
2845 static Cell makeFloat Args((FloatPro));
2846 static Void* derefMallocPtr Args((Cell));
2847 static Cell* Fst Args((Cell));
2848 static Cell* Snd Args((Cell));
2850 static Cell makeTuple(n) Int n; { return mkTuple(n); }
2851 static Cell makeInt(n) Int n; { return mkInt(n); }
2852 static Cell makeChar(n) Char n; { return mkChar(n); }
2853 static Char CharOf(n) Cell n; { return charOf(n); }
2854 static Cell makeFloat(n) FloatPro n; { return mkFloat(n); }
2855 static Void* derefMallocPtr(n) Cell n; { return derefMP(n); }
2856 static Cell* Fst(n) Cell n; { return (Cell*)&fst(n); }
2857 static Cell* Snd(n) Cell n; { return (Cell*)&snd(n); }
2859 HugsAPI1* hugsAPI1() {
2860 static HugsAPI1 api;
2861 static Bool initialised = FALSE;
2863 api.nameTrue = nameTrue;
2864 api.nameFalse = nameFalse;
2865 api.nameNil = nameNil;
2866 api.nameCons = nameCons;
2867 api.nameJust = nameJust;
2868 api.nameNothing = nameNothing;
2869 api.nameLeft = nameLeft;
2870 api.nameRight = nameRight;
2871 api.nameUnit = nameUnit;
2872 api.nameIORun = nameIORun;
2873 api.makeInt = makeInt;
2874 api.makeChar = makeChar;
2875 api.CharOf = CharOf;
2876 api.makeFloat = makeFloat;
2877 api.makeTuple = makeTuple;
2879 api.mkMallocPtr = mkMallocPtr;
2880 api.derefMallocPtr = derefMallocPtr;
2881 api.mkStablePtr = mkStablePtr;
2882 api.derefStablePtr = derefStablePtr;
2883 api.freeStablePtr = freeStablePtr;
2885 api.evalWithNoError = evalWithNoError;
2886 api.evalFails = evalFails;
2887 api.whnfArgs = &whnfArgs;
2888 api.whnfHead = &whnfHead;
2889 api.whnfInt = &whnfInt;
2890 api.whnfFloat = &whnfFloat;
2891 api.garbageCollect = garbageCollect;
2892 api.stackOverflow = hugsStackOverflow;
2893 api.internal = internal;
2894 api.registerPrims = registerPrims;
2895 api.addPrimCfun = addPrimCfun;
2896 api.inventText = inventText;
2899 api.cellStack = cellStack;
2905 #endif /* GREENCARD */
2908 /* --------------------------------------------------------------------------
2910 * ------------------------------------------------------------------------*/
2913 static void far* safeFarCalloc Args((Int,Int));
2914 static void far* safeFarCalloc(n,s) /* allocate table storage and check*/
2915 Int n, s; { /* for non-null return */
2916 void far* tab = farCalloc(n,s);
2918 ERRMSG(0) "Cannot allocate run-time tables"
2923 #define TABALLOC(v,t,n) v=(t far*)safeFarCalloc(n,sizeof(t));
2925 #define TABALLOC(v,t,n)
2933 case POSTPREL: break;
2935 case RESET : clearStack();
2937 /* the next 2 statements are particularly important
2938 * if you are using GLOBALfst or GLOBALsnd since the
2939 * corresponding registers may be reset to their
2940 * uninitialised initial values by a longjump.
2942 heapTopFst = heapFst + heapSize;
2943 heapTopSnd = heapSnd + heapSize;
2947 if (isNull(lastExprSaved))
2948 savedText = NUM_TEXT;
2953 for (i=NAMEMIN; i<nameHw; ++i) {
2954 mark(name(i).parent);
2956 mark(name(i).stgVar);
2959 end("Names", nameHw-NAMEMIN);
2962 for (i=MODMIN; i<moduleHw; ++i) {
2963 mark(module(i).tycons);
2964 mark(module(i).names);
2965 mark(module(i).classes);
2966 mark(module(i).exports);
2967 mark(module(i).qualImports);
2969 end("Modules", moduleHw-MODMIN);
2972 for (i=TYCMIN; i<tyconHw; ++i) {
2973 mark(tycon(i).defn);
2974 mark(tycon(i).kind);
2975 mark(tycon(i).what);
2977 end("Type constructors", tyconHw-TYCMIN);
2980 for (i=CLASSMIN; i<classHw; ++i) {
2981 mark(cclass(i).head);
2982 mark(cclass(i).kinds);
2983 mark(cclass(i).fds);
2984 mark(cclass(i).xfds);
2985 mark(cclass(i).dsels);
2986 mark(cclass(i).supers);
2987 mark(cclass(i).members);
2988 mark(cclass(i).defaults);
2989 mark(cclass(i).instances);
2992 end("Classes", classHw-CLASSMIN);
2995 for (i=INSTMIN; i<instHw; ++i) {
2997 mark(inst(i).kinds);
2998 mark(inst(i).specifics);
2999 mark(inst(i).implements);
3001 end("Instances", instHw-INSTMIN);
3004 for (i=0; i<=sp; ++i)
3009 mark(lastExprSaved);
3012 end("Last expression", 3);
3017 end("C stack", stackRoots);
3022 case PREPREL : heapFst = heapAlloc(heapSize);
3023 heapSnd = heapAlloc(heapSize);
3025 if (heapFst==(Heap)0 || heapSnd==(Heap)0) {
3026 ERRMSG(0) "Cannot allocate heap storage (%d cells)",
3031 heapTopFst = heapFst + heapSize;
3032 heapTopSnd = heapSnd + heapSize;
3033 for (i=1; i<heapSize; ++i) {
3037 snd(-heapSize) = NIL;
3044 marksSize = bitArraySize(heapSize);
3045 if ((marks=(Int *)calloc(marksSize, sizeof(Int)))==0) {
3046 ERRMSG(0) "Unable to allocate gc markspace"
3050 TABALLOC(text, char, NUM_TEXT)
3051 TABALLOC(tyconHash, Tycon, TYCONHSZ)
3052 TABALLOC(tabTycon, struct strTycon, NUM_TYCON)
3053 TABALLOC(nameHash, Name, NAMEHSZ)
3054 TABALLOC(tabName, struct strName, NUM_NAME)
3055 TABALLOC(tabClass, struct strClass, NUM_CLASSES)
3056 TABALLOC(cellStack, Cell, NUM_STACK)
3057 TABALLOC(tabModule, struct Module, NUM_SCRIPTS)
3059 TABALLOC(tabExt, Text, NUM_EXT)
3064 nextNewText = NUM_TEXT;
3065 nextNewDText = (-1);
3066 lastExprSaved = NIL;
3067 savedText = NUM_TEXT;
3068 for (i=0; i<TEXTHSZ; ++i)
3069 textHash[i][0] = NOTEXT;
3075 for (i=0; i<TYCONHSZ; ++i)
3082 for (i=0; i<NAMEHSZ; ++i)
3093 tabInst = (struct strInst far *)
3094 farCalloc(NUM_INSTS,sizeof(struct strInst));
3097 ERRMSG(0) "Cannot allocate instance tables"
3107 /*-------------------------------------------------------------------------*/