-- PackTree.Mesa
-- last edited by Lewis on 22-Oct-81 18:42:49
-- last edited by Satterthwaite, January 12, 1983 11:40 am

DIRECTORY
  CodePackProcs: TYPE USING [ModuleIndex, nullModuleIndex],
  HashTypes: TYPE USING [HTIndex, htNull],
  Symbols: TYPE USING [STIndex],
  Table: TYPE USING [Base, Finger, Limit, Selector, chunkType];

Tree, Literals: DEFINITIONS={

  treeType: Table.Selector~Table.chunkType;

  Base: TYPE~Table.Base;
  Finger: TYPE~Table.Finger;
  Limit: CARDINAL~Table.Limit;

  Link: TYPE~RECORD [
    SELECT tag: * FROM
      subtree => [index: Tree.Index],
      hash    => [index: HashTypes.HTIndex],
      symbol  => [index: Symbols.STIndex],
      literal   => [index: CodePackProcs.ModuleIndex] -- procs in a code pack
      ENDCASE];

  null:      Tree.Link~[subtree[index: Tree.nullIndex]];
  nullId:    Tree.Link~[hash[index: HashTypes.htNull]];

  ProcsLink: TYPE~Tree.Link.literal;
  nullProcs: ProcsLink~[literal[index: CodePackProcs.nullModuleIndex]];

  Index: TYPE~Base RELATIVE POINTER [0..Limit) TO Tree.Node;
    nullIndex: Tree.Index~Tree.Index.FIRST;

  Node: TYPE~MACHINE DEPENDENT RECORD [
    free (0: 0..0): BOOL,		-- reserved for allocator
    name (0: 1..5): NodeName,
    nSons (0: 6..15): [0..maxNSons],
    info (1): CARDINAL,		-- (source file index)
    shared (2: 0..0): BOOL,
    attrs (2: 1..15): PACKED ARRAY AttrId OF BOOL←ALL[FALSE],
    cp (3): Tree.Index,		-- enclosing code pack node if component desc
    seg (4): Tree.Index,		-- enclosing segment node if component desc
    son (5): ARRAY [1..1) OF Tree.Link];

  Info: TYPE~CARDINAL;

  AttrId: TYPE~{
    superceded,	-- if code pack, seg, frame pack node superceded
    placed,		-- if code pack, seg placed
    exceptMAIN,	-- if code pack excludes MAIN procs
    exceptEV,	-- if code pack excludes entry vectors
    exceptCatch};	-- if code pack excludes catch phrases
  
  maxNSons: CARDINAL~1777b; -- largest list without null terminator

  NodeName: TYPE~{
   -- general tree constructor
    list,

   -- declarations
    codeSeg,
    codePack, unnamedCodePack, discardCodePack,
    framePack,
    merge,            -- merge segment
    mergeFP,          -- merge frame pack

   -- component descriptions
    allComp,          -- ComponentDesc ::= Component
    compItems,        -- ComponentDesc ::= Component [ItemList]
    exceptItems,      -- ComponentDesc ::= Component EXCEPT [ItemList]
    exceptPacks,      -- ComponentDesc ::= Component EXCEPT PackList
    itemsExceptPacks, -- ComponentDesc ::= Component [ItemList] EXCEPT PackList
    exceptPacksItems, -- ComponentDesc ::= Component EXCEPT PackList, [ItemList]
    mainOfPL,         -- ComponentDesc ::= MAIN OF PackList
    evOfPL,           -- ComponentDesc ::= ENTRY VECTOR OF PackList
    catchOfPL,        -- ComponentDesc ::= CATCH CODE OF PackList

   -- expressions
    component,
    main,
    ev,
    catch,

   -- nil
    none
    };
    

 -- tree manipulation

  Id:   TYPE~RECORD [baseP: Finger, link: Tree.Link];
  Scan: TYPE~PROC [t: Tree.Link];
  Map:  TYPE~PROC [t: Tree.Link] RETURNS [v: Tree.Link];
  Test: TYPE~PROC [t: Tree.Link] RETURNS [BOOL];


 -- Literals: (for proto- modules)
 
 LitIndex: TYPE~CodePackProcs.ModuleIndex;
 
 }.