(*

  This is just a quick hack to check the *NEW* Stack ADT.
  Written by P.Fröhlich 03-Sep-1991.
  Removed SYSTEM dependency [phf] 08-Sep-1991.

  This example shows how to deal with type-extension.

*)

MODULE TestStack;

IMPORT
  st : Stack,
(*       NoGuru,
       Break,*)
  io : termio; (* same as io, has all workbench stuff removed *)

TYPE
  MyElement = POINTER TO MyElementObject;

  MyElementObject = RECORD (st.ElementObject);
    int : INTEGER;
      c : CHAR;
      l : LONGINT;
  END;

VAR
  i : INTEGER;
  myStack : st.Stack;
  myElement : MyElement; (* we need this for creation only *)
  element : st.Element;

BEGIN
  st.Create(myStack);
  IF (myStack # NIL) THEN
    i := 0;

    WHILE (i < 20) DO
      NEW(myElement);
      myElement.int := i;
      myElement.c   := CHR(i+65);
      myElement.l   := i * i;
      st.Push(myStack,myElement);
      INC(i);
    END;

    WHILE NOT st.Empty(myStack) DO
      element := st.Pop(myStack);
      IF (element IS MyElement) THEN
        WITH element : MyElement DO
          io.WriteInt(element.int,10); io.WriteString("  ");
          io.Write(element.c);
          io.WriteInt(element.l,10);
        END;
      ELSE  
        io.WriteString("Illegal stack content!\n");
      END;
      io.WriteLn;
      DISPOSE(element);
    END;
  END;
CLOSE
  IF (myStack # NIL) THEN st.Discard(myStack) END;
END TestStack.
