home *** CD-ROM | disk | FTP | other *** search
- ;;; (C) Copyright 1984 by Gold Hill Computers
-
- ;;; The TRACE facility
-
- ;;; the interface macros are:
-
- ;;; (TRACE &REST functions)
- ;;; TRACE of no args returns a list of the functions currently
- ;;; being traced.
-
- ;;; (UNTRACE &rest fcns)
- ;;; UNTRACE of no args untraces all the functions currently traced.
-
- (defvar *trace-func-spec*)
- (defvar *trace-func*)
- (defvar *trace-cnt* 0)
-
- ;; TOPLEVEL macro
- (defmacro trace x
- `(trace1 ',x))
-
- (defun trace1 (fcns &aux *trace-func*)
- (if (null fcns)
- (get 'trace 'traced-funcs)
- (progn
- (when fcns (untrace1 fcns))
- (dolist (*trace-func-spec* fcns t)
- (cond ((fboundp *trace-func-spec*)
- (untrace *trace-func-spec*)
- (setq *trace-func* (symbol-function *trace-func-spec*))
- (fset *trace-func-spec*
- (closure '(*trace-func* *trace-func-spec*)
- 'trace-internal))
- (setf (get 'trace 'traced-funcs)
- (cons *trace-func-spec* (get 'trace 'traced-funcs))))
- (t (error "~S is not a defined function."
- *trace-func-spec*)))))))
-
- ;; TOPLEVEL macro
- (defmacro untrace x
- `(untrace1 ',x))
-
- (defun untrace1 (funcs &aux untrace)
- (when (null funcs) (setq funcs (get 'trace 'traced-funcs)))
- (dolist (f funcs)
- (when (member f (get 'trace 'traced-funcs))
- (push f untrace)
- (fset (getf (cdr (symbol-function f)) '*trace-func-spec*)
- (getf (cdr (symbol-function f)) '*trace-func*))
- (setf (get 'trace 'traced-funcs)
- (delete f (get 'trace 'traced-funcs)))))
- untrace)
-
- ;; Function that is executed during a trace.
- (defun trace-internal (&rest arglist &aux value)
- (funcall *trace-output* :fresh-line)
- (dotimes (i *trace-cnt*) (funcall *trace-output* :WRITE-CHAR #\SPACE))
- (format *trace-output* "Entering: ~S, Argument list: ~S~%"
- *trace-func-spec* arglist)
- (incf *trace-cnt*)
- (unwind-protect
- (progn
- (setq value (multiple-value-list (apply *trace-func* arglist)))
- (funcall *trace-output* :fresh-line)
- (dotimes (i (1- *trace-cnt*))
- (funcall *trace-output* :WRITE-CHAR #\SPACE))
- (format *trace-output* "Exiting: ~S, Value~:[~;s list~]: ~S~%"
- *trace-func-spec* (> (length value) 1)
- (if (> (length value) 1) value (car value)))
- (values-list value))
- (decf *trace-cnt*)))