DEFINITION MODULE Stab;

(*
    Title    :  Symbol Table Handling Module - Simple Version
    LastEdit :  Mon Dec 19 10:39:57 1983
    Author   :  Lee Smith
    Acorn Computers VLSI Design Aids Group
*)

FROM SYSTEM   IMPORT ADDRESS;

FROM PSMCI    IMPORT PSCANPROC;

(*------------------------------------------------------------------------*)
(*  This implementation uses a simple linked list representation of name  *)
(*  tables.  The performance of this is almost certainly within a factor  *)
(*  of two of any non-hashing method for tables with fewer than a couple  *)
(*  of hundred entries.                                                   *)
(*------------------------------------------------------------------------*)
(*  Strings passed to this package are assumed to be terminated by a ' '  *)
(*  or to be exactly the length specified in ARRAY OF CHAR parameters.    *)
(*------------------------------------------------------------------------*)
(*  In fact, only pointers to objects are managed by this package: names  *)
(*  are assumed to reside in the first field of each object.              *)
(*------------------------------------------------------------------------*)

EXPORT QUALIFIED Table, NewTable, DestroyTable, ScanTable, Enter, Find,
                 Remove, PScan;

TYPE      Table = POINTER TO TableEntry;
     TableEntry = RECORD
                    Next : Table;
                  Object : ADDRESS;
                  END;
      CSCANPROC = PROCEDURE(ADDRESS) : BOOLEAN;
       SCANPROC = PROCEDURE(ADDRESS);
       
PROCEDURE NewTable() : Table;
(* Create a new empty Name table and return a token for it *)

PROCEDURE DestroyTable(VAR T : Table;  DestroyEntry : SCANPROC);

PROCEDURE ScanTable(T : Table;  ProcessEntry : CSCANPROC) : BOOLEAN;

PROCEDURE Enter(T : Table;  Object : ADDRESS);

PROCEDURE Remove(T : Table;  Object : ADDRESS);
   
PROCEDURE Find(T : Table;  Name : ARRAY OF CHAR) : ADDRESS;
(* Find the named entry and return the corresponding
   Object pointer or NIL if no Object of that Name was found *)

PROCEDURE PScan(T : Table;  ScanProc : PSCANPROC);   

END Stab.
