anchor.diff:  ;; License along with this library; if not, write to the Free Software
   ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   
  -;; $Id: gtype.lisp,v 1.11 2001-05-29 15:49:23 espen Exp $
  +;; $Id: gtype.lisp,v 1.12 2001-10-21 21:50:18 espen Exp $
   
   (in-package "GLIB")
   
  
positive.code: 
  ;;;; 
  
  (defvar *derivable-type-info* ())
  
  (defun register-derivable-type (type id &key query expand)
    (register-type type id)
    (let* ((type-number (register-type type id))
  	 (info (assoc type-number *derivable-type-info*)))
      (if info
  	(setf (cdr info) (list query expand))
        (push
         (list type-number query expand)
         *derivable-type-info*))))
  
  (defun find-type-info (type)
    (dolist (super (cdr (type-hierarchy type)))
      (let ((info (assoc super *derivable-type-info*)))
        (return-if info))))
  
  (defun type-dependencies (type)
    (let ((query (second (find-type-info type))))
      (when query
        (funcall query (find-type-number type t)))))
  
  (defun expand-type-definition (type)
    (let ((expander (third (find-type-info type))))
      (funcall expander (find-type-number type t))))
  
  (defbinding type-parent (type) type-number
    ((find-type-number type t) type-number))
  
negative.code: 
  (defun find-types (prefix)
    (let ((type-list nil))
      (maphash
       #'(lambda (type-number expander)
  	 (declare (ignore expander))
  	 (map-subtypes
  	  #'(lambda (type-number)
  	      (pushnew type-number type-list))
  	  type-number prefix))
       *derivable-type-info*)
      type-list))
  
  (defun %sort-types-topologicaly (unsorted)
    (let ((sorted ()))
      (loop while unsorted do
        (dolist (type unsorted)
  	(let ((dependencies (rest (type-hierarchy type))))
  	  (cond
  	   ((null dependencies)
  	    (push type sorted)
  	    (setq unsorted (delete type unsorted)))
  	   (t
  	    (unless (dolist (dep dependencies)
  		      (when (find type (rest (type-hierarchy dep)))
  			(error "Cyclic type dependencie"))
  		      (return-if (find dep unsorted)))
  	      (push type sorted)
  	      (setq unsorted (delete type unsorted))))))))
  