-- file Symbols.Mesa
-- last modified by Satterthwaite, October 30, 1979  3:20 PM

DIRECTORY
  AltoDefs: FROM "altodefs" USING [VMLimit, wordlength],
  BcdDefs: FROM "bcddefs" USING [VersionStamp],
  Table: FROM "table" USING [Base, Selector, Limit];

Symbols: DEFINITIONS =
  BEGIN

 -- hash table declarations

  HVLength: PRIVATE CARDINAL = 71;
  HVIndex: TYPE = CARDINAL [0..HVLength);

  HTRecord: TYPE = RECORD [
    anyInternal, anyPublic: BOOLEAN,
    link: HTIndex,
    ssIndex: CARDINAL];

  HTIndex: TYPE = CARDINAL [0..Table.Limit/2);
  HTNull: HTIndex = FIRST[HTIndex];

 -- semantic entry table declarations

  TypeClass: TYPE = {
    mode,
    basic,
    enumerated,
    record,
    pointer,
    array,
    arraydesc,
    transfer,
    definition,
    union,
    relative,
    subrange,
    long,
    real,
    unique,
    nil
    };

  TransferMode: TYPE = {procedure, port, signal, error, process, program, none};

  SERecord: TYPE = RECORD [
    mark3, mark4: BOOLEAN,
    body: SELECT seTag: * FROM
      id => [
	extended: BOOLEAN,
	public: BOOLEAN,
	idCtx: CTXIndex,
	immutable, constant: BOOLEAN,
	idType: SEIndex,
	idInfo: UNSPECIFIED,
	idValue: UNSPECIFIED,
	hash: HTIndex,
	linkSpace: BOOLEAN,
	ctxLink: SELECT linkTag: * FROM
	  terminal => NULL,
	  sequential => NULL,
	  linked => [link: ISEIndex],
	  ENDCASE],
      cons => [
	typeInfo: SELECT typeTag: TypeClass FROM
	  mode => NULL,
	  basic => [
	    ordered: BOOLEAN,
	    code: [0..16),
	    length: CARDINAL],
	  enumerated => [
	    ordered: BOOLEAN,
	    valueCtx: CTXIndex,
	    nValues: CARDINAL],
	  record => [
	    machineDep: BOOLEAN,
	    monitored: BOOLEAN,
	    argument: BOOLEAN,
	    hints: RECORD [
	      variant: BOOLEAN,
	      unifield: BOOLEAN,
	      comparable: BOOLEAN,
	      privateFields: BOOLEAN],
	    lengthUsed: BOOLEAN,
	    length: CARDINAL,
	    fieldCtx: CTXIndex,
	    linkPart: SELECT linkTag: * FROM
	      notLinked => NULL,
	      linked => [linkType: SEIndex],
	      ENDCASE],
	  pointer => [
	    ordered, readOnly, basing: BOOLEAN,
	    dereferenced: BOOLEAN,
	    refType: SEIndex],
	  array => [
	    oldPacked: BOOLEAN,
	    comparable: BOOLEAN,
	    lengthUsed: BOOLEAN,
	    indexType: SEIndex,
	    componentType: SEIndex],
	  arraydesc => [
	    readOnly: BOOLEAN,
	    describedType: SEIndex],
	  transfer => [
	    mode: TransferMode,
	    inRecord, outRecord: RecordSEIndex],
	  definition => [
	    nGfi: [1 .. 4],
	    named: BOOLEAN,
	    defCtx: CTXIndex],
	  union => [
	    equalLengths: BOOLEAN,
	    caseCtx: CTXIndex,
	    overlayed, controlled: BOOLEAN,
	    tagSei: ISEIndex],
	  relative => [
	    baseType: SEIndex,
	    offsetType: SEIndex,
	    resultType: SEIndex],
	  subrange => [
	    filled, empty, flexible: BOOLEAN,
	    rangeType: SEIndex,
	    origin: INTEGER,
	    range: CARDINAL],
	  long, real => [rangeType: SEIndex],
	  unique => [
	    virtual, opaque: BOOLEAN,
	    lengthKnown, lengthUsed: BOOLEAN,
	    link: SEIndex,
	    length: CARDINAL],
	  nil => NULL,
	  ENDCASE],
      ENDCASE];

  SEIndex: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO SERecord;

  ISEIndex: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO id SERecord;
  CSEIndex: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO cons SERecord;
  RecordSEIndex: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO record cons SERecord;
  ArraySEIndex: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO array cons SERecord;

  SENull: SEIndex = FIRST[SEIndex];
  ISENull: ISEIndex = LOOPHOLE[SENull];
  CSENull: CSEIndex = LOOPHOLE[SENull];
    RecordSENull: RecordSEIndex = LOOPHOLE[SENull];
    ArraySENull: ArraySEIndex = LOOPHOLE[SENull];

 -- the following two values are guaranteed by the compiler
  typeTYPE: CSEIndex = FIRST[CSEIndex] + SIZE[nil cons SERecord];
  typeANY: CSEIndex = typeTYPE + SIZE[mode cons SERecord];

 -- codes identifying the basic types (extensible)
  codeANY: CARDINAL = 0;
  codeINTEGER: CARDINAL = 1;
  codeCHARACTER: CARDINAL = 2;

  BitAddress: TYPE = RECORD[
    wd: [0..AltoDefs.VMLimit/AltoDefs.wordlength],	-- word displacement
    bd: [0..AltoDefs.wordlength)];   		-- bit displacement  

  ExtensionType: TYPE = {value, form, default, none};

  Linkage: TYPE = {val, ref, manifest, none};	-- for import/export

 -- context table declarations

  ContextLevel: TYPE = [0..7];
    lZ: ContextLevel = 0;	-- context level of non-frame records
    lG: ContextLevel = 1;	-- context level of global frame
    lL: ContextLevel = lG+1;	-- context level of outer procedures

  CTXRecord: TYPE = RECORD [
    mark, varUpdated: BOOLEAN,
    seList: ISEIndex,
    level: ContextLevel,
    extension: SELECT ctxType: * FROM
      simple => [ctxNew: CTXIndex],	-- for DeSoto
      included => [
	chain: IncludedCTXIndex,
	module: MDIndex,
	map: CTXIndex,
	closed, complete, restricted: BOOLEAN,
	reset: BOOLEAN],
      imported => [includeLink: IncludedCTXIndex],
      nil => NULL,
      ENDCASE];

  CTXIndex: TYPE = Table.Base RELATIVE ORDERED POINTER [0..3777B] TO CTXRecord;
   IncludedCTXIndex: TYPE = Table.Base RELATIVE ORDERED POINTER [0..3777B] TO included CTXRecord;

  CTXNull: CTXIndex = FIRST[CTXIndex];
    IncludedCTXNull: IncludedCTXIndex = LOOPHOLE[CTXNull];

  StandardContext: TYPE = CTXIndex[CTXNull..CTXNull+5*SIZE[simple CTXRecord]];

 -- module table declarations

  FileIndex: TYPE = [0..77777B];	-- internal file handle
  NullFileIndex: FileIndex = LAST[FileIndex];

  MDRecord: TYPE = RECORD [
    stamp: BcdDefs.VersionStamp,
    moduleId: HTIndex,		-- hash entry for module name
    fileId: HTIndex,		-- hash entry for file name
    shared: BOOLEAN,		-- overrides PRIVATE, etc.
    exported: BOOLEAN,
    ctx: IncludedCTXIndex,	-- context of copied entries
    defaultImport: CTXIndex,	-- unnamed imported instance
    file: FileIndex];		-- associated file

  MDIndex: TYPE = Table.Base RELATIVE ORDERED POINTER [0..Table.Limit) TO MDRecord;
  MDNull: MDIndex = LAST[MDIndex];

  OwnMdi: MDIndex = FIRST[MDIndex];

 -- body table declarations

  BodyLink: TYPE = RECORD [which: {sibling, parent}, index: BTIndex];

  BodyRecord: TYPE = RECORD [
    link: BodyLink,
    firstSon: BTIndex,
    localCtx: CTXIndex,
    level: ContextLevel,
    info: BodyInfo,
    extension: SELECT kind: * FROM
      Callable => [
	inline: BOOLEAN,
	id: ISEIndex,
	ioType: CSEIndex,
	monitored, stopping, resident: BOOLEAN,
	entry, internal: BOOLEAN,
	entryIndex: [0..128),
	hints: RECORD [safe, argUpdated, nameSafe, attr4, attr5: BOOLEAN],
	closure: SELECT nesting: * FROM
	  Outer => NULL,
	  Inner => [frameOffset: [0..AltoDefs.VMLimit]],
	  ENDCASE],
      Other => NULL,
      ENDCASE];

    BodyInfo: TYPE = RECORD [
      SELECT mark: * FROM
	Internal => [
	  bodyTree: Table.Base RELATIVE POINTER [0..Table.Limit),
	    --Tree.Index-- 
	  sourceIndex: CARDINAL,
	  thread: Table.Base RELATIVE POINTER [0..Table.Limit),
	    --Tree.Index / LitDefs.STIndex-- 
	  frameSize: [0..4096)],
	External => [
	  origin: [0..AltoDefs.VMLimit/2],
	  bytes: CARDINAL,
	  startIndex, indexLength: CARDINAL],
	ENDCASE];

  BTIndex: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO BodyRecord;
    CBTIndex: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO Callable BodyRecord;
      ICBTIndex: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO Inner Callable BodyRecord;
      OCBTIndex: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO Outer Callable BodyRecord;
  BTNull: BTIndex = LAST[BTIndex];
    CBTNull: CBTIndex = LOOPHOLE[BTNull];

 -- allocation codes for table components

  seType: Table.Selector = 1;
  htType: Table.Selector = 2;
  ssType: Table.Selector = 3;
  ctxType: Table.Selector = 4;
  mdType: Table.Selector = 5;
  bodyType: Table.Selector = 6;

  END.