
    <<Symbols.mesa>>
        <<Copyright  1985 by Xerox Corporation.  All rights reserved.>>
        <<Satterthwaite, June 18, 1986 10:06:53 am PDT>>
        <<Rovner, July 6, 1983 1:33 pm>>
    <<Russ Atkinson (RRA) January 31, 1985 12:51:14 pm PST>>

    DIRECTORY
        BcdDefs: TYPE USING [VersionStamp, MaxNDMi],
        PrincOps: TYPE USING [EPRange, MaxFrameSize, MaxNGfi],
        Table: TYPE USING [Base, IndexRep, Selector, Tag];

    Symbols: DEFINITIONS = {

        Base: TYPE = Table.Base;

    <<tag codes    (zero reserved for treeType)>>

        htTag: Table.Tag = 1;
        seTag: Table.Tag = 2;

    <<hash table declarations>>

        Name: TYPE = Base RELATIVE LONG POINTER TO HTRecord;
        firstName: Name = LOOPHOLE[Table.IndexRep[tag: htTag, highBits: 0, lowBits: 0]];
        nullName: Name = firstName;

        HTIndex: TYPE = Name;
        HTFirst: HTIndex = firstName;
        HTNull: Name = nullName;

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

        HVIndex: TYPE = [0..71);
        HashVector: TYPE = ARRAY HVIndex OF HTIndex;

    <<semantic entry table declarations>>

        TypeClass: TYPE = {
            mode,
            basic,
            enumerated,
            record,
            ref,
            array,
            arraydesc,
            transfer,
            definition,
            union,
            sequence,
            relative,
            subrange,
            long,
            real,
            opaque,
            zone,
            any,
            nil};

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

        UNSPEC: TYPE = RECORD[low, high: WORD];    -- opaque, conversions use LOOPHOLE

        SERecord: TYPE = RECORD[
            mark3, mark4: BOOL,
            body: SELECT seTag: * FROM
                id => [
                    extended: BOOL,
                    public: BOOL,
                    idCtx: CTXIndex,
                    immutable, constant: BOOL,
                    idType: Type,
                    idInfo: UNSPEC,
                    idValue: UNSPEC,
                    hash: Name,
                    linkSpace: BOOL,
                    ctxLink: SELECT linkTag: * FROM
                        terminal => [],
                        sequential => [],
                        linked => [link: ISEIndex]
                        ENDCASE],
                cons => [
                    typeInfo: SELECT typeTag: TypeClass FROM
                        mode => [],
                        basic => [
                            ordered: BOOL,
                            code: [0..16),
                            length: CARDINAL],
                        enumerated => [
                            ordered, machineDep: BOOL,
                            painted: BOOL,
                            empty: BOOL,
                            sparse: BOOL,
                            valueCtx: CTXIndex,
                            range: CARD],
                        record => [
                            hints: RECORD[
                                comparable, assignable: BOOL,
                                unifield, variant, privateFields: BOOL,
                                refField, default, voidable: BOOL],
                            length: CARD,
                            argument, monitored, machineDep: BOOL,
                            painted: BOOL,
                            fieldCtx: CTXIndex,
                            linkPart: SELECT linkTag: * FROM
                                notLinked => [],
                                linked => [linkType: Type]
                                ENDCASE],
                        ref => [
                            counted, ordered, readOnly, list, var, basing: BOOL,
                            refType: Type],
                        array => [
                            packed: BOOL,
                            indexType: Type,
                            componentType: Type],
                        arraydesc => [
                            var, readOnly: BOOL,
                            describedType: Type],
                        transfer => [
                            safe: BOOL,
                            mode: TransferMode,
                            typeIn, typeOut: CSEIndex],
                        definition => [
                            nDummyGfi: [0 .. BcdDefs.MaxNDMi],
                            named: BOOL,
                            defCtx: CTXIndex],
                        union => [
                            hints: RECORD [
                                equalLengths: BOOL,
                                refField, default, voidable: BOOL],
                            overlaid, controlled, machineDep: BOOL,
                            caseCtx: CTXIndex,
                            tagSei: ISEIndex],
                        sequence => [
                            packed: BOOL,
                            controlled, machineDep: BOOL,
                            tagSei: ISEIndex,
                            componentType: Type],
                        relative => [
                            baseType: Type,
                            offsetType: Type,
                            resultType: Type],
                        subrange => [
                            filled: BOOL,
                            biased, empty: BOOL,
                            rangeType: Type,
                            origin: INT,
                            range: CARD],
                        long, real => [rangeType: Type],
                        opaque => [
                            lengthKnown: BOOL,
                            length: CARD,
                            id: ISEIndex],
                        zone => [counted, mds: BOOL],
                        any => [],
                        nil => []
                        ENDCASE],
                ENDCASE];

        SEIndex: TYPE = Base RELATIVE LONG POINTER TO SERecord;
        Type: TYPE = SEIndex;

        ISEIndex: TYPE = Base RELATIVE LONG POINTER TO SERecord.id;
        CSEIndex: TYPE = Base RELATIVE LONG POINTER TO SERecord.cons;
        RecordSEIndex: TYPE = Base RELATIVE LONG POINTER TO SERecord.cons.record;
        RefSEIndex: TYPE = Base RELATIVE LONG POINTER TO SERecord.cons.ref;
        ArraySEIndex: TYPE = Base RELATIVE LONG POINTER TO SERecord.cons.array;

        SEFirst: SEIndex = LOOPHOLE[Table.IndexRep[tag: seTag, highBits: 0, lowBits: 0]];
        SENull: SEIndex = SEFirst;
            nullType: Type = SENull;
        ISEFirst: ISEIndex = LOOPHOLE[SEFirst];
        ISENull: ISEIndex = LOOPHOLE[SENull];
        CSEFirst: CSEIndex = LOOPHOLE[SEFirst];
        CSENull: CSEIndex = LOOPHOLE[SENull];
            RecordSENull: RecordSEIndex = LOOPHOLE[SENull];
            RefSENull: RefSEIndex = LOOPHOLE[SENull];
            ArraySENull: ArraySEIndex = LOOPHOLE[SENull];

    <<the following two values are guaranteed by the compiler>>
        typeTYPE: CSEIndex = CSENull + SERecord.cons.nil.SIZE;
        typeANY: CSEIndex = typeTYPE + SERecord.cons.mode.SIZE;

    <<codes identifying the basic types (extensible)>>
        codeANY: NAT = 0;
        codeINT: NAT = 1;
        codeCHAR: NAT = 2;

        BitCount: TYPE = CARD;        -- sizes in bits

        BitAddress: TYPE = RECORD[bd: BitCount];    -- bit offset
            <<wd: CARD,            word displacement>>
            <<bd: [0..wordLength)];           bit displacement  >>

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

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

        RefClass: TYPE = {none, simple, composite};

    <<context table declarations>>

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

        Closure: TYPE = {none, unit, rc, full};  -- completeness of copied contexts

        CTXRecord: TYPE = RECORD[
            varUpdated: BOOL,
            seList: ISEIndex,
            level: ContextLevel,
            extension: SELECT ctxType: * FROM
                simple => [copied: Closure _ $unit],
                included => [
                    chain: IncludedCTXIndex,
                    copied: Closure _ $none,
                    module: MDIndex,
                    map: CTXIndex,
                    closed, complete, restricted: BOOL,
                    reset: BOOL],
                imported => [includeLink: IncludedCTXIndex],
                nil => []
                ENDCASE];

        CTXIndex: TYPE = Base RELATIVE LONG ORDERED POINTER TO CTXRecord;
            IncludedCTXIndex: TYPE = Base RELATIVE LONG ORDERED POINTER TO CTXRecord.included;

        CTXFirst: CTXIndex = LOOPHOLE[Table.IndexRep[tag:0, highBits:0, lowBits:0]];
        CTXNull: CTXIndex = CTXFirst;
            IncludedCTXNull: IncludedCTXIndex = LOOPHOLE[CTXNull];

        <<StandardContext: TYPE = CTXIndex[CTXFirst+CTXRecord.simple.SIZE ..  CTXFirst+6*CTXRecord.simple.SIZE];>>
        FirstStandardCtx: CTXIndex = CTXFirst+CTXRecord.simple.SIZE;
        LastStandardCtx: CTXIndex = CTXFirst+6*CTXRecord.simple.SIZE;

    <<module table declarations>>

        FileIndex: TYPE = NAT;    -- internal file handle
        nullFileIndex: FileIndex = FileIndex.LAST;

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

        MDIndex: TYPE = Base RELATIVE LONG ORDERED POINTER TO MDRecord;
        MDFirst: MDIndex = LOOPHOLE[Table.IndexRep[tag:0, highBits:0, lowBits:0]];
        MDNull: MDIndex = LOOPHOLE[Table.IndexRep[tag:0]];

        OwnMdi: MDIndex = MDFirst;

    <<body table declarations>>

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

        BodyRecord: TYPE = RECORD[
            link: BodyLink,
            firstSon: BTIndex,
            type: RecordSEIndex,
            localCtx: CTXIndex,
            level: ContextLevel,
            sourceIndex: CARD,
            info: BodyInfo,
            extension: SELECT kind: * FROM
                Callable => [
                    inline: BOOL,
                    id: ISEIndex,
                    ioType: CSEIndex,
                    monitored, noXfers, resident: BOOL,
                    entry, internal: BOOL,
                    entryIndex: [0..PrincOps.EPRange*PrincOps.MaxNGfi),
                    hints: RECORD[safe, argUpdated, nameSafe, noStrings: BOOL],
                    closure: SELECT nesting: * FROM
                        Outer => [],
                        Inner => [frameOffset: [0..PrincOps.MaxFrameSize)],
                        Catch => [index: CatchIndex]        -- used only in Trinity
                        ENDCASE],
                Other => [relOffset: [0..CARDINAL.LAST/2]]
                ENDCASE];

            BodyInfo: TYPE = RECORD[
                SELECT mark: * FROM
                    Internal => [
                        frameSize: [0..PrincOps.MaxFrameSize],
                        bodyTree: Base RELATIVE LONG POINTER,    -- Tree.Index 
                        thread: Base RELATIVE LONG POINTER],    -- Tree.Index / LitDefs.STIndex 
                    External => [
                        bytes: CARD,
                        startIndex, indexLength: CARD]
                    ENDCASE];

        BTIndex: TYPE = Base RELATIVE LONG POINTER TO BodyRecord;
            CBTIndex: TYPE = Base RELATIVE LONG POINTER TO BodyRecord.Callable;
                ICBTIndex: TYPE = Base RELATIVE LONG POINTER TO BodyRecord.Callable.Inner;
                OCBTIndex: TYPE = Base RELATIVE LONG POINTER TO BodyRecord.Callable.Outer;
                CCBTIndex: TYPE = Base RELATIVE LONG POINTER TO BodyRecord.Callable.Catch;
        BTFirst: BTIndex = LOOPHOLE[Table.IndexRep[tag:0, highBits:0, lowBits:0]];
        BTNull: BTIndex = LOOPHOLE[Table.IndexRep[tag:0]];
            CBTNull: CBTIndex = LOOPHOLE[BTNull];
                CCBTNull: CCBTIndex = LOOPHOLE[CBTNull];

        RootBti: CBTIndex = LOOPHOLE[BTFirst];

        CatchIndex: TYPE = NAT;

    <<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;

        }.

