|
40 | 40 | (%write-result-captures result stream) |
41 | 41 | (%write-result-ctx result stream)))) |
42 | 42 |
|
43 | | -;;; Remove % and %% (see CAPTURE), so that they don't pollute the form |
44 | | -;;; displayed in the events. KLUDGE: We should use a proper code |
45 | | -;;; walker, but we simply assume that all % and %% are to be removed. |
46 | | -;;; FIXME: Infinite loop on #1=(#1#) or #1=(% #1#). |
| 43 | +(declaim (ftype function capture-subform capture-explicitp)) |
| 44 | + |
| 45 | +;;; Remove % and %% (see CAPTURE) in explicit captures, so that they |
| 46 | +;;; don't pollute the form displayed in the events. |
47 | 47 | (defun %frob-form-for-printing (result form) |
48 | 48 | ;; Memoize the results so that printing a result twice writes EQ |
49 | 49 | ;; objects and *PRINT-CIRCLE* thus works. |
50 | 50 | (let ((data (print-form-memoization-data result))) |
51 | | - (labels ((frob (form) |
| 51 | + (labels ((explicitly-captured-p (subform) |
| 52 | + (loop for capture in (captures result) |
| 53 | + thereis (and (capture-explicitp capture) |
| 54 | + (eq subform (capture-subform capture))))) |
| 55 | + (frob (form) |
52 | 56 | (or (gethash form data) |
53 | 57 | (cond |
54 | | - ;; Basically ATOM, but also include improper |
55 | | - ;; lists. |
56 | | - ((not (alexandria:proper-list-p form)) |
| 58 | + ((atom form) |
57 | 59 | form) |
58 | | - ((and (member (first form) '(% %%)) |
59 | | - ;; Catch circles in code. |
| 60 | + ((and (member (car form) '(% %%)) |
| 61 | + ;; See if it's a proper list of length 2. |
| 62 | + (consp (cdr form)) |
60 | 63 | (null (cddr form)) |
61 | | - (= (length form) 2)) |
62 | | - (setf (gethash form data) (frob (second form)))) |
| 64 | + (explicitly-captured-p (second form))) |
| 65 | + (let* ((subform (second form)) |
| 66 | + (frobbed (frob subform))) |
| 67 | + (setf (gethash subform data) frobbed) |
| 68 | + (values frobbed t))) |
63 | 69 | (t |
64 | | - (setf (gethash form data) |
65 | | - (mapcar #'frob form))))))) |
| 70 | + (let ((new (cons nil nil))) |
| 71 | + (setf (gethash form data) new) |
| 72 | + (multiple-value-bind (car car-frobbed?) |
| 73 | + (frob (car form)) |
| 74 | + (multiple-value-bind (cdr cdr-frobbed?) |
| 75 | + (frob (cdr form)) |
| 76 | + (cond ((or car-frobbed? cdr-frobbed?) |
| 77 | + (setf (car new) car |
| 78 | + (cdr new) cdr) |
| 79 | + (values new t)) |
| 80 | + (t |
| 81 | + (setf (gethash form data) form))))))))))) |
66 | 82 | (frob form)))) |
67 | 83 |
|
68 | 84 | (defun %write-result-msg (result stream &key terse) |
|
0 commit comments