
    <<ProtoTreeOps.mesa>>
        <<Copyright © 1985 by Xerox Corporation.  All rights reserved.>>
        <<Satterthwaite, June 6, 1986 1:18:22 pm PDT>>
        <<Paul Rovner, September 7, 1983 12:14 am>>
        <<Russ Atkinson (RRA) March 6, 1985 10:06:59 pm PST>>

    DIRECTORY
        Alloc: TYPE USING [Handle],
        Literals: TYPE USING [LTIndex, STIndex],
        SourceMap: TYPE USING [Loc],
        Symbols: TYPE USING [HTIndex, ISEIndex],
        Tree: TYPE USING [
            AttrId, Finger, Id, Index, Info, Link, LinkRep, LinkTag, Map, NodeName, Scan, Test];

    TreeOps: DEFINITIONS = {

    <<tree construction interface>>

        Initialize: PROC[Alloc.Handle];
        Reset, Finalize: PROC;

        PushTree: PROC[v: Tree.Link];
        PopTree: PROC RETURNS[Tree.Link];

        InsertTree: PROC[Tree.Link, CARDINAL];
        ExtractTree: PROC[CARDINAL] RETURNS[Tree.Link];

        MakeNode: PROC[name: Tree.NodeName, count: INTEGER] RETURNS[Tree.Link];
        MakeList: PROC[size: INTEGER] RETURNS[Tree.Link];

        PushNode: PROC[name: Tree.NodeName, count: INTEGER];
        PushList, PushProperList: PROC[size: INTEGER];
        PushHash: PROC[hti: Symbols.HTIndex];
        PushSe: PROC[sei: Symbols.ISEIndex];
        PushLit: PROC[lti: Literals.LTIndex];
        PushString: PROC[lti: Literals.STIndex];

        SetAttr: PROC[attr: Tree.AttrId, value: BOOL];
        SetInfo: PROC[info: Tree.Info];

    <<tree deallocation>>

        FreeNode: PROC[node: Tree.Index];
        FreeTree: PROC[t: Tree.Link] RETURNS[Tree.Link];

    <<tree attributes>>

        GetTag: PROC[t: Tree.Link] RETURNS[Tree.LinkTag] = INLINE {
            RETURN[VAL[LOOPHOLE[t, Tree.LinkRep].tag]]};

        GetHash: PROC[t: Tree.Link] RETURNS[Symbols.HTIndex];
        GetNode: PROC[t: Tree.Link] RETURNS[Tree.Index];
        GetSe: PROC[t: Tree.Link] RETURNS[Symbols.ISEIndex];
        GetLit: PROC[t: Tree.Link] RETURNS[Literals.LTIndex];
        GetStr: PROC[t: Tree.Link] RETURNS[Literals.STIndex];

        NthSon: PROC[t: Tree.Link, n: CARDINAL] RETURNS[Tree.Link];
        OpName: PROC[t: Tree.Link] RETURNS[Tree.NodeName];

        GetAttr: PROC[t: Tree.Link, attr: Tree.AttrId] RETURNS[BOOL];
        PutAttr: PROC[t: Tree.Link, attr: Tree.AttrId, value: BOOL];

        GetInfo: PROC[t: Tree.Link] RETURNS[Tree.Info];
        PutInfo: PROC[t: Tree.Link, value: Tree.Info];

        ToCard: PROC[card: Tree.Info] RETURNS[CARD] = INLINE {
            RETURN[LOOPHOLE[card, CARD]]};
        ToLoc: PROC[loc: Tree.Info] RETURNS[SourceMap.Loc] = INLINE {
            RETURN[LOOPHOLE[loc, SourceMap.Loc]]};

        FromCard: PROC[card: CARD] RETURNS[Tree.Info] = INLINE {
            RETURN[LOOPHOLE[card, Tree.Info]]};
        FromLoc: PROC[loc: SourceMap.Loc] RETURNS[Tree.Info] = INLINE {
            RETURN[LOOPHOLE[loc, Tree.Info]]};

        Shared: PROC[t: Tree.Link] RETURNS[BOOL];
        MarkShared: PROC[t: Tree.Link, shared: BOOL];

    <<tree manipulation>>

        ScanSons: PROC[root: Tree.Link, action: Tree.Scan];
        UpdateLeaves: PROC[root: Tree.Link, map: Tree.Map] RETURNS[v: Tree.Link];

    <<list testing>>

        ListLength: PROC[t: Tree.Link] RETURNS[CARDINAL];
        ListHead: PROC[t: Tree.Link] RETURNS[Tree.Link];
        ListTail: PROC[t: Tree.Link] RETURNS[Tree.Link];

    <<list manipulation>>

        ScanList: PROC[root: Tree.Link, action: Tree.Scan];
        SearchList: PROC[root: Tree.Link, test: Tree.Test];
        ReverseScanList: PROC[root: Tree.Link, action: Tree.Scan];
        UpdateList: PROC[root: Tree.Link, map: Tree.Map] RETURNS[Tree.Link];
        ReverseUpdateList: PROC[root: Tree.Link, map: Tree.Map] RETURNS[Tree.Link];


    <<cross-table tree copying>>

        CopyTree: PROC[root: Tree.Id, map: Tree.Map] RETURNS[v: Tree.Link];
        IdentityMap: Tree.Map;
        NodeSize: PROC[baseP: Tree.Finger, node: Tree.Index] RETURNS[CARDINAL];

        }.

