X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fdescribe.lisp;h=fc7bb94751636f5896f2a4ab8de350ec53364074;hb=31361af9eb64344f521abbb245ea784c76c746e5;hp=d53dcc62763a3f3935e0927aa923c233dba642c7;hpb=cea4896b2482b7b2b429c1631d774b4cfbc0efba;p=sbcl.git diff --git a/src/code/describe.lisp b/src/code/describe.lisp index d53dcc6..fc7bb94 100644 --- a/src/code/describe.lisp +++ b/src/code/describe.lisp @@ -10,7 +10,10 @@ ;;;; provided with absolutely no warranty. See the COPYING and CREDITS ;;;; files for more information. -(in-package "SB-IMPL") +(in-package "SB-IMPL") ;(SB-IMPL, not SB!IMPL, since we're built in warm load.) + +(declaim #.*optimize-byte-compilation*) + (defvar *describe-indentation-step* 3 #+sb-doc @@ -22,10 +25,12 @@ (defun describe (x &optional (stream-designator *standard-output*)) #+sb-doc "Print a description of the object X." + (declare #.*optimize-external-despite-byte-compilation*) (let ((stream (out-synonym-of stream-designator))) - #+nil (fresh-line stream) (pprint-logical-block (stream nil) - (describe-object x stream))) + (fresh-line stream) + (describe-object x stream) + (fresh-line stream))) (values)) ;;;; miscellaneous DESCRIBE-OBJECT methods @@ -83,7 +88,10 @@ (when (and *print-length* (> n *print-length*)) (format s "~:_...") (return)) - (format s "~:_(~S ~S)" k v))))) + (format s "~:_(~@<~S ~:_~S~:>)" k v))))) + +(defmethod describe-object ((condition condition) s) + (sb-kernel:describe-condition condition s)) ;;;; DESCRIBE-OBJECT methods for symbols and functions, including all ;;;; sorts of messy stuff about documentation, type information, @@ -91,7 +99,7 @@ ;;; Print the specified kind of documentation about the given NAME. If ;;; NAME is null, or not a valid name, then don't print anything. -(declaim (ftype (function (symbol stream t t) (values)) %describe-doc)) +(declaim (ftype (function (t stream t t) (values)) %describe-doc)) (defun %describe-doc (name s kind kind-doc) (when (and name (typep name '(or symbol cons))) (let ((doc (fdocumentation name kind))) @@ -101,28 +109,33 @@ (values)) ;;; Describe various stuff about the functional semantics attached to -;;; the specified Name. Type-Spec is the function type specifier +;;; the specified NAME, if NAME is the kind of thing you can look +;;; up as a name. (In the case of anonymous closures and other +;;; things, it might not be.) TYPE-SPEC is the function type specifier ;;; extracted from the definition, or NIL if none. -(declaim (ftype (function ((or symbol cons) stream t)) %describe-function-name)) +(declaim (ftype (function (t stream t)) %describe-function-name)) (defun %describe-function-name (name s type-spec) - (multiple-value-bind (type where) - (if (or (symbolp name) (and (listp name) (eq (car name) 'setf))) - (values (type-specifier (info :function :type name)) - (info :function :where-from name)) - (values type-spec :defined)) - (when (consp type) - (format s "~@:_Its ~(~A~) argument types are:~@:_ ~S" - where (second type)) - (format s "~@:_Its result type is:~@:_ ~S" (third type)))) - (let ((inlinep (info :function :inlinep name))) - (when inlinep - (format s "~@:_It is currently declared ~(~A~);~ + (when (and name (typep name '(or symbol cons))) + (multiple-value-bind (type where) + (if (or (symbolp name) (and (listp name) (eq (car name) 'setf))) + (values (type-specifier (info :function :type name)) + (info :function :where-from name)) + (values type-spec :defined)) + (when (consp type) + (format s "~@:_Its ~(~A~) argument types are:~@:_ ~S" + where (second type)) + (format s "~@:_Its result type is:~@:_ ~S" (third type)))) + (let ((inlinep (info :function :inlinep name))) + (when inlinep + (format s + "~@:_It is currently declared ~(~A~);~ ~:[no~;~] expansion is available." - inlinep (info :function :inline-expansion name))))) + inlinep (info :function :inline-expansion name)))))) ;;; Interpreted function describing; handles both closure and ;;; non-closure functions. Instead of printing the compiled-from info, ;;; we print the definition. +#+sb-interpreter (defun %describe-function-interpreted (x s kind name) (declare (type stream s)) (multiple-value-bind (exp closure-p dname) @@ -140,12 +153,12 @@ s (type-specifier (sb-eval:interpreted-function-type x))))) (when closure-p - (format s "~@:_Its closure environment is:") + (format s "~@:_Its closure environment is:~%") (pprint-logical-block (s nil) (pprint-indent :current 2) - (let ((clos (sb-eval:interpreted-function-closure x))) - (dotimes (i (length clos)) - (format s "~@:_~S: ~S" i (svref clos i)))))) + (let ((closure (sb-eval:interpreted-function-closure x))) + (dotimes (i (length closure)) + (format s "~@:_~S: ~S" i (svref closure i)))))) (format s "~@:_Its definition is:~@:_ ~S" exp))) ;;; Print information from the debug-info about where CODE-OBJ was @@ -155,25 +168,23 @@ (let ((info (sb-kernel:%code-debug-info code-obj))) (when info (let ((sources (sb-c::debug-info-source info))) - (format s "~@:_On ~A it was compiled from:" - ;; FIXME: The FORMAT-UNIVERSAL-TIME calls in the system - ;; should become more consistent, probably not using - ;; any nondefault options. - (format-universal-time nil - (sb-c::debug-source-compiled - (first sources)) - :style :abbreviated)) - (dolist (source sources) - (let ((name (sb-c::debug-source-name source))) - (ecase (sb-c::debug-source-from source) - (:file - (format s "~@:_~A~@:_ Created: " (namestring name)) - (sb-int:format-universal-time t (sb-c::debug-source-created - source)) - (let ((comment (sb-c::debug-source-comment source))) - (when comment - (format s "~@:_ Comment: ~A" comment)))) - (:lisp (format s "~@:_~S" name))))))))) + (when sources + (format s "~@:_On ~A it was compiled from:" + ;; FIXME: The FORMAT-UNIVERSAL-TIME calls in the system + ;; should become more consistent, probably not using + ;; any nondefault options. + (format-universal-time nil + (sb-c::debug-source-compiled + (first sources)) + :style :abbreviated)) + (dolist (source sources) + (let ((name (sb-c::debug-source-name source))) + (ecase (sb-c::debug-source-from source) + (:file + (format s "~@:_~A~@:_ Created: " (namestring name)) + (format-universal-time s (sb-c::debug-source-created + source))) + (:lisp (format s "~@:_~S" name)))))))))) ;;; Describe a compiled function. The closure case calls us to print ;;; the guts. @@ -246,6 +257,7 @@ (let ((data (byte-closure-data x))) (dotimes (i (length data)) (format s "~@:_~S: ~S" i (svref data i)))))) + #+sb-interpreter (sb-eval:interpreted-function (%describe-function-interpreted x s kind name)) (standard-generic-function @@ -269,9 +281,9 @@ (multiple-value-bind (symbol status) (find-symbol (symbol-name x) package) (declare (ignore symbol)) - (format s "~S is an ~(~A~) symbol in ~S." + (format s "~S is ~_an ~(~A~) symbol ~_in ~S." x status (symbol-package x))) - (format s "~S is an uninterned symbol." x))) + (format s "~S is ~_an uninterned symbol." x))) ;; TO DO: We could grovel over all packages looking for and ;; reporting other phenomena, e.g. IMPORT and SHADOW, or ;; availability in some package even after (SYMBOL-PACKAGE X) has @@ -294,12 +306,12 @@ (format s "~@" (eval x)))) ((boundp x) - (format s "~@:_It is a ~A; its value is ~S." wot (symbol-value x))) + (format s "~@:_It is a ~A; its ~_value is ~S." wot (symbol-value x))) ((not (eq kind :global)) (format s "~@:_It is a ~A; no current value." wot))) (when (eq (info :variable :where-from x) :declared) - (format s "~@:_Its declared type is ~S." + (format s "~@:_Its declared type ~_is ~S." (type-specifier (info :variable :type x)))) (%describe-doc x s 'variable kind)) @@ -315,18 +327,25 @@ ((fboundp x) (%describe-function (fdefinition x) s :function x))) - ;; TO DO: Print out other stuff from the INFO database: - ;; * Does it name a type or class? - ;; * Is it a structure accessor? (important since those are + ;; FIXME: Print out other stuff from the INFO database: + ;; * Does it name a type? + ;; * Is it a structure accessor? (This is important since those are ;; magical in some ways, e.g. blasting the structure if you - ;; redefine them) + ;; redefine them.) ;; Print other documentation. (%describe-doc x s 'structure "Structure") (%describe-doc x s 'type "Type") (%describe-doc x s 'setf "Setf macro") + (dolist (assoc (info :random-documentation :stuff x)) (format s "~@:_Documentation on the ~(~A~):~@:_~A" (car assoc) - (cdr assoc)))) + (cdr assoc))) + + ;; Describe the associated class, if any. + (let ((symbol-named-class (cl:find-class x nil))) + (when symbol-named-class + (format t "~&It names a class ~A." symbol-named-class) + (describe symbol-named-class))))