-- This is a partial dynamic implementation of the generic specification
--    for a stack abstract data type.

with Unchecked_Deallocation;

package body StackPkg2 is

    procedure Dispose is
        new Unchecked_Deallocation (Object => StackNode,
                        Name   => Stack);


    function Full (S : Stack) return Boolean is
        Tmp_Pointer : Stack;

    begin
        Tmp_Pointer := new StackNode;
        Dispose (Tmp_Pointer);
        return False;
    exception
        when STORAGE_ERROR =>
            return TRUE;
    end Full;


    procedure Push (Item : ItemType; S : in out Stack) is
    begin
        if Full (S) then
            raise Stack_Full;
        else
            S := new StackNode'(Item, S);
        end if;
    end Push;

end StackPkg2;