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 (string= (string-modulo-tabspace x)
40 (string-modulo-tabspace y)))
42 ;;;; tests based on stuff at the end of the original CMU CL
43 ;;;; pcl/walk.lisp file
45 (defmacro take-it-out-for-a-test-walk (form)
46 `(take-it-out-for-a-test-walk-1 ',form))
48 (defun take-it-out-for-a-test-walk-1 (form)
49 (let ((copy-of-form (copy-tree form))
50 (result (walk-form form nil
52 (format t "~&Form: ~S ~3T Context: ~A" x y)
54 (let ((lexical (var-lexical-p x env))
55 (special (var-special-p x env)))
58 (format t "lexically bound"))
61 (format t "declared special"))
64 (format t "bound: ~S " (eval x)))))
66 (cond ((not (equal result copy-of-form))
67 (format t "~%Warning: Result not EQUAL to copy of start."))
68 ((not (eq result form))
69 (format t "~%Warning: Result not EQ to copy of start.")))
73 (defmacro foo (&rest ignore)
74 (declare (ignore ignore))
77 (defmacro bar (&rest ignore)
78 (declare (ignore ignore))
81 (assert (string=-modulo-tabspace
82 (with-output-to-string (*standard-output*)
83 (take-it-out-for-a-test-walk (list arg1 arg2 arg3)))
84 "Form: (LIST ARG1 ARG2 ARG3) Context: EVAL
85 Form: ARG1 Context: EVAL
86 Form: ARG2 Context: EVAL
87 Form: ARG3 Context: EVAL
88 (LIST ARG1 ARG2 ARG3)"))
90 (assert (string=-modulo-tabspace
91 (with-output-to-string (*standard-output*)
92 (take-it-out-for-a-test-walk (list (cons 1 2) (list 3 4 5))))
93 "Form: (LIST (CONS 1 2) (LIST 3 4 5)) Context: EVAL
94 Form: (CONS 1 2) Context: EVAL
97 Form: (LIST 3 4 5) Context: EVAL
100 Form: 5 Context: EVAL
101 (LIST (CONS 1 2) (LIST 3 4 5))"))
103 (assert (string=-modulo-tabspace
104 (with-output-to-string (*standard-output*)
105 (take-it-out-for-a-test-walk (progn (foo) (bar 1))))
106 "Form: (PROGN (FOO) (BAR 1)) Context: EVAL
107 Form: (FOO) Context: EVAL
108 Form: 'GLOBAL-FOO Context: EVAL
109 Form: (BAR 1) Context: EVAL
110 Form: 'GLOBAL-BAR Context: EVAL
111 (PROGN (FOO) (BAR 1))"))
113 (assert (string=-modulo-tabspace
114 (with-output-to-string (*standard-output*)
115 (take-it-out-for-a-test-walk (block block-name a b c)))
116 "Form: (BLOCK BLOCK-NAME A B C) Context: EVAL
117 Form: A Context: EVAL
118 Form: B Context: EVAL
119 Form: C Context: EVAL
120 (BLOCK BLOCK-NAME A B C)"))
122 (assert (string=-modulo-tabspace
123 (with-output-to-string (*standard-output*)
124 (take-it-out-for-a-test-walk (block block-name (list a) b c)))
125 "Form: (BLOCK BLOCK-NAME (LIST A) B C) Context: EVAL
126 Form: (LIST A) Context: EVAL
127 Form: A Context: EVAL
128 Form: B Context: EVAL
129 Form: C Context: EVAL
130 (BLOCK BLOCK-NAME (LIST A) B C)"))
132 (assert (string=-modulo-tabspace
133 (with-output-to-string (*standard-output*)
134 (take-it-out-for-a-test-walk (catch catch-tag (list a) b c)))
135 "Form: (CATCH CATCH-TAG (LIST A) B C) Context: EVAL
136 Form: CATCH-TAG Context: EVAL
137 Form: (LIST A) Context: EVAL
138 Form: A Context: EVAL
139 Form: B Context: EVAL
140 Form: C Context: EVAL
141 (CATCH CATCH-TAG (LIST A) B C)"))
143 ;;; This is a fairly simple MACROLET case. While walking the body of the
144 ;;; macro, X should be lexically bound. In the body of the MACROLET form
145 ;;; itself, X should not be bound.
146 (assert (string=-modulo-tabspace
147 (with-output-to-string (*standard-output*)
148 (take-it-out-for-a-test-walk
149 (macrolet ((foo (x) (list x) ''inner))
152 "Form: (MACROLET ((FOO (X)
156 (FOO 1)) Context: EVAL
157 Form: (LIST X) Context: EVAL
158 Form: X Context: EVAL; lexically bound
159 Form: ''INNER Context: EVAL
160 Form: X Context: EVAL
161 Form: (FOO 1) Context: EVAL
162 Form: 'INNER Context: EVAL
170 ;;; The original PCL documentation for this test said
171 ;;; A slightly more complex MACROLET case. In the body of the macro
172 ;;; X should not be lexically bound. In the body of the macrolet
173 ;;; form itself X should be bound. Note that THIS CASE WILL CAUSE AN
174 ;;; ERROR when it tries to macroexpand the call to FOO.
176 ;;; This test is commented out in SBCL because ANSI says, in the
177 ;;; definition of the special operator MACROLET,
178 ;;; The macro-expansion functions defined by MACROLET are defined
179 ;;; in the lexical environment in which the MACROLET form appears.
180 ;;; Declarations and MACROLET and SYMBOL-MACROLET definitions affect
181 ;;; the local macro definitions in a MACROLET, but the consequences
182 ;;; are undefined if the local macro definitions reference any
183 ;;; local variable or function bindings that are visible in that
184 ;;; lexical environment.
185 ;;; Since the behavior is undefined, anything we do conforms.:-|
186 ;;; This is of course less than ideal; see bug 124.
188 (multiple-value-bind (res cond)
190 (take-it-out-for-a-test-walk
192 (macrolet ((foo () (list x) ''inner))
195 (assert (and (null res) cond)))
197 (assert (string=-modulo-tabspace
198 (with-output-to-string (*standard-output*)
199 (take-it-out-for-a-test-walk
200 (flet ((foo (x) (list x y))
201 (bar (x) (list x y)))
203 "Form: (FLET ((FOO (X)
207 (FOO 1)) Context: EVAL
208 Form: (LIST X Y) Context: EVAL
209 Form: X Context: EVAL; lexically bound
210 Form: Y Context: EVAL
211 Form: (LIST X Y) Context: EVAL
212 Form: X Context: EVAL; lexically bound
213 Form: Y Context: EVAL
214 Form: (FOO 1) Context: EVAL
215 Form: 1 Context: EVAL
222 (assert (string=-modulo-tabspace
223 (with-output-to-string (*standard-output*)
224 (take-it-out-for-a-test-walk
226 (flet ((foo (x) (list x y))
227 (bar (x) (list x y)))
234 (FOO 1))) Context: EVAL
235 Form: 2 Context: EVAL
236 Form: (FLET ((FOO (X)
240 (FOO 1)) Context: EVAL
241 Form: (LIST X Y) Context: EVAL
242 Form: X Context: EVAL; lexically bound
243 Form: Y Context: EVAL; lexically bound
244 Form: (LIST X Y) Context: EVAL
245 Form: X Context: EVAL; lexically bound
246 Form: Y Context: EVAL; lexically bound
247 Form: (FOO 1) Context: EVAL
248 Form: 1 Context: EVAL
256 (assert (string=-modulo-tabspace
257 (with-output-to-string (*standard-output*)
258 (take-it-out-for-a-test-walk
259 (labels ((foo (x) (bar x))
262 "Form: (LABELS ((FOO (X)
266 (FOO 1)) Context: EVAL
267 Form: (BAR X) Context: EVAL
268 Form: X Context: EVAL; lexically bound
269 Form: (FOO X) Context: EVAL
270 Form: X Context: EVAL; lexically bound
271 Form: (FOO 1) Context: EVAL
272 Form: 1 Context: EVAL
279 (assert (string=-modulo-tabspace
280 (with-output-to-string (*standard-output*)
281 (take-it-out-for-a-test-walk
282 (flet ((foo (x) (foo x)))
284 "Form: (FLET ((FOO (X)
286 (FOO 1)) Context: EVAL
287 Form: (FOO X) Context: EVAL
288 Form: 'GLOBAL-FOO Context: EVAL
289 Form: (FOO 1) Context: EVAL
290 Form: 1 Context: EVAL
295 (assert (string=-modulo-tabspace
296 (with-output-to-string (*standard-output*)
297 (take-it-out-for-a-test-walk
298 (flet ((foo (x) (foo x)))
299 (flet ((bar (x) (foo x)))
301 "Form: (FLET ((FOO (X)
305 (BAR 1))) Context: EVAL
306 Form: (FOO X) Context: EVAL
307 Form: 'GLOBAL-FOO Context: EVAL
308 Form: (FLET ((BAR (X)
310 (BAR 1)) Context: EVAL
311 Form: (FOO X) Context: EVAL
312 Form: X Context: EVAL; lexically bound
313 Form: (BAR 1) Context: EVAL
314 Form: 1 Context: EVAL
321 (assert (string=-modulo-tabspace
322 (with-output-to-string (*standard-output*)
323 (take-it-out-for-a-test-walk (prog () (declare (special a b)))))
324 "Form: (PROG () (DECLARE (SPECIAL A B))) Context: EVAL
327 (DECLARE (SPECIAL A B))
328 (TAGBODY))) Context: EVAL
330 (DECLARE (SPECIAL A B))
331 (TAGBODY)) Context: EVAL
332 Form: (TAGBODY) Context: EVAL
333 (PROG () (DECLARE (SPECIAL A B)))"))
335 (assert (string=-modulo-tabspace
336 (with-output-to-string (*standard-output*)
337 (take-it-out-for-a-test-walk (let (a b c)
338 (declare (special a b))
341 (DECLARE (SPECIAL A B))
345 Form: (FOO A) Context: EVAL
346 Form: 'GLOBAL-FOO Context: EVAL
347 Form: B Context: EVAL; lexically bound
348 Form: C Context: EVAL; lexically bound
350 (DECLARE (SPECIAL A B))
355 (assert (string=-modulo-tabspace
356 (with-output-to-string (*standard-output*)
357 (take-it-out-for-a-test-walk (let (a b c)
358 (declare (special a) (special b))
361 (DECLARE (SPECIAL A) (SPECIAL B))
365 Form: (FOO A) Context: EVAL
366 Form: 'GLOBAL-FOO Context: EVAL
367 Form: B Context: EVAL; lexically bound; declared special
368 Form: C Context: EVAL; lexically bound
370 (DECLARE (SPECIAL A) (SPECIAL B))
375 (assert (string=-modulo-tabspace
376 (with-output-to-string (*standard-output*)
377 (take-it-out-for-a-test-walk (let (a b c)
378 (declare (special a))
379 (declare (special b))
382 (DECLARE (SPECIAL A))
383 (DECLARE (SPECIAL B))
387 Form: (FOO A) Context: EVAL
388 Form: 'GLOBAL-FOO Context: EVAL
389 Form: B Context: EVAL; lexically bound; declared special
390 Form: C Context: EVAL; lexically bound
392 (DECLARE (SPECIAL A))
393 (DECLARE (SPECIAL B))
398 (assert (string=-modulo-tabspace
399 (with-output-to-string (*standard-output*)
400 (take-it-out-for-a-test-walk (let (a b c)
401 (declare (special a))
402 (declare (special b))
406 (DECLARE (SPECIAL A))
407 (DECLARE (SPECIAL B))
416 Form: 1 Context: EVAL
417 Form: (FOO A) Context: EVAL
418 Form: 'GLOBAL-FOO Context: EVAL
419 Form: B Context: EVAL; lexically bound; declared special
420 Form: C Context: EVAL; lexically bound
422 (DECLARE (SPECIAL A))
423 (DECLARE (SPECIAL B))
429 (assert (string=-modulo-tabspace
430 (with-output-to-string (*standard-output*)
431 (take-it-out-for-a-test-walk (eval-when ()
434 "Form: (EVAL-WHEN NIL A (FOO A)) Context: EVAL
435 Form: A Context: EVAL
436 Form: (FOO A) Context: EVAL
437 Form: 'GLOBAL-FOO Context: EVAL
438 (EVAL-WHEN NIL A (FOO A))"))
440 (assert (string=-modulo-tabspace
441 (with-output-to-string (*standard-output*)
442 (take-it-out-for-a-test-walk
443 (eval-when (:execute :compile-toplevel :load-toplevel)
446 "Form: (EVAL-WHEN (:EXECUTE :COMPILE-TOPLEVEL :LOAD-TOPLEVEL) A (FOO A)) Context: EVAL
447 Form: A Context: EVAL
448 Form: (FOO A) Context: EVAL
449 Form: 'GLOBAL-FOO Context: EVAL
450 (EVAL-WHEN (:EXECUTE :COMPILE-TOPLEVEL :LOAD-TOPLEVEL) A (FOO A))"))
452 (assert (string=-modulo-tabspace
453 (with-output-to-string (*standard-output*)
454 (take-it-out-for-a-test-walk (multiple-value-bind (a b)
455 (foo a b) (list a b))))
456 "Form: (MULTIPLE-VALUE-BIND (A B) (FOO A B) (LIST A B)) Context: EVAL
457 Form: (FOO A B) Context: EVAL
458 Form: 'GLOBAL-FOO Context: EVAL
459 Form: (LIST A B) Context: EVAL
460 Form: A Context: EVAL; lexically bound
461 Form: B Context: EVAL; lexically bound
462 (MULTIPLE-VALUE-BIND (A B) (FOO A B) (LIST A B))"))
464 (assert (string=-modulo-tabspace
465 (with-output-to-string (*standard-output*)
466 (take-it-out-for-a-test-walk (multiple-value-bind (a b)
468 (declare (special a))
470 "Form: (MULTIPLE-VALUE-BIND (A B) (FOO A B) (DECLARE (SPECIAL A)) (LIST A B)) Context: EVAL
471 Form: (FOO A B) Context: EVAL
472 Form: 'GLOBAL-FOO Context: EVAL
473 Form: (LIST A B) Context: EVAL
474 Form: A Context: EVAL; lexically bound
475 Form: B Context: EVAL; lexically bound
476 (MULTIPLE-VALUE-BIND (A B) (FOO A B) (DECLARE (SPECIAL A)) (LIST A B))"))
478 (assert (string=-modulo-tabspace
479 (with-output-to-string (*standard-output*)
480 (take-it-out-for-a-test-walk (progn (function foo))))
481 "Form: (PROGN #'FOO) Context: EVAL
482 Form: #'FOO Context: EVAL
485 (assert (string=-modulo-tabspace
486 (with-output-to-string (*standard-output*)
487 (take-it-out-for-a-test-walk (progn a b (go a))))
488 "Form: (PROGN A B (GO A)) Context: EVAL
489 Form: A Context: EVAL
490 Form: B Context: EVAL
491 Form: (GO A) Context: EVAL
492 (PROGN A B (GO A))"))
494 (assert (string=-modulo-tabspace
495 (with-output-to-string (*standard-output*)
496 (take-it-out-for-a-test-walk (if a b c)))
497 "Form: (IF A B C) Context: EVAL
498 Form: A Context: EVAL
499 Form: B Context: EVAL
500 Form: C Context: EVAL
503 (assert (string=-modulo-tabspace
504 (with-output-to-string (*standard-output*)
505 (take-it-out-for-a-test-walk (if a b)))
506 "Form: (IF A B) Context: EVAL
507 Form: A Context: EVAL
508 Form: B Context: EVAL
509 Form: NIL Context: EVAL; bound: NIL
512 (assert (string=-modulo-tabspace
513 (with-output-to-string (*standard-output*)
514 (take-it-out-for-a-test-walk ((lambda (a b) (list a b)) 1 2)))
515 "Form: ((LAMBDA (A B) (LIST A B)) 1 2) Context: EVAL
516 Form: (LAMBDA (A B) (LIST A B)) Context: EVAL
517 Form: (LIST A B) Context: EVAL
518 Form: A Context: EVAL; lexically bound
519 Form: B Context: EVAL; lexically bound
520 Form: 1 Context: EVAL
521 Form: 2 Context: EVAL
522 ((LAMBDA (A B) (LIST A B)) 1 2)"))
524 (assert (string=-modulo-tabspace
525 (with-output-to-string (*standard-output*)
526 (take-it-out-for-a-test-walk ((lambda (a b)
527 (declare (special a))
530 "Form: ((LAMBDA (A B) (DECLARE (SPECIAL A)) (LIST A B)) 1 2) Context: EVAL
531 Form: (LAMBDA (A B) (DECLARE (SPECIAL A)) (LIST A B)) Context: EVAL
532 Form: (LIST A B) Context: EVAL
533 Form: A Context: EVAL; lexically bound; declared special
534 Form: B Context: EVAL; lexically bound
535 Form: 1 Context: EVAL
536 Form: 2 Context: EVAL
537 ((LAMBDA (A B) (DECLARE (SPECIAL A)) (LIST A B)) 1 2)"))
539 (assert (string=-modulo-tabspace
540 (with-output-to-string (*standard-output*)
541 (take-it-out-for-a-test-walk (let ((a a) (b a) (c b))
543 "Form: (LET ((A A) (B A) (C B))
544 (LIST A B C)) Context: EVAL
545 Form: A Context: EVAL
546 Form: A Context: EVAL
547 Form: B Context: EVAL
548 Form: (LIST A B C) Context: EVAL
549 Form: A Context: EVAL; lexically bound
550 Form: B Context: EVAL; lexically bound
551 Form: C Context: EVAL; lexically bound
552 (LET ((A A) (B A) (C B))
555 (assert (string=-modulo-tabspace
556 (with-output-to-string (*standard-output*)
557 (take-it-out-for-a-test-walk (let* ((a a) (b a) (c b)) (list a b c))))
558 "Form: (LET* ((A A) (B A) (C B))
559 (LIST A B C)) Context: EVAL
560 Form: A Context: EVAL
561 Form: A Context: EVAL; lexically bound
562 Form: B Context: EVAL; lexically bound
563 Form: (LIST A B C) Context: EVAL
564 Form: A Context: EVAL; lexically bound
565 Form: B Context: EVAL; lexically bound
566 Form: C Context: EVAL; lexically bound
567 (LET* ((A A) (B A) (C B))
570 (assert (string=-modulo-tabspace
571 (with-output-to-string (*standard-output*)
572 (take-it-out-for-a-test-walk (let ((a a) (b a) (c b))
573 (declare (special a b))
575 "Form: (LET ((A A) (B A) (C B))
576 (DECLARE (SPECIAL A B))
577 (LIST A B C)) Context: EVAL
578 Form: A Context: EVAL
579 Form: A Context: EVAL
580 Form: B Context: EVAL
581 Form: (LIST A B C) Context: EVAL
582 Form: A Context: EVAL; lexically bound; declared special
583 Form: B Context: EVAL; lexically bound
584 Form: C Context: EVAL; lexically bound
585 (LET ((A A) (B A) (C B))
586 (DECLARE (SPECIAL A B))
589 (assert (string=-modulo-tabspace
590 (with-output-to-string (*standard-output*)
591 (take-it-out-for-a-test-walk (let* ((a a) (b a) (c b))
592 (declare (special a b))
594 "Form: (LET* ((A A) (B A) (C B))
595 (DECLARE (SPECIAL A B))
596 (LIST A B C)) Context: EVAL
597 Form: A Context: EVAL
598 Form: A Context: EVAL; lexically bound
599 Form: B Context: EVAL; lexically bound
600 Form: (LIST A B C) Context: EVAL
601 Form: A Context: EVAL; lexically bound; declared special
602 Form: B Context: EVAL; lexically bound
603 Form: C Context: EVAL; lexically bound
604 (LET* ((A A) (B A) (C B))
605 (DECLARE (SPECIAL A B))
608 (assert (string=-modulo-tabspace
609 (with-output-to-string (*standard-output*)
610 (take-it-out-for-a-test-walk (let ((a 1) (b 2))
613 (declare (special a))
615 "Form: (LET ((A 1) (B 2))
618 (DECLARE (SPECIAL A))
619 (FOO A B))) Context: EVAL
620 Form: 1 Context: EVAL
621 Form: 2 Context: EVAL
622 Form: (FOO BAR) Context: EVAL
623 Form: 'GLOBAL-FOO Context: EVAL
625 (DECLARE (SPECIAL A))
626 (FOO A B)) Context: EVAL
627 Form: (FOO A B) Context: EVAL
628 Form: 'GLOBAL-FOO Context: EVAL
632 (DECLARE (SPECIAL A))
635 (assert (string=-modulo-tabspace
636 (with-output-to-string (*standard-output*)
637 (take-it-out-for-a-test-walk (multiple-value-call #'foo a b c)))
638 "Form: (MULTIPLE-VALUE-CALL #'FOO A B C) Context: EVAL
639 Form: #'FOO Context: EVAL
640 Form: A Context: EVAL
641 Form: B Context: EVAL
642 Form: C Context: EVAL
643 (MULTIPLE-VALUE-CALL #'FOO A B C)"))
645 (assert (string=-modulo-tabspace
646 (with-output-to-string (*standard-output*)
647 (take-it-out-for-a-test-walk (multiple-value-prog1 a b c)))
648 "Form: (MULTIPLE-VALUE-PROG1 A B C) Context: EVAL
649 Form: A Context: EVAL
650 Form: B Context: EVAL
651 Form: C Context: EVAL
652 (MULTIPLE-VALUE-PROG1 A B C)"))
654 (assert (string=-modulo-tabspace
655 (with-output-to-string (*standard-output*)
656 (take-it-out-for-a-test-walk (progn a b c)))
657 "Form: (PROGN A B C) Context: EVAL
658 Form: A Context: EVAL
659 Form: B Context: EVAL
660 Form: C Context: EVAL
663 (assert (string=-modulo-tabspace
664 (with-output-to-string (*standard-output*)
665 (take-it-out-for-a-test-walk (progv vars vals a b c)))
666 "Form: (PROGV VARS VALS A B C) Context: EVAL
667 Form: VARS Context: EVAL
668 Form: VALS Context: EVAL
669 Form: A Context: EVAL
670 Form: B Context: EVAL
671 Form: C Context: EVAL
672 (PROGV VARS VALS A B C)"))
674 (assert (string=-modulo-tabspace
675 (with-output-to-string (*standard-output*)
676 (take-it-out-for-a-test-walk (quote a)))
677 "Form: 'A Context: EVAL
680 (assert (string=-modulo-tabspace
681 (with-output-to-string (*standard-output*)
682 (take-it-out-for-a-test-walk (return-from block-name a b c)))
683 "Form: (RETURN-FROM BLOCK-NAME A B C) Context: EVAL
684 Form: A Context: EVAL
685 Form: B Context: EVAL
686 Form: C Context: EVAL
687 (RETURN-FROM BLOCK-NAME A B C)"))
689 (assert (string=-modulo-tabspace
690 (with-output-to-string (*standard-output*)
691 (take-it-out-for-a-test-walk (setq a 1)))
692 "Form: (SETQ A 1) Context: EVAL
694 Form: 1 Context: EVAL
698 (assert (string=-modulo-tabspace
699 (with-output-to-string (*standard-output*)
700 (take-it-out-for-a-test-walk (setq a (foo 1) b (bar 2) c 3)))
701 "Form: (SETQ A (FOO 1) B (BAR 2) C 3) Context: EVAL
702 Form: (SETQ A (FOO 1)) Context: EVAL
704 Form: (FOO 1) Context: EVAL
705 Form: 'GLOBAL-FOO Context: EVAL
706 Form: (SETQ B (BAR 2)) Context: EVAL
708 Form: (BAR 2) Context: EVAL
709 Form: 'GLOBAL-BAR Context: EVAL
710 Form: (SETQ C 3) Context: EVAL
712 Form: 3 Context: EVAL
713 (SETQ A (FOO 1) B (BAR 2) C 3)"))
718 (assert (string=-modulo-tabspace
719 (with-output-to-string (*standard-output*)
720 (take-it-out-for-a-test-walk (tagbody a b c (go a))))
721 "Form: (TAGBODY A B C (GO A)) Context: EVAL
722 Form: A Context: QUOTE
723 Form: B Context: QUOTE
724 Form: C Context: QUOTE
725 Form: (GO A) Context: EVAL
726 (TAGBODY A B C (GO A))"))
728 (assert (string=-modulo-tabspace
729 (with-output-to-string (*standard-output*)
730 (take-it-out-for-a-test-walk (the foo (foo-form a b c))))
731 "Form: (THE FOO (FOO-FORM A B C)) Context: EVAL
732 Form: (FOO-FORM A B C) Context: EVAL
733 Form: A Context: EVAL
734 Form: B Context: EVAL
735 Form: C Context: EVAL
736 (THE FOO (FOO-FORM A B C))"))
738 (assert (string=-modulo-tabspace
739 (with-output-to-string (*standard-output*)
740 (take-it-out-for-a-test-walk (throw tag-form a)))
741 "Form: (THROW TAG-FORM A) Context: EVAL
742 Form: TAG-FORM Context: EVAL
743 Form: A Context: EVAL
744 (THROW TAG-FORM A)"))
746 (assert (string=-modulo-tabspace
747 (with-output-to-string (*standard-output*)
748 (take-it-out-for-a-test-walk (unwind-protect (foo a b) d e f)))
749 "Form: (UNWIND-PROTECT (FOO A B) D E F) Context: EVAL
750 Form: (FOO A B) Context: EVAL
751 Form: 'GLOBAL-FOO Context: EVAL
752 Form: D Context: EVAL
753 Form: E Context: EVAL
754 Form: F Context: EVAL
755 (UNWIND-PROTECT (FOO A B) D E F)"))
757 (defmacro flet-1 (a b)
758 (declare (ignore a b))
761 (defmacro labels-1 (a b)
762 (declare (ignore a b))
765 (assert (string=-modulo-tabspace
766 (with-output-to-string (*standard-output*)
767 (take-it-out-for-a-test-walk
768 (flet ((flet-1 (a b) () (flet-1 a b) (list a b)))
771 "Form: (FLET ((FLET-1 (A B)
776 (FOO 1 2)) Context: EVAL
777 Form: NIL Context: EVAL; bound: NIL
778 Form: (FLET-1 A B) Context: EVAL
779 Form: 'OUTER Context: EVAL
780 Form: (LIST A B) Context: EVAL
781 Form: A Context: EVAL; lexically bound
782 Form: B Context: EVAL; lexically bound
783 Form: (FLET-1 1 2) Context: EVAL
784 Form: 1 Context: EVAL
785 Form: 2 Context: EVAL
786 Form: (FOO 1 2) Context: EVAL
787 Form: 'GLOBAL-FOO Context: EVAL
795 (assert (string=-modulo-tabspace
796 (with-output-to-string (*standard-output*)
797 (take-it-out-for-a-test-walk
798 (labels ((label-1 (a b) () (label-1 a b)(list a b)))
801 "Form: (LABELS ((LABEL-1 (A B)
806 (FOO 1 2)) Context: EVAL
807 Form: NIL Context: EVAL; bound: NIL
808 Form: (LABEL-1 A B) Context: EVAL
809 Form: A Context: EVAL; lexically bound
810 Form: B Context: EVAL; lexically bound
811 Form: (LIST A B) Context: EVAL
812 Form: A Context: EVAL; lexically bound
813 Form: B Context: EVAL; lexically bound
814 Form: (LABEL-1 1 2) Context: EVAL
815 Form: 1 Context: EVAL
816 Form: 2 Context: EVAL
817 Form: (FOO 1 2) Context: EVAL
818 Form: 'GLOBAL-FOO Context: EVAL
819 (LABELS ((LABEL-1 (A B)
826 (assert (string=-modulo-tabspace
827 (with-output-to-string (*standard-output*)
828 (take-it-out-for-a-test-walk (macrolet ((macrolet-1 (a b) (list a b)))
831 "Form: (MACROLET ((MACROLET-1 (A B)
834 (FOO 1 2)) Context: EVAL
835 Form: (LIST A B) Context: EVAL
836 Form: A Context: EVAL; lexically bound
837 Form: B Context: EVAL; lexically bound
838 Form: (MACROLET-1 A B) Context: EVAL
839 Form: (A B) Context: EVAL
840 Form: B Context: EVAL
841 Form: (FOO 1 2) Context: EVAL
842 Form: 'GLOBAL-FOO Context: EVAL
843 (MACROLET ((MACROLET-1 (A B)
848 (assert (string=-modulo-tabspace
849 (with-output-to-string (*standard-output*)
850 (take-it-out-for-a-test-walk (macrolet ((foo (a) `(inner-foo-expanded ,a)))
852 "Form: (MACROLET ((FOO (A)
853 `(INNER-FOO-EXPANDED ,A)))
854 (FOO 1)) Context: EVAL
855 Form: `(INNER-FOO-EXPANDED ,A) Context: EVAL
856 Form: 'INNER-FOO-EXPANDED Context: EVAL
857 Form: A Context: EVAL; lexically bound
858 Form: (FOO 1) Context: EVAL
859 Form: (INNER-FOO-EXPANDED 1) Context: EVAL
860 Form: 1 Context: EVAL
862 `(INNER-FOO-EXPANDED ,A)))
865 (assert (string=-modulo-tabspace
866 (with-output-to-string (*standard-output*)
867 (take-it-out-for-a-test-walk (progn (bar 1)
869 `(inner-bar-expanded ,a)))
874 `(INNER-BAR-EXPANDED ,A)))
875 (BAR 2))) Context: EVAL
876 Form: (BAR 1) Context: EVAL
877 Form: 'GLOBAL-BAR Context: EVAL
878 Form: (MACROLET ((BAR (A)
879 `(INNER-BAR-EXPANDED ,A)))
880 (BAR 2)) Context: EVAL
881 Form: `(INNER-BAR-EXPANDED ,A) Context: EVAL
882 Form: 'INNER-BAR-EXPANDED Context: EVAL
883 Form: A Context: EVAL; lexically bound
884 Form: (BAR 2) Context: EVAL
885 Form: (INNER-BAR-EXPANDED 2) Context: EVAL
886 Form: 2 Context: EVAL
890 `(INNER-BAR-EXPANDED ,A)))
893 (assert (string=-modulo-tabspace
894 (with-output-to-string (*standard-output*)
895 (take-it-out-for-a-test-walk (progn (bar 1)
898 `(inner-bar-expanded ,s)))
904 `(INNER-BAR-EXPANDED ,S)))
905 (BAR 2))) Context: EVAL
906 Form: (BAR 1) Context: EVAL
907 Form: 'GLOBAL-BAR Context: EVAL
908 Form: (MACROLET ((BAR (S)
910 `(INNER-BAR-EXPANDED ,S)))
911 (BAR 2)) Context: EVAL
912 Form: (BAR S) Context: EVAL
913 Form: 'GLOBAL-BAR Context: EVAL
914 Form: `(INNER-BAR-EXPANDED ,S) Context: EVAL
915 Form: 'INNER-BAR-EXPANDED Context: EVAL
916 Form: S Context: EVAL; lexically bound
917 Form: (BAR 2) Context: EVAL
918 Form: (INNER-BAR-EXPANDED 2) Context: EVAL
919 Form: 2 Context: EVAL
924 `(INNER-BAR-EXPANDED ,S)))
927 (assert (string=-modulo-tabspace
928 (with-output-to-string (*standard-output*)
929 (take-it-out-for-a-test-walk (cond (a b)
930 ((foo bar) a (foo a)))))
931 "Form: (COND (A B) ((FOO BAR) A (FOO A))) Context: EVAL
932 Form: (IF A (PROGN B) (COND ((FOO BAR) A (FOO A)))) Context: EVAL
933 Form: A Context: EVAL
934 Form: (PROGN B) Context: EVAL
935 Form: B Context: EVAL
936 Form: (COND ((FOO BAR) A (FOO A))) Context: EVAL
937 Form: (IF (FOO BAR) (PROGN A (FOO A)) NIL) Context: EVAL
938 Form: (FOO BAR) Context: EVAL
939 Form: 'GLOBAL-FOO Context: EVAL
940 Form: (PROGN A (FOO A)) Context: EVAL
941 Form: A Context: EVAL
942 Form: (FOO A) Context: EVAL
943 Form: 'GLOBAL-FOO Context: EVAL
944 Form: NIL Context: EVAL; bound: NIL
945 (COND (A B) ((FOO BAR) A (FOO A)))"))
947 (assert (string=-modulo-tabspace
948 (with-output-to-string (*standard-output*)
949 (let ((the-lexical-variables ()))
950 (walk-form '(let ((a 1) (b 2))
951 (lambda (x) (list a b x y)))
953 (lambda (form context env)
954 (declare (ignore context))
955 (when (and (symbolp form)
956 (var-lexical-p form env))
957 (push form the-lexical-variables))
959 (or (and (= (length the-lexical-variables) 3)
960 (member 'a the-lexical-variables)
961 (member 'b the-lexical-variables)
962 (member 'x the-lexical-variables))
963 (error "Walker didn't do lexical variables of a closure properly."))))
968 ;;; Old PCL hung up on this.