1 ;;;; tests for the code walker
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from software originally released by Xerox
7 ;;;; Corporation. Copyright and release statements follow. Later modifications
8 ;;;; to the software are in the public domain and are provided with
9 ;;;; absolutely no warranty. See the COPYING and CREDITS files for more
12 ;;;; copyright information from original PCL sources:
14 ;;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
15 ;;;; All rights reserved.
17 ;;;; Use and copying of this software and preparation of derivative works based
18 ;;;; upon this software are permitted. Any distribution of this software or
19 ;;;; derivative works must comply with all applicable United States export
22 ;;;; This software is made available AS IS, and Xerox Corporation makes no
23 ;;;; warranty about the software, its performance or its conformity to any
26 (in-package :sb-walker)
28 ;;;; utilities to support tests
30 ;;; string equality modulo deletion of TABs and SPACEs (as a crude way
31 ;;; of washing away irrelevant differences in indentation)
32 (defun string-modulo-tabspace (s)
33 (remove-if (lambda (c)
38 (defun string=-modulo-tabspace (x y)
39 (if (string= (string-modulo-tabspace x)
40 (string-modulo-tabspace y))
43 (print (list :want y :got x))
46 ;;;; tests based on stuff at the end of the original CMU CL
47 ;;;; pcl/walk.lisp file
49 (defmacro take-it-out-for-a-test-walk (form)
50 `(take-it-out-for-a-test-walk-1 ',form))
52 (defun take-it-out-for-a-test-walk-1 (form)
53 (let ((copy-of-form (copy-tree form))
54 (result (walk-form form nil
56 (format t "~&Form: ~S ~3T Context: ~A" x y)
58 (let ((lexical (var-lexical-p x env))
59 (special (var-special-p x env)))
62 (format t "lexically bound"))
65 (format t "declared special"))
68 (format t "bound: ~S " (eval x)))))
70 (cond ((not (equal result copy-of-form))
71 (format t "~%Warning: Result not EQUAL to copy of start."))
72 ((not (eq result form))
73 (format t "~%Warning: Result not EQ to copy of start.")))
77 (defmacro foo (&rest ignore)
78 (declare (ignore ignore))
81 (defmacro bar (&rest ignore)
82 (declare (ignore ignore))
85 (assert (string=-modulo-tabspace
86 (with-output-to-string (*standard-output*)
87 (take-it-out-for-a-test-walk (list arg1 arg2 arg3)))
88 "Form: (LIST ARG1 ARG2 ARG3) Context: EVAL
89 Form: ARG1 Context: EVAL
90 Form: ARG2 Context: EVAL
91 Form: ARG3 Context: EVAL
92 (LIST ARG1 ARG2 ARG3)"))
94 (assert (string=-modulo-tabspace
95 (with-output-to-string (*standard-output*)
96 (take-it-out-for-a-test-walk (list (cons 1 2) (list 3 4 5))))
97 "Form: (LIST (CONS 1 2) (LIST 3 4 5)) Context: EVAL
98 Form: (CONS 1 2) Context: EVAL
100 Form: 2 Context: EVAL
101 Form: (LIST 3 4 5) Context: EVAL
102 Form: 3 Context: EVAL
103 Form: 4 Context: EVAL
104 Form: 5 Context: EVAL
105 (LIST (CONS 1 2) (LIST 3 4 5))"))
107 (assert (string=-modulo-tabspace
108 (with-output-to-string (*standard-output*)
109 (take-it-out-for-a-test-walk (progn (foo) (bar 1))))
110 "Form: (PROGN (FOO) (BAR 1)) Context: EVAL
111 Form: (FOO) Context: EVAL
112 Form: 'GLOBAL-FOO Context: EVAL
113 Form: (BAR 1) Context: EVAL
114 Form: 'GLOBAL-BAR Context: EVAL
115 (PROGN (FOO) (BAR 1))"))
117 (assert (string=-modulo-tabspace
118 (with-output-to-string (*standard-output*)
119 (take-it-out-for-a-test-walk (block block-name a b c)))
120 "Form: (BLOCK BLOCK-NAME A B C) Context: EVAL
121 Form: A Context: EVAL
122 Form: B Context: EVAL
123 Form: C Context: EVAL
124 (BLOCK BLOCK-NAME A B C)"))
126 (assert (string=-modulo-tabspace
127 (with-output-to-string (*standard-output*)
128 (take-it-out-for-a-test-walk (block block-name (list a) b c)))
129 "Form: (BLOCK BLOCK-NAME (LIST A) B C) Context: EVAL
130 Form: (LIST A) Context: EVAL
131 Form: A Context: EVAL
132 Form: B Context: EVAL
133 Form: C Context: EVAL
134 (BLOCK BLOCK-NAME (LIST A) B C)"))
136 (assert (string=-modulo-tabspace
137 (with-output-to-string (*standard-output*)
138 (take-it-out-for-a-test-walk (catch catch-tag (list a) b c)))
139 "Form: (CATCH CATCH-TAG (LIST A) B C) Context: EVAL
140 Form: CATCH-TAG Context: EVAL
141 Form: (LIST A) Context: EVAL
142 Form: A Context: EVAL
143 Form: B Context: EVAL
144 Form: C Context: EVAL
145 (CATCH CATCH-TAG (LIST A) B C)"))
147 ;;; This is a fairly simple MACROLET case. While walking the body of the
148 ;;; macro, X should be lexically bound. In the body of the MACROLET form
149 ;;; itself, X should not be bound.
150 (assert (string=-modulo-tabspace
151 (with-output-to-string (*standard-output*)
152 (take-it-out-for-a-test-walk
153 (macrolet ((foo (x) (list x) ''inner))
156 "Form: (MACROLET ((FOO (X)
160 (FOO 1)) Context: EVAL
161 Form: (LIST X) Context: EVAL
162 Form: X Context: EVAL; lexically bound
163 Form: ''INNER Context: EVAL
164 Form: X Context: EVAL
165 Form: (FOO 1) Context: EVAL
166 Form: 'INNER Context: EVAL
174 ;;; The original PCL documentation for this test said
175 ;;; A slightly more complex MACROLET case. In the body of the macro
176 ;;; X should not be lexically bound. In the body of the macrolet
177 ;;; form itself X should be bound. Note that THIS CASE WILL CAUSE AN
178 ;;; ERROR when it tries to macroexpand the call to FOO.
180 ;;; This test is commented out in SBCL because ANSI says, in the
181 ;;; definition of the special operator MACROLET,
182 ;;; The macro-expansion functions defined by MACROLET are defined
183 ;;; in the lexical environment in which the MACROLET form appears.
184 ;;; Declarations and MACROLET and SYMBOL-MACROLET definitions affect
185 ;;; the local macro definitions in a MACROLET, but the consequences
186 ;;; are undefined if the local macro definitions reference any
187 ;;; local variable or function bindings that are visible in that
188 ;;; lexical environment.
189 ;;; Since the behavior is undefined, anything we do conforms.:-|
190 ;;; This is of course less than ideal; see bug 124.
192 (multiple-value-bind (res cond)
194 (take-it-out-for-a-test-walk
196 (macrolet ((foo () (list x) ''inner))
199 (assert (and (null res) cond)))
201 (assert (string=-modulo-tabspace
202 (with-output-to-string (*standard-output*)
203 (take-it-out-for-a-test-walk
204 (flet ((foo (x) (list x y))
205 (bar (x) (list x y)))
207 "Form: (FLET ((FOO (X)
211 (FOO 1)) Context: EVAL
212 Form: (LIST X Y) Context: EVAL
213 Form: X Context: EVAL; lexically bound
214 Form: Y Context: EVAL
215 Form: (LIST X Y) Context: EVAL
216 Form: X Context: EVAL; lexically bound
217 Form: Y Context: EVAL
218 Form: (FOO 1) Context: EVAL
219 Form: 1 Context: EVAL
226 (assert (string=-modulo-tabspace
227 (with-output-to-string (*standard-output*)
228 (take-it-out-for-a-test-walk
230 (flet ((foo (x) (list x y))
231 (bar (x) (list x y)))
238 (FOO 1))) Context: EVAL
239 Form: 2 Context: EVAL
240 Form: (FLET ((FOO (X)
244 (FOO 1)) Context: EVAL
245 Form: (LIST X Y) Context: EVAL
246 Form: X Context: EVAL; lexically bound
247 Form: Y Context: EVAL; lexically bound
248 Form: (LIST X Y) Context: EVAL
249 Form: X Context: EVAL; lexically bound
250 Form: Y Context: EVAL; lexically bound
251 Form: (FOO 1) Context: EVAL
252 Form: 1 Context: EVAL
260 (assert (string=-modulo-tabspace
261 (with-output-to-string (*standard-output*)
262 (take-it-out-for-a-test-walk
263 (labels ((foo (x) (bar x))
266 "Form: (LABELS ((FOO (X)
270 (FOO 1)) Context: EVAL
271 Form: (BAR X) Context: EVAL
272 Form: X Context: EVAL; lexically bound
273 Form: (FOO X) Context: EVAL
274 Form: X Context: EVAL; lexically bound
275 Form: (FOO 1) Context: EVAL
276 Form: 1 Context: EVAL
283 (assert (string=-modulo-tabspace
284 (with-output-to-string (*standard-output*)
285 (take-it-out-for-a-test-walk
286 (flet ((foo (x) (foo x)))
288 "Form: (FLET ((FOO (X)
290 (FOO 1)) Context: EVAL
291 Form: (FOO X) Context: EVAL
292 Form: 'GLOBAL-FOO Context: EVAL
293 Form: (FOO 1) Context: EVAL
294 Form: 1 Context: EVAL
299 (assert (string=-modulo-tabspace
300 (with-output-to-string (*standard-output*)
301 (take-it-out-for-a-test-walk
302 (flet ((foo (x) (foo x)))
303 (flet ((bar (x) (foo x)))
305 "Form: (FLET ((FOO (X)
309 (BAR 1))) Context: EVAL
310 Form: (FOO X) Context: EVAL
311 Form: 'GLOBAL-FOO Context: EVAL
312 Form: (FLET ((BAR (X)
314 (BAR 1)) Context: EVAL
315 Form: (FOO X) Context: EVAL
316 Form: X Context: EVAL; lexically bound
317 Form: (BAR 1) Context: EVAL
318 Form: 1 Context: EVAL
325 (assert (string=-modulo-tabspace
326 (with-output-to-string (*standard-output*)
327 (take-it-out-for-a-test-walk (prog () (declare (special a b)))))
328 "Form: (PROG () (DECLARE (SPECIAL A B))) Context: EVAL
331 (DECLARE (SPECIAL A B))
332 (TAGBODY))) Context: EVAL
334 (DECLARE (SPECIAL A B))
335 (TAGBODY)) Context: EVAL
336 Form: (TAGBODY) Context: EVAL
337 (PROG () (DECLARE (SPECIAL A B)))"))
339 (assert (string=-modulo-tabspace
340 (with-output-to-string (*standard-output*)
341 (take-it-out-for-a-test-walk (let (a b c)
342 (declare (special a b))
345 (DECLARE (SPECIAL A B))
349 Form: (FOO A) Context: EVAL
350 Form: 'GLOBAL-FOO Context: EVAL
351 Form: B Context: EVAL; lexically bound; declared special
352 Form: C Context: EVAL; lexically bound
354 (DECLARE (SPECIAL A B))
359 (assert (string=-modulo-tabspace
360 (with-output-to-string (*standard-output*)
361 (take-it-out-for-a-test-walk (let (a b c)
362 (declare (special a) (special b))
365 (DECLARE (SPECIAL A) (SPECIAL B))
369 Form: (FOO A) Context: EVAL
370 Form: 'GLOBAL-FOO Context: EVAL
371 Form: B Context: EVAL; lexically bound; declared special
372 Form: C Context: EVAL; lexically bound
374 (DECLARE (SPECIAL A) (SPECIAL B))
379 (assert (string=-modulo-tabspace
380 (with-output-to-string (*standard-output*)
381 (take-it-out-for-a-test-walk (let (a b c)
382 (declare (special a))
383 (declare (special b))
386 (DECLARE (SPECIAL A))
387 (DECLARE (SPECIAL B))
391 Form: (FOO A) Context: EVAL
392 Form: 'GLOBAL-FOO Context: EVAL
393 Form: B Context: EVAL; lexically bound; declared special
394 Form: C Context: EVAL; lexically bound
396 (DECLARE (SPECIAL A))
397 (DECLARE (SPECIAL B))
402 (assert (string=-modulo-tabspace
403 (with-output-to-string (*standard-output*)
404 (take-it-out-for-a-test-walk (let (a b c)
405 (declare (special a))
406 (declare (special b))
410 (DECLARE (SPECIAL A))
411 (DECLARE (SPECIAL B))
420 Form: 1 Context: EVAL
421 Form: (FOO A) Context: EVAL
422 Form: 'GLOBAL-FOO Context: EVAL
423 Form: B Context: EVAL; lexically bound; declared special
424 Form: C Context: EVAL; lexically bound
426 (DECLARE (SPECIAL A))
427 (DECLARE (SPECIAL B))
433 (assert (string=-modulo-tabspace
434 (with-output-to-string (*standard-output*)
435 (take-it-out-for-a-test-walk (eval-when ()
438 "Form: (EVAL-WHEN NIL A (FOO A)) Context: EVAL
439 Form: A Context: EVAL
440 Form: (FOO A) Context: EVAL
441 Form: 'GLOBAL-FOO Context: EVAL
442 (EVAL-WHEN NIL A (FOO A))"))
444 (assert (string=-modulo-tabspace
445 (with-output-to-string (*standard-output*)
446 (take-it-out-for-a-test-walk
447 (eval-when (:execute :compile-toplevel :load-toplevel)
450 "Form: (EVAL-WHEN (:EXECUTE :COMPILE-TOPLEVEL :LOAD-TOPLEVEL) A (FOO A)) Context: EVAL
451 Form: A Context: EVAL
452 Form: (FOO A) Context: EVAL
453 Form: 'GLOBAL-FOO Context: EVAL
454 (EVAL-WHEN (:EXECUTE :COMPILE-TOPLEVEL :LOAD-TOPLEVEL) A (FOO A))"))
456 (assert (string=-modulo-tabspace
457 (with-output-to-string (*standard-output*)
458 (take-it-out-for-a-test-walk (multiple-value-bind (a b)
459 (foo a b) (list a b))))
460 "Form: (MULTIPLE-VALUE-BIND (A B) (FOO A B) (LIST A B)) Context: EVAL
461 Form: (FOO A B) Context: EVAL
462 Form: 'GLOBAL-FOO Context: EVAL
463 Form: (LIST A B) Context: EVAL
464 Form: A Context: EVAL; lexically bound
465 Form: B Context: EVAL; lexically bound
466 (MULTIPLE-VALUE-BIND (A B) (FOO A B) (LIST A B))"))
468 (assert (string=-modulo-tabspace
469 (with-output-to-string (*standard-output*)
470 (take-it-out-for-a-test-walk (multiple-value-bind (a b)
472 (declare (special a))
474 "Form: (MULTIPLE-VALUE-BIND (A B) (FOO A B) (DECLARE (SPECIAL A)) (LIST A B)) Context: EVAL
475 Form: (FOO A B) Context: EVAL
476 Form: 'GLOBAL-FOO Context: EVAL
477 Form: (LIST A B) Context: EVAL
478 Form: A Context: EVAL; lexically bound; declared special
479 Form: B Context: EVAL; lexically bound
480 (MULTIPLE-VALUE-BIND (A B) (FOO A B) (DECLARE (SPECIAL A)) (LIST A B))"))
482 (assert (string=-modulo-tabspace
483 (with-output-to-string (*standard-output*)
484 (take-it-out-for-a-test-walk (progn (function foo))))
485 "Form: (PROGN #'FOO) Context: EVAL
486 Form: #'FOO Context: EVAL
489 (assert (string=-modulo-tabspace
490 (with-output-to-string (*standard-output*)
491 (take-it-out-for-a-test-walk (progn a b (go a))))
492 "Form: (PROGN A B (GO A)) Context: EVAL
493 Form: A Context: EVAL
494 Form: B Context: EVAL
495 Form: (GO A) Context: EVAL
496 (PROGN A B (GO A))"))
498 (assert (string=-modulo-tabspace
499 (with-output-to-string (*standard-output*)
500 (take-it-out-for-a-test-walk (if a b c)))
501 "Form: (IF A B C) Context: EVAL
502 Form: A Context: EVAL
503 Form: B Context: EVAL
504 Form: C Context: EVAL
507 (assert (string=-modulo-tabspace
508 (with-output-to-string (*standard-output*)
509 (take-it-out-for-a-test-walk (if a b)))
510 "Form: (IF A B) Context: EVAL
511 Form: A Context: EVAL
512 Form: B Context: EVAL
513 Form: NIL Context: EVAL; bound: NIL
516 (assert (string=-modulo-tabspace
517 (with-output-to-string (*standard-output*)
518 (take-it-out-for-a-test-walk ((lambda (a b) (list a b)) 1 2)))
519 "Form: ((LAMBDA (A B) (LIST A B)) 1 2) Context: EVAL
520 Form: (LAMBDA (A B) (LIST A B)) Context: EVAL
521 Form: (LIST A B) Context: EVAL
522 Form: A Context: EVAL; lexically bound
523 Form: B Context: EVAL; lexically bound
524 Form: 1 Context: EVAL
525 Form: 2 Context: EVAL
526 ((LAMBDA (A B) (LIST A B)) 1 2)"))
528 (assert (string=-modulo-tabspace
529 (with-output-to-string (*standard-output*)
530 (take-it-out-for-a-test-walk ((lambda (a b)
531 (declare (special a))
534 "Form: ((LAMBDA (A B) (DECLARE (SPECIAL A)) (LIST A B)) 1 2) Context: EVAL
535 Form: (LAMBDA (A B) (DECLARE (SPECIAL A)) (LIST A B)) Context: EVAL
536 Form: (LIST A B) Context: EVAL
537 Form: A Context: EVAL; lexically bound; declared special
538 Form: B Context: EVAL; lexically bound
539 Form: 1 Context: EVAL
540 Form: 2 Context: EVAL
541 ((LAMBDA (A B) (DECLARE (SPECIAL A)) (LIST A B)) 1 2)"))
543 (assert (string=-modulo-tabspace
544 (with-output-to-string (*standard-output*)
545 (take-it-out-for-a-test-walk (let ((a a) (b a) (c b))
547 "Form: (LET ((A A) (B A) (C B))
548 (LIST A B C)) Context: EVAL
549 Form: A Context: EVAL
550 Form: A Context: EVAL
551 Form: B Context: EVAL
552 Form: (LIST A B C) Context: EVAL
553 Form: A Context: EVAL; lexically bound
554 Form: B Context: EVAL; lexically bound
555 Form: C Context: EVAL; lexically bound
556 (LET ((A A) (B A) (C B))
559 (assert (string=-modulo-tabspace
560 (with-output-to-string (*standard-output*)
561 (take-it-out-for-a-test-walk (let* ((a a) (b a) (c b)) (list a b c))))
562 "Form: (LET* ((A A) (B A) (C B))
563 (LIST A B C)) Context: EVAL
564 Form: A Context: EVAL
565 Form: A Context: EVAL; lexically bound
566 Form: B Context: EVAL; lexically bound
567 Form: (LIST A B C) Context: EVAL
568 Form: A Context: EVAL; lexically bound
569 Form: B Context: EVAL; lexically bound
570 Form: C Context: EVAL; lexically bound
571 (LET* ((A A) (B A) (C B))
574 (assert (string=-modulo-tabspace
575 (with-output-to-string (*standard-output*)
576 (take-it-out-for-a-test-walk (let ((a a) (b a) (c b))
577 (declare (special a b))
579 "Form: (LET ((A A) (B A) (C B))
580 (DECLARE (SPECIAL A B))
581 (LIST A B C)) Context: EVAL
582 Form: A Context: EVAL
583 Form: A Context: EVAL
584 Form: B Context: EVAL
585 Form: (LIST A B C) Context: EVAL
586 Form: A Context: EVAL; lexically bound; declared special
587 Form: B Context: EVAL; lexically bound; declared special
588 Form: C Context: EVAL; lexically bound
589 (LET ((A A) (B A) (C B))
590 (DECLARE (SPECIAL A B))
593 ;;;; Bug in LET* walking!
594 (test-util:with-test (:name (:walk-let* :hairy-specials)
597 (string=-modulo-tabspace
598 (with-output-to-string (*standard-output*)
599 (take-it-out-for-a-test-walk (let* ((a a) (b a) (c b))
600 (declare (special a b))
602 "Form: (LET* ((A A) (B A) (C B))
603 (DECLARE (SPECIAL A B))
604 (LIST A B C)) Context: EVAL
605 Form: A Context: EVAL
606 Form: A Context: EVAL; lexically bound; declared special
607 Form: B Context: EVAL; lexically bound; declared special
608 Form: (LIST A B C) Context: EVAL
609 Form: A Context: EVAL; lexically bound; declared special
610 Form: B Context: EVAL; lexically bound; declared special
611 Form: C Context: EVAL; lexically bound
612 (LET* ((A A) (B A) (C B))
613 (DECLARE (SPECIAL A B))
616 (assert (string=-modulo-tabspace
617 (with-output-to-string (*standard-output*)
618 (take-it-out-for-a-test-walk (let ((a 1) (b 2))
621 (declare (special a))
623 "Form: (LET ((A 1) (B 2))
626 (DECLARE (SPECIAL A))
627 (FOO A B))) Context: EVAL
628 Form: 1 Context: EVAL
629 Form: 2 Context: EVAL
630 Form: (FOO BAR) Context: EVAL
631 Form: 'GLOBAL-FOO Context: EVAL
633 (DECLARE (SPECIAL A))
634 (FOO A B)) Context: EVAL
635 Form: (FOO A B) Context: EVAL
636 Form: 'GLOBAL-FOO Context: EVAL
640 (DECLARE (SPECIAL A))
643 (assert (string=-modulo-tabspace
644 (with-output-to-string (*standard-output*)
645 (take-it-out-for-a-test-walk (multiple-value-call #'foo a b c)))
646 "Form: (MULTIPLE-VALUE-CALL #'FOO A B C) Context: EVAL
647 Form: #'FOO Context: EVAL
648 Form: A Context: EVAL
649 Form: B Context: EVAL
650 Form: C Context: EVAL
651 (MULTIPLE-VALUE-CALL #'FOO A B C)"))
653 (assert (string=-modulo-tabspace
654 (with-output-to-string (*standard-output*)
655 (take-it-out-for-a-test-walk (multiple-value-prog1 a b c)))
656 "Form: (MULTIPLE-VALUE-PROG1 A B C) Context: EVAL
657 Form: A Context: EVAL
658 Form: B Context: EVAL
659 Form: C Context: EVAL
660 (MULTIPLE-VALUE-PROG1 A B C)"))
662 (assert (string=-modulo-tabspace
663 (with-output-to-string (*standard-output*)
664 (take-it-out-for-a-test-walk (progn a b c)))
665 "Form: (PROGN A B C) Context: EVAL
666 Form: A Context: EVAL
667 Form: B Context: EVAL
668 Form: C Context: EVAL
671 (assert (string=-modulo-tabspace
672 (with-output-to-string (*standard-output*)
673 (take-it-out-for-a-test-walk (progv vars vals a b c)))
674 "Form: (PROGV VARS VALS A B C) Context: EVAL
675 Form: VARS Context: EVAL
676 Form: VALS Context: EVAL
677 Form: A Context: EVAL
678 Form: B Context: EVAL
679 Form: C Context: EVAL
680 (PROGV VARS VALS A B C)"))
682 (assert (string=-modulo-tabspace
683 (with-output-to-string (*standard-output*)
684 (take-it-out-for-a-test-walk (quote a)))
685 "Form: 'A Context: EVAL
688 (assert (string=-modulo-tabspace
689 (with-output-to-string (*standard-output*)
690 (take-it-out-for-a-test-walk (return-from block-name a b c)))
691 "Form: (RETURN-FROM BLOCK-NAME A B C) Context: EVAL
692 Form: A Context: EVAL
693 Form: B Context: EVAL
694 Form: C Context: EVAL
695 (RETURN-FROM BLOCK-NAME A B C)"))
697 (assert (string=-modulo-tabspace
698 (with-output-to-string (*standard-output*)
699 (take-it-out-for-a-test-walk (setq a 1)))
700 "Form: (SETQ A 1) Context: EVAL
702 Form: 1 Context: EVAL
706 (assert (string=-modulo-tabspace
707 (with-output-to-string (*standard-output*)
708 (take-it-out-for-a-test-walk (setq a (foo 1) b (bar 2) c 3)))
709 "Form: (SETQ A (FOO 1) B (BAR 2) C 3) Context: EVAL
710 Form: (SETQ A (FOO 1)) Context: EVAL
712 Form: (FOO 1) Context: EVAL
713 Form: 'GLOBAL-FOO Context: EVAL
714 Form: (SETQ B (BAR 2)) Context: EVAL
716 Form: (BAR 2) Context: EVAL
717 Form: 'GLOBAL-BAR Context: EVAL
718 Form: (SETQ C 3) Context: EVAL
720 Form: 3 Context: EVAL
721 (SETQ A (FOO 1) B (BAR 2) C 3)"))
726 (assert (string=-modulo-tabspace
727 (with-output-to-string (*standard-output*)
728 (take-it-out-for-a-test-walk (tagbody a b c (go a))))
729 "Form: (TAGBODY A B C (GO A)) Context: EVAL
730 Form: A Context: QUOTE
731 Form: B Context: QUOTE
732 Form: C Context: QUOTE
733 Form: (GO A) Context: EVAL
734 (TAGBODY A B C (GO A))"))
736 (assert (string=-modulo-tabspace
737 (with-output-to-string (*standard-output*)
738 (take-it-out-for-a-test-walk (the foo (foo-form a b c))))
739 "Form: (THE FOO (FOO-FORM A B C)) Context: EVAL
740 Form: (FOO-FORM A B C) Context: EVAL
741 Form: A Context: EVAL
742 Form: B Context: EVAL
743 Form: C Context: EVAL
744 (THE FOO (FOO-FORM A B C))"))
746 (assert (string=-modulo-tabspace
747 (with-output-to-string (*standard-output*)
748 (take-it-out-for-a-test-walk (throw tag-form a)))
749 "Form: (THROW TAG-FORM A) Context: EVAL
750 Form: TAG-FORM Context: EVAL
751 Form: A Context: EVAL
752 (THROW TAG-FORM A)"))
754 (assert (string=-modulo-tabspace
755 (with-output-to-string (*standard-output*)
756 (take-it-out-for-a-test-walk (unwind-protect (foo a b) d e f)))
757 "Form: (UNWIND-PROTECT (FOO A B) D E F) Context: EVAL
758 Form: (FOO A B) Context: EVAL
759 Form: 'GLOBAL-FOO Context: EVAL
760 Form: D Context: EVAL
761 Form: E Context: EVAL
762 Form: F Context: EVAL
763 (UNWIND-PROTECT (FOO A B) D E F)"))
765 (defmacro flet-1 (a b)
766 (declare (ignore a b))
769 (defmacro labels-1 (a b)
770 (declare (ignore a b))
773 (assert (string=-modulo-tabspace
774 (with-output-to-string (*standard-output*)
775 (take-it-out-for-a-test-walk
776 (flet ((flet-1 (a b) () (flet-1 a b) (list a b)))
779 "Form: (FLET ((FLET-1 (A B)
784 (FOO 1 2)) Context: EVAL
785 Form: NIL Context: EVAL; bound: NIL
786 Form: (FLET-1 A B) Context: EVAL
787 Form: 'OUTER Context: EVAL
788 Form: (LIST A B) Context: EVAL
789 Form: A Context: EVAL; lexically bound
790 Form: B Context: EVAL; lexically bound
791 Form: (FLET-1 1 2) Context: EVAL
792 Form: 1 Context: EVAL
793 Form: 2 Context: EVAL
794 Form: (FOO 1 2) Context: EVAL
795 Form: 'GLOBAL-FOO Context: EVAL
803 (assert (string=-modulo-tabspace
804 (with-output-to-string (*standard-output*)
805 (take-it-out-for-a-test-walk
806 (labels ((label-1 (a b) () (label-1 a b)(list a b)))
809 "Form: (LABELS ((LABEL-1 (A B)
814 (FOO 1 2)) Context: EVAL
815 Form: NIL Context: EVAL; bound: NIL
816 Form: (LABEL-1 A B) Context: EVAL
817 Form: A Context: EVAL; lexically bound
818 Form: B Context: EVAL; lexically bound
819 Form: (LIST A B) Context: EVAL
820 Form: A Context: EVAL; lexically bound
821 Form: B Context: EVAL; lexically bound
822 Form: (LABEL-1 1 2) Context: EVAL
823 Form: 1 Context: EVAL
824 Form: 2 Context: EVAL
825 Form: (FOO 1 2) Context: EVAL
826 Form: 'GLOBAL-FOO Context: EVAL
827 (LABELS ((LABEL-1 (A B)
834 (assert (string=-modulo-tabspace
835 (with-output-to-string (*standard-output*)
836 (take-it-out-for-a-test-walk (macrolet ((macrolet-1 (a b) (list a b)))
839 "Form: (MACROLET ((MACROLET-1 (A B)
842 (FOO 1 2)) Context: EVAL
843 Form: (LIST A B) Context: EVAL
844 Form: A Context: EVAL; lexically bound
845 Form: B Context: EVAL; lexically bound
846 Form: (MACROLET-1 A B) Context: EVAL
847 Form: (A B) Context: EVAL
848 Form: B Context: EVAL
849 Form: (FOO 1 2) Context: EVAL
850 Form: 'GLOBAL-FOO Context: EVAL
851 (MACROLET ((MACROLET-1 (A B)
856 (assert (string=-modulo-tabspace
857 (with-output-to-string (*standard-output*)
858 (take-it-out-for-a-test-walk (macrolet ((foo (a) `(inner-foo-expanded ,a)))
860 "Form: (MACROLET ((FOO (A)
861 `(INNER-FOO-EXPANDED ,A)))
862 (FOO 1)) Context: EVAL
863 Form: `(INNER-FOO-EXPANDED ,A) Context: EVAL
864 Form: 'INNER-FOO-EXPANDED Context: EVAL
865 Form: A Context: EVAL; lexically bound
866 Form: (FOO 1) Context: EVAL
867 Form: (INNER-FOO-EXPANDED 1) Context: EVAL
868 Form: 1 Context: EVAL
870 `(INNER-FOO-EXPANDED ,A)))
873 (assert (string=-modulo-tabspace
874 (with-output-to-string (*standard-output*)
875 (take-it-out-for-a-test-walk (progn (bar 1)
877 `(inner-bar-expanded ,a)))
882 `(INNER-BAR-EXPANDED ,A)))
883 (BAR 2))) Context: EVAL
884 Form: (BAR 1) Context: EVAL
885 Form: 'GLOBAL-BAR Context: EVAL
886 Form: (MACROLET ((BAR (A)
887 `(INNER-BAR-EXPANDED ,A)))
888 (BAR 2)) Context: EVAL
889 Form: `(INNER-BAR-EXPANDED ,A) Context: EVAL
890 Form: 'INNER-BAR-EXPANDED Context: EVAL
891 Form: A Context: EVAL; lexically bound
892 Form: (BAR 2) Context: EVAL
893 Form: (INNER-BAR-EXPANDED 2) Context: EVAL
894 Form: 2 Context: EVAL
898 `(INNER-BAR-EXPANDED ,A)))
901 (assert (string=-modulo-tabspace
902 (with-output-to-string (*standard-output*)
903 (take-it-out-for-a-test-walk (progn (bar 1)
906 `(inner-bar-expanded ,s)))
912 `(INNER-BAR-EXPANDED ,S)))
913 (BAR 2))) Context: EVAL
914 Form: (BAR 1) Context: EVAL
915 Form: 'GLOBAL-BAR Context: EVAL
916 Form: (MACROLET ((BAR (S)
918 `(INNER-BAR-EXPANDED ,S)))
919 (BAR 2)) Context: EVAL
920 Form: (BAR S) Context: EVAL
921 Form: 'GLOBAL-BAR Context: EVAL
922 Form: `(INNER-BAR-EXPANDED ,S) Context: EVAL
923 Form: 'INNER-BAR-EXPANDED Context: EVAL
924 Form: S Context: EVAL; lexically bound
925 Form: (BAR 2) Context: EVAL
926 Form: (INNER-BAR-EXPANDED 2) Context: EVAL
927 Form: 2 Context: EVAL
932 `(INNER-BAR-EXPANDED ,S)))
935 (assert (string=-modulo-tabspace
936 (with-output-to-string (*standard-output*)
937 (take-it-out-for-a-test-walk (cond (a b)
938 ((foo bar) a (foo a)))))
939 "Form: (COND (A B) ((FOO BAR) A (FOO A))) Context: EVAL
940 Form: (IF A (PROGN B) (COND ((FOO BAR) A (FOO A)))) Context: EVAL
941 Form: A Context: EVAL
942 Form: (PROGN B) Context: EVAL
943 Form: B Context: EVAL
944 Form: (COND ((FOO BAR) A (FOO A))) Context: EVAL
945 Form: (IF (FOO BAR) (PROGN A (FOO A)) NIL) Context: EVAL
946 Form: (FOO BAR) Context: EVAL
947 Form: 'GLOBAL-FOO Context: EVAL
948 Form: (PROGN A (FOO A)) Context: EVAL
949 Form: A Context: EVAL
950 Form: (FOO A) Context: EVAL
951 Form: 'GLOBAL-FOO Context: EVAL
952 Form: NIL Context: EVAL; bound: NIL
953 (COND (A B) ((FOO BAR) A (FOO A)))"))
955 (assert (string=-modulo-tabspace
956 (with-output-to-string (*standard-output*)
957 (let ((the-lexical-variables ()))
958 (walk-form '(let ((a 1) (b 2))
959 (lambda (x) (list a b x y)))
961 (lambda (form context env)
962 (declare (ignore context))
963 (when (and (symbolp form)
964 (var-lexical-p form env))
965 (push form the-lexical-variables))
967 (or (and (= (length the-lexical-variables) 3)
968 (member 'a the-lexical-variables)
969 (member 'b the-lexical-variables)
970 (member 'x the-lexical-variables))
971 (error "Walker didn't do lexical variables of a closure properly."))))
976 ;;; Old PCL hung up on this.