-- file SakuraTreeOps.Mesa
-- last modified by Satterthwaite, January 13, 1981  9:27 AM
-- last edit by Suzuki, 25-Nov-81 13:13:55

DIRECTORY
  PPLeaves: TYPE USING [Leaf, HTIndex, ISEIndex],
  Rope: TYPE USING [Ref],
  SakuraTree: TYPE;

SakuraTreeOps: DEFINITIONS =
  BEGIN OPEN Tree: SakuraTree, PPLeaves;

 -- tree construction interface

  Initialize, Reset, Finalize: PROC;

  Eq: PROC [l,r: Tree.Link] RETURNS [BOOLEAN];
  
  PushTree: PROC [v: Tree.Link];
  PopTree: PROC RETURNS [Tree.Link];

  InsertTree: PROC [Tree.Link, NAT];
  ExtractTree: PROC [NAT] 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: Leaf] = INLINE {PushTree[hti]};		-- HTIndex
  PushSe: PROC [sei: ISEIndex] = INLINE {PushTree[LOOPHOLE[sei]]};	-- ISEIndex
  PushLit: PROC [lti: Leaf] = INLINE {PushTree[lti]};		-- LTIndex
  PushStringLit: PROC [sti: Leaf] = INLINE {PushTree[sti]};	-- STIndex

  SetInfo: PROC [info: CARDINAL];
  SetAttr: PROC [which: Tree.AttrId, value: BOOLEAN];

  FreeTree: PROC [t: Tree.Link] RETURNS [Tree.Link] = INLINE {RETURN [Tree.Null]};

  PrintName: PROC [name: Tree.NodeName] RETURNS[Rope.Ref];
 
 -- tree attributes

  GetHash: PROC [t: Tree.Link] RETURNS [HTIndex];
  GetNode: PROC [t: Tree.Link] RETURNS [Tree.Handle];
  GetSe: PROC [t: Tree.Link] RETURNS [ISEIndex];
  
  NSons: PROC [t: Tree.Link] RETURNS [NAT];
      
  NthSon: PROC [t: Tree.Link, n: Tree.SonId] RETURNS [Tree.Link];
  
  OpName: PROC [t: Tree.Link] RETURNS [Tree.NodeName];

 -- stack manipulation

  GetIth: PROC [CARDINAL] RETURNS [Tree.Link];
  StackSize: PROC RETURNS [CARDINAL];
  
 -- tree manipulation

  Append: PROC [l,r: Tree.Link] RETURNS [Tree.Link];
  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 [NAT];
  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];
  ExpandList: PROC [a: Tree.Link] RETURNS [nList: NAT];
    -- Pushes elements of the list a onto the stack

 -- cross-table tree copying

  CopyTree: PROC [root: Tree.Id, map: Tree.Map] RETURNS [v: Tree.Link];
  IdentityMap: Tree.Map;

  END.