-- file BcdTree.Mesa
-- last modified by Satterthwaite, September 14, 1982 3:17 pm

DIRECTORY
  BcdDefs: TYPE USING [treetype],
  Symbols: TYPE USING [HTIndex, HTNull, STIndex],
  Table: TYPE USING [Base, Finger, Limit, Selector];

Tree, Literals: DEFINITIONS = {

  treeType: Table.Selector ~ BcdDefs.treetype;

  Base: TYPE ~ Table.Base;
  Finger: TYPE ~ Table.Finger;
  Limit: CARDINAL ~ Table.Limit;
  
 -- data structures
 
   Link: TYPE ~ RECORD [
    SELECT tag: * FROM
      subtree => [index: Tree.Index],
      hash => [index: Symbols.HTIndex],
      symbol => [index: Symbols.STIndex],
      literal => [info: Literals.LitRecord]
      ENDCASE];


  Node: TYPE ~ MACHINE DEPENDENT RECORD [
    free (0: 0..0): BOOL,	-- reserved for allocator
    name (0: 1..4): NodeName,
    attr1 (0: 5..5), attr2 (0: 6..6), attr3 (0: 7..7): BOOL,
    shared (0: 8..8): BOOL,
    nSons (0: 9..15): [0..MaxNSons],
    info (1): UNSPECIFIED,
    son (2): ARRAY [1..1) OF Tree.Link];

  AttrId: TYPE ~ [1..3];
  
  MaxNSons: CARDINAL ~ 177b;

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

  NullIndex: Tree.Index ~ Tree.Index.FIRST;
  Null: Tree.Link ~ [subtree[index: Tree.NullIndex]];

  NullId: Tree.Link ~ [hash[index: Symbols.HTNull]];


  NodeName: TYPE ~ {
   -- general tree constructors
    list, item,

   -- declarations
    source,
    config,

   -- expressions
    module,
    assign,
    plus,
    then,

   -- file names
    dot,
    slash,

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

  LTIndex, STIndex: TYPE ~ Symbols.HTIndex;

  LitRecord: TYPE ~ RECORD [
    SELECT litTag: * FROM
      word => [index: LTIndex],
      string => [index: STIndex]
      ENDCASE];

  }.