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 (test-util:with-test
(:name
(:walk list
))
82 (assert (string=-modulo-tabspace
83 (with-output-to-string (*standard-output
*)
84 (take-it-out-for-a-test-walk (list arg1 arg2 arg3
)))
85 "Form: (LIST ARG1 ARG2 ARG3) Context: EVAL
86 Form: ARG1 Context: EVAL
87 Form: ARG2 Context: EVAL
88 Form: ARG3 Context: EVAL
89 \(LIST ARG1 ARG2 ARG3)")))
91 (test-util:with-test
(:name
(:walk list cons
))
92 (assert (string=-modulo-tabspace
93 (with-output-to-string (*standard-output
*)
94 (take-it-out-for-a-test-walk (list (cons 1 2) (list 3 4 5))))
95 "Form: (LIST (CONS 1 2) (LIST 3 4 5)) Context: EVAL
96 Form: (CONS 1 2) Context: EVAL
99 Form: (LIST 3 4 5) Context: EVAL
100 Form: 3 Context: EVAL
101 Form: 4 Context: EVAL
102 Form: 5 Context: EVAL
103 \(LIST (CONS 1 2) (LIST 3 4 5))")))
105 (test-util:with-test
(:name
(:walk progn
1))
106 (assert (string=-modulo-tabspace
107 (with-output-to-string (*standard-output
*)
108 (take-it-out-for-a-test-walk (progn (foo) (bar 1))))
109 "Form: (PROGN (FOO) (BAR 1)) Context: EVAL
110 Form: (FOO) Context: EVAL
111 Form: 'GLOBAL-FOO Context: EVAL
112 Form: (BAR 1) Context: EVAL
113 Form: 'GLOBAL-BAR Context: EVAL
114 \(PROGN (FOO) (BAR 1))")))
116 (test-util:with-test
(:name
(:walk block
))
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 (test-util:with-test
(:name
(:walk block list
))
127 (assert (string=-modulo-tabspace
128 (with-output-to-string (*standard-output
*)
129 (take-it-out-for-a-test-walk (block block-name
(list a
) b c
)))
130 "Form: (BLOCK BLOCK-NAME (LIST A) B C) Context: EVAL
131 Form: (LIST A) Context: EVAL
132 Form: A Context: EVAL
133 Form: B Context: EVAL
134 Form: C Context: EVAL
135 \(BLOCK BLOCK-NAME (LIST A) B C)")))
137 (test-util:with-test
(:name
(:walk catch list
))
138 (assert (string=-modulo-tabspace
139 (with-output-to-string (*standard-output
*)
140 (take-it-out-for-a-test-walk (catch catch-tag
(list a
) b c
)))
141 "Form: (CATCH CATCH-TAG (LIST A) B C) Context: EVAL
142 Form: CATCH-TAG Context: EVAL
143 Form: (LIST A) Context: EVAL
144 Form: A Context: EVAL
145 Form: B Context: EVAL
146 Form: C Context: EVAL
147 \(CATCH CATCH-TAG (LIST A) B C)")))
149 ;;; This is a fairly simple MACROLET case. While walking the body of the
150 ;;; macro, X should be lexically bound. In the body of the MACROLET form
151 ;;; itself, X should not be bound.
152 (test-util:with-test
(:name
(:walk macrolet
))
153 (assert (string=-modulo-tabspace
154 (with-output-to-string (*standard-output
*)
155 (take-it-out-for-a-test-walk
156 (macrolet ((foo (x) (list x
) ''inner
))
159 "Form: (MACROLET ((FOO (X)
163 (FOO 1)) Context: EVAL
164 Form: (LIST X) Context: EVAL
165 Form: X Context: EVAL; lexically bound
166 Form: ''INNER Context: EVAL
167 Form: X Context: EVAL
168 Form: (FOO 1) Context: EVAL
169 Form: 'INNER Context: EVAL
176 ;;; The original PCL documentation for this test said
177 ;;; A slightly more complex MACROLET case. In the body of the macro
178 ;;; X should not be lexically bound. In the body of the macrolet
179 ;;; form itself X should be bound. Note that THIS CASE WILL CAUSE AN
180 ;;; ERROR when it tries to macroexpand the call to FOO.
182 ;;; This test is commented out in SBCL because ANSI says, in the
183 ;;; definition of the special operator MACROLET,
184 ;;; The macro-expansion functions defined by MACROLET are defined
185 ;;; in the lexical environment in which the MACROLET form appears.
186 ;;; Declarations and MACROLET and SYMBOL-MACROLET definitions affect
187 ;;; the local macro definitions in a MACROLET, but the consequences
188 ;;; are undefined if the local macro definitions reference any
189 ;;; local variable or function bindings that are visible in that
190 ;;; lexical environment.
191 ;;; Since the behavior is undefined, anything we do conforms.:-|
192 ;;; This is of course less than ideal; see bug 124.
194 (multiple-value-bind (res cond
)
196 (take-it-out-for-a-test-walk
198 (macrolet ((foo () (list x
) ''inner
))
201 (assert (and (null res
) cond
)))
203 (test-util:with-test
(:name
(:walk flet
1))
204 (assert (string=-modulo-tabspace
205 (with-output-to-string (*standard-output
*)
206 (take-it-out-for-a-test-walk
207 (flet ((foo (x) (list x y
))
208 (bar (x) (list x y
)))
210 "Form: (FLET ((FOO (X)
214 (FOO 1)) Context: EVAL
215 Form: (LIST X Y) Context: EVAL
216 Form: X Context: EVAL; lexically bound
217 Form: Y Context: EVAL
218 Form: (LIST X Y) Context: EVAL
219 Form: X Context: EVAL; lexically bound
220 Form: Y Context: EVAL
221 Form: (FOO 1) Context: EVAL
222 Form: 1 Context: EVAL
229 (test-util:with-test
(:name
(:walk let flet
))
230 (assert (string=-modulo-tabspace
231 (with-output-to-string (*standard-output
*)
232 (take-it-out-for-a-test-walk
234 (flet ((foo (x) (list x y
))
235 (bar (x) (list x y
)))
242 (FOO 1))) Context: EVAL
243 Form: 2 Context: EVAL
244 Form: (FLET ((FOO (X)
248 (FOO 1)) Context: EVAL
249 Form: (LIST X Y) Context: EVAL
250 Form: X Context: EVAL; lexically bound
251 Form: Y Context: EVAL; lexically bound
252 Form: (LIST X Y) Context: EVAL
253 Form: X Context: EVAL; lexically bound
254 Form: Y Context: EVAL; lexically bound
255 Form: (FOO 1) Context: EVAL
256 Form: 1 Context: EVAL
264 (test-util:with-test
(:name
(:walk labels
))
265 (assert (string=-modulo-tabspace
266 (with-output-to-string (*standard-output
*)
267 (take-it-out-for-a-test-walk
268 (labels ((foo (x) (bar x
))
271 "Form: (LABELS ((FOO (X)
275 (FOO 1)) Context: EVAL
276 Form: (BAR X) Context: EVAL
277 Form: X Context: EVAL; lexically bound
278 Form: (FOO X) Context: EVAL
279 Form: X Context: EVAL; lexically bound
280 Form: (FOO 1) Context: EVAL
281 Form: 1 Context: EVAL
288 (test-util:with-test
(:name
(:walk flet
2))
289 (assert (string=-modulo-tabspace
290 (with-output-to-string (*standard-output
*)
291 (take-it-out-for-a-test-walk
292 (flet ((foo (x) (foo x
)))
294 "Form: (FLET ((FOO (X)
296 (FOO 1)) Context: EVAL
297 Form: (FOO X) Context: EVAL
298 Form: 'GLOBAL-FOO Context: EVAL
299 Form: (FOO 1) Context: EVAL
300 Form: 1 Context: EVAL
305 (test-util:with-test
(:name
(:walk flet
3))
306 (assert (string=-modulo-tabspace
307 (with-output-to-string (*standard-output
*)
308 (take-it-out-for-a-test-walk
309 (flet ((foo (x) (foo x
)))
310 (flet ((bar (x) (foo x
)))
312 "Form: (FLET ((FOO (X)
316 (BAR 1))) Context: EVAL
317 Form: (FOO X) Context: EVAL
318 Form: 'GLOBAL-FOO Context: EVAL
319 Form: (FLET ((BAR (X)
321 (BAR 1)) Context: EVAL
322 Form: (FOO X) Context: EVAL
323 Form: X Context: EVAL; lexically bound
324 Form: (BAR 1) Context: EVAL
325 Form: 1 Context: EVAL
332 (test-util:with-test
(:name
(:walk progn special
))
333 (assert (string=-modulo-tabspace
334 (with-output-to-string (*standard-output
*)
335 (take-it-out-for-a-test-walk (prog () (declare (special a b
)))))
336 "Form: (PROG () (DECLARE (SPECIAL A B))) Context: EVAL
339 (DECLARE (SPECIAL A B))
340 (TAGBODY))) Context: EVAL
342 (DECLARE (SPECIAL A B))
343 (TAGBODY)) Context: EVAL
344 Form: (TAGBODY) Context: EVAL
345 \(PROG () (DECLARE (SPECIAL A B)))")))
347 (test-util:with-test
(:name
(:walk let special
1))
348 (assert (string=-modulo-tabspace
349 (with-output-to-string (*standard-output
*)
350 (take-it-out-for-a-test-walk (let (a b c
)
351 (declare (special a b
))
354 (DECLARE (SPECIAL A B))
358 Form: (FOO A) Context: EVAL
359 Form: 'GLOBAL-FOO Context: EVAL
360 Form: B Context: EVAL; lexically bound; declared special
361 Form: C Context: EVAL; lexically bound
363 (DECLARE (SPECIAL A B))
368 (test-util:with-test
(:name
(:walk let special
2))
369 (assert (string=-modulo-tabspace
370 (with-output-to-string (*standard-output
*)
371 (take-it-out-for-a-test-walk (let (a b c
)
372 (declare (special a
) (special b
))
375 (DECLARE (SPECIAL A) (SPECIAL B))
379 Form: (FOO A) Context: EVAL
380 Form: 'GLOBAL-FOO Context: EVAL
381 Form: B Context: EVAL; lexically bound; declared special
382 Form: C Context: EVAL; lexically bound
384 (DECLARE (SPECIAL A) (SPECIAL B))
389 (test-util:with-test
(:name
(:walk let special
3))
390 (assert (string=-modulo-tabspace
391 (with-output-to-string (*standard-output
*)
392 (take-it-out-for-a-test-walk (let (a b c
)
393 (declare (special a
))
394 (declare (special b
))
397 (DECLARE (SPECIAL A))
398 (DECLARE (SPECIAL B))
402 Form: (FOO A) Context: EVAL
403 Form: 'GLOBAL-FOO Context: EVAL
404 Form: B Context: EVAL; lexically bound; declared special
405 Form: C Context: EVAL; lexically bound
407 (DECLARE (SPECIAL A))
408 (DECLARE (SPECIAL B))
413 (test-util:with-test
(:name
(:walk let special
4))
414 (assert (string=-modulo-tabspace
415 (with-output-to-string (*standard-output
*)
416 (take-it-out-for-a-test-walk (let (a b c
)
417 (declare (special a
))
418 (declare (special b
))
422 (DECLARE (SPECIAL A))
423 (DECLARE (SPECIAL B))
432 Form: 1 Context: EVAL
433 Form: (FOO A) Context: EVAL
434 Form: 'GLOBAL-FOO Context: EVAL
435 Form: B Context: EVAL; lexically bound; declared special
436 Form: C Context: EVAL; lexically bound
438 (DECLARE (SPECIAL A))
439 (DECLARE (SPECIAL B))
445 (test-util:with-test
(:name
(:walk eval-when
1))
446 (assert (string=-modulo-tabspace
447 (with-output-to-string (*standard-output
*)
448 (take-it-out-for-a-test-walk (eval-when ()
451 "Form: (EVAL-WHEN NIL A (FOO A)) Context: EVAL
452 Form: A Context: EVAL
453 Form: (FOO A) Context: EVAL
454 Form: 'GLOBAL-FOO Context: EVAL
455 \(EVAL-WHEN NIL A (FOO A))")))
457 (test-util:with-test
(:name
(:walk eval-when
2))
458 (assert (string=-modulo-tabspace
459 (with-output-to-string (*standard-output
*)
460 (take-it-out-for-a-test-walk
461 (eval-when (:execute
:compile-toplevel
:load-toplevel
)
464 "Form: (EVAL-WHEN (:EXECUTE :COMPILE-TOPLEVEL :LOAD-TOPLEVEL) A (FOO A)) Context: EVAL
465 Form: A Context: EVAL
466 Form: (FOO A) Context: EVAL
467 Form: 'GLOBAL-FOO Context: EVAL
468 \(EVAL-WHEN (:EXECUTE :COMPILE-TOPLEVEL :LOAD-TOPLEVEL) A (FOO A))")))
470 (test-util:with-test
(:name
(:walk multiple-value-bind
))
471 (assert (string=-modulo-tabspace
472 (with-output-to-string (*standard-output
*)
473 (take-it-out-for-a-test-walk (multiple-value-bind (a b
)
474 (foo a b
) (list a b
))))
475 "Form: (MULTIPLE-VALUE-BIND (A B) (FOO A B) (LIST A B)) Context: EVAL
476 Form: (FOO A B) Context: EVAL
477 Form: 'GLOBAL-FOO Context: EVAL
478 Form: (LIST A B) Context: EVAL
479 Form: A Context: EVAL; lexically bound
480 Form: B Context: EVAL; lexically bound
481 \(MULTIPLE-VALUE-BIND (A B) (FOO A B) (LIST A B))")))
483 (test-util:with-test
(:name
(:walk multiple-value-bind special
))
484 (assert (string=-modulo-tabspace
485 (with-output-to-string (*standard-output
*)
486 (take-it-out-for-a-test-walk (multiple-value-bind (a b
)
488 (declare (special a
))
490 "Form: (MULTIPLE-VALUE-BIND (A B) (FOO A B) (DECLARE (SPECIAL A)) (LIST A B)) Context: EVAL
491 Form: (FOO A B) Context: EVAL
492 Form: 'GLOBAL-FOO Context: EVAL
493 Form: (LIST A B) Context: EVAL
494 Form: A Context: EVAL; lexically bound; declared special
495 Form: B Context: EVAL; lexically bound
496 \(MULTIPLE-VALUE-BIND (A B) (FOO A B) (DECLARE (SPECIAL A)) (LIST A B))")))
498 (test-util:with-test
(:name
(:walk progn function
))
499 (assert (string=-modulo-tabspace
500 (with-output-to-string (*standard-output
*)
501 (take-it-out-for-a-test-walk (progn (function foo
))))
502 "Form: (PROGN #'FOO) Context: EVAL
503 Form: #'FOO Context: EVAL
506 (test-util:with-test
(:name
(:walk progn go
))
507 (assert (string=-modulo-tabspace
508 (with-output-to-string (*standard-output
*)
509 (take-it-out-for-a-test-walk (progn a b
(go a
))))
510 "Form: (PROGN A B (GO A)) Context: EVAL
511 Form: A Context: EVAL
512 Form: B Context: EVAL
513 Form: (GO A) Context: EVAL
514 \(PROGN A B (GO A))")))
516 (test-util:with-test
(:name
(:walk if
1))
517 (assert (string=-modulo-tabspace
518 (with-output-to-string (*standard-output
*)
519 (take-it-out-for-a-test-walk (if a b c
)))
520 "Form: (IF A B C) Context: EVAL
521 Form: A Context: EVAL
522 Form: B Context: EVAL
523 Form: C Context: EVAL
526 (test-util:with-test
(:name
(:walk if
2))
527 (assert (string=-modulo-tabspace
528 (with-output-to-string (*standard-output
*)
529 (take-it-out-for-a-test-walk (if a b
)))
530 "Form: (IF A B) Context: EVAL
531 Form: A Context: EVAL
532 Form: B Context: EVAL
533 Form: NIL Context: EVAL; bound: NIL
536 (test-util:with-test
(:name
(:walk lambda
))
537 (assert (string=-modulo-tabspace
538 (with-output-to-string (*standard-output
*)
539 (take-it-out-for-a-test-walk ((lambda (a b
) (list a b
)) 1 2)))
540 "Form: ((LAMBDA (A B) (LIST A B)) 1 2) Context: EVAL
541 Form: (LAMBDA (A B) (LIST A B)) Context: EVAL
542 Form: (LIST A B) Context: EVAL
543 Form: A Context: EVAL; lexically bound
544 Form: B Context: EVAL; lexically bound
545 Form: 1 Context: EVAL
546 Form: 2 Context: EVAL
547 \((LAMBDA (A B) (LIST A B)) 1 2)")))
549 (test-util:with-test
(:name
(:walk lambda special
))
550 (assert (string=-modulo-tabspace
551 (with-output-to-string (*standard-output
*)
552 (take-it-out-for-a-test-walk ((lambda (a b
)
553 (declare (special a
))
556 "Form: ((LAMBDA (A B) (DECLARE (SPECIAL A)) (LIST A B)) 1 2) Context: EVAL
557 Form: (LAMBDA (A B) (DECLARE (SPECIAL A)) (LIST A B)) Context: EVAL
558 Form: (LIST A B) Context: EVAL
559 Form: A Context: EVAL; lexically bound; declared special
560 Form: B Context: EVAL; lexically bound
561 Form: 1 Context: EVAL
562 Form: 2 Context: EVAL
563 \((LAMBDA (A B) (DECLARE (SPECIAL A)) (LIST A B)) 1 2)")))
565 (test-util:with-test
(:name
(:walk let list
))
566 (assert (string=-modulo-tabspace
567 (with-output-to-string (*standard-output
*)
568 (take-it-out-for-a-test-walk (let ((a a
) (b a
) (c b
))
570 "Form: (LET ((A A) (B A) (C B))
571 (LIST A B C)) Context: EVAL
572 Form: A Context: EVAL
573 Form: A Context: EVAL
574 Form: B Context: EVAL
575 Form: (LIST A B C) Context: EVAL
576 Form: A Context: EVAL; lexically bound
577 Form: B Context: EVAL; lexically bound
578 Form: C Context: EVAL; lexically bound
579 \(LET ((A A) (B A) (C B))
582 (test-util:with-test
(:name
(:walk let
* list
))
583 (assert (string=-modulo-tabspace
584 (with-output-to-string (*standard-output
*)
585 (take-it-out-for-a-test-walk (let* ((a a
) (b a
) (c b
)) (list a b c
))))
586 "Form: (LET* ((A A) (B A) (C B))
587 (LIST A B C)) Context: EVAL
588 Form: A Context: EVAL
589 Form: A Context: EVAL; lexically bound
590 Form: B Context: EVAL; lexically bound
591 Form: (LIST A B C) Context: EVAL
592 Form: A Context: EVAL; lexically bound
593 Form: B Context: EVAL; lexically bound
594 Form: C Context: EVAL; lexically bound
595 \(LET* ((A A) (B A) (C B))
598 (test-util:with-test
(:name
(:walk let special list
))
599 (assert (string=-modulo-tabspace
600 (with-output-to-string (*standard-output
*)
601 (take-it-out-for-a-test-walk (let ((a a
) (b a
) (c b
))
602 (declare (special a b
))
604 "Form: (LET ((A A) (B A) (C B))
605 (DECLARE (SPECIAL A B))
606 (LIST A B C)) Context: EVAL
607 Form: A Context: EVAL
608 Form: A Context: EVAL
609 Form: B Context: EVAL
610 Form: (LIST A B C) Context: EVAL
611 Form: A Context: EVAL; lexically bound; declared special
612 Form: B Context: EVAL; lexically bound; declared special
613 Form: C Context: EVAL; lexically bound
614 \(LET ((A A) (B A) (C B))
615 (DECLARE (SPECIAL A B))
618 ;;;; Bug in LET* walking!
619 (test-util:with-test
(:name
(:walk let
* special list
:hairy-specials
))
621 (string=-modulo-tabspace
622 (with-output-to-string (*standard-output
*)
623 (take-it-out-for-a-test-walk (let* ((a a
) (b a
) (c b
))
624 (declare (special a b
))
626 "Form: (LET* ((A A) (B A) (C B))
627 (DECLARE (SPECIAL A B))
628 (LIST A B C)) Context: EVAL
629 Form: A Context: EVAL
630 Form: A Context: EVAL; lexically bound; declared special
631 Form: B Context: EVAL; lexically bound; declared special
632 Form: (LIST A B C) Context: EVAL
633 Form: A Context: EVAL; lexically bound; declared special
634 Form: B Context: EVAL; lexically bound; declared special
635 Form: C Context: EVAL; lexically bound
636 (LET* ((A A) (B A) (C B))
637 (DECLARE (SPECIAL A B))
640 (test-util:with-test
(:name
(:walk let special
5))
641 (assert (string=-modulo-tabspace
642 (with-output-to-string (*standard-output
*)
643 (take-it-out-for-a-test-walk (let ((a 1) (b 2))
646 (declare (special a
))
648 "Form: (LET ((A 1) (B 2))
651 (DECLARE (SPECIAL A))
652 (FOO A B))) Context: EVAL
653 Form: 1 Context: EVAL
654 Form: 2 Context: EVAL
655 Form: (FOO BAR) Context: EVAL
656 Form: 'GLOBAL-FOO Context: EVAL
658 (DECLARE (SPECIAL A))
659 (FOO A B)) Context: EVAL
660 Form: (FOO A B) Context: EVAL
661 Form: 'GLOBAL-FOO Context: EVAL
665 (DECLARE (SPECIAL A))
668 (test-util:with-test
(:name
(:walk multiple-value-call
))
669 (assert (string=-modulo-tabspace
670 (with-output-to-string (*standard-output
*)
671 (take-it-out-for-a-test-walk (multiple-value-call #'foo a b c
)))
672 "Form: (MULTIPLE-VALUE-CALL #'FOO A B C) Context: EVAL
673 Form: #'FOO Context: EVAL
674 Form: A Context: EVAL
675 Form: B Context: EVAL
676 Form: C Context: EVAL
677 \(MULTIPLE-VALUE-CALL #'FOO A B C)")))
679 (test-util:with-test
(:name
(:walk multiple-value-prog1
))
680 (assert (string=-modulo-tabspace
681 (with-output-to-string (*standard-output
*)
682 (take-it-out-for-a-test-walk (multiple-value-prog1 a b c
)))
683 "Form: (MULTIPLE-VALUE-PROG1 A B C) Context: EVAL
684 Form: A Context: EVAL
685 Form: B Context: EVAL
686 Form: C Context: EVAL
687 \(MULTIPLE-VALUE-PROG1 A B C)")))
689 (test-util:with-test
(:name
(:walk progn
2))
690 (assert (string=-modulo-tabspace
691 (with-output-to-string (*standard-output
*)
692 (take-it-out-for-a-test-walk (progn a b c
)))
693 "Form: (PROGN A B C) Context: EVAL
694 Form: A Context: EVAL
695 Form: B Context: EVAL
696 Form: C Context: EVAL
699 (test-util:with-test
(:name
(:walk progv
))
700 (assert (string=-modulo-tabspace
701 (with-output-to-string (*standard-output
*)
702 (take-it-out-for-a-test-walk (progv vars vals a b c
)))
703 "Form: (PROGV VARS VALS A B C) Context: EVAL
704 Form: VARS Context: EVAL
705 Form: VALS Context: EVAL
706 Form: A Context: EVAL
707 Form: B Context: EVAL
708 Form: C Context: EVAL
709 \(PROGV VARS VALS A B C)")))
711 (test-util:with-test
(:name
(:walk quote
))
712 (assert (string=-modulo-tabspace
713 (with-output-to-string (*standard-output
*)
714 (take-it-out-for-a-test-walk (quote a
)))
715 "Form: 'A Context: EVAL
718 (test-util:with-test
(:name
(:walk return-from
))
719 (assert (string=-modulo-tabspace
720 (with-output-to-string (*standard-output
*)
721 (take-it-out-for-a-test-walk (return-from block-name a b c
)))
722 "Form: (RETURN-FROM BLOCK-NAME A B C) Context: EVAL
723 Form: A Context: EVAL
724 Form: B Context: EVAL
725 Form: C Context: EVAL
726 \(RETURN-FROM BLOCK-NAME A B C)")))
729 (test-util:with-test
(:name
(:walk setq
1))
730 (assert (string=-modulo-tabspace
731 (with-output-to-string (*standard-output
*)
732 (take-it-out-for-a-test-walk (setq a
1)))
733 "Form: (SETQ A 1) Context: EVAL
735 Form: 1 Context: EVAL
739 (test-util:with-test
(:name
(:walk setq
2))
740 (assert (string=-modulo-tabspace
741 (with-output-to-string (*standard-output
*)
742 (take-it-out-for-a-test-walk (setq a
(foo 1) b
(bar 2) c
3)))
743 "Form: (SETQ A (FOO 1) B (BAR 2) C 3) Context: EVAL
744 Form: (SETQ A (FOO 1)) Context: EVAL
746 Form: (FOO 1) Context: EVAL
747 Form: 'GLOBAL-FOO Context: EVAL
748 Form: (SETQ B (BAR 2)) Context: EVAL
750 Form: (BAR 2) Context: EVAL
751 Form: 'GLOBAL-BAR Context: EVAL
752 Form: (SETQ C 3) Context: EVAL
754 Form: 3 Context: EVAL
755 \(SETQ A (FOO 1) B (BAR 2) C 3)")))
760 (test-util:with-test
(:name
(:walk tagbody
))
761 (assert (string=-modulo-tabspace
762 (with-output-to-string (*standard-output
*)
763 (take-it-out-for-a-test-walk (tagbody a b c
(go a
))))
764 "Form: (TAGBODY A B C (GO A)) Context: EVAL
765 Form: (GO A) Context: EVAL
766 \(TAGBODY A B C (GO A))")))
768 (test-util:with-test
(:name
(:walk the
))
769 (assert (string=-modulo-tabspace
770 (with-output-to-string (*standard-output
*)
771 (take-it-out-for-a-test-walk (the foo
(foo-form a b c
))))
772 "Form: (THE FOO (FOO-FORM A B C)) Context: EVAL
773 Form: (FOO-FORM A B C) Context: EVAL
774 Form: A Context: EVAL
775 Form: B Context: EVAL
776 Form: C Context: EVAL
777 \(THE FOO (FOO-FORM A B C))")))
779 (test-util:with-test
(:name
(:walk throw
))
780 (assert (string=-modulo-tabspace
781 (with-output-to-string (*standard-output
*)
782 (take-it-out-for-a-test-walk (throw tag-form a
)))
783 "Form: (THROW TAG-FORM A) Context: EVAL
784 Form: TAG-FORM Context: EVAL
785 Form: A Context: EVAL
786 \(THROW TAG-FORM A)")))
788 (test-util:with-test
(:name
(:walk unwind-protect
))
789 (assert (string=-modulo-tabspace
790 (with-output-to-string (*standard-output
*)
791 (take-it-out-for-a-test-walk (unwind-protect (foo a b
) d e f
)))
792 "Form: (UNWIND-PROTECT (FOO A B) D E F) Context: EVAL
793 Form: (FOO A B) Context: EVAL
794 Form: 'GLOBAL-FOO Context: EVAL
795 Form: D Context: EVAL
796 Form: E Context: EVAL
797 Form: F Context: EVAL
798 \(UNWIND-PROTECT (FOO A B) D E F)")))
800 (defmacro flet-1
(a b
)
801 (declare (ignore a b
))
804 (defmacro labels-1
(a b
)
805 (declare (ignore a b
))
808 (test-util:with-test
(:name
(:walk flet defmacro
))
809 (assert (string=-modulo-tabspace
810 (with-output-to-string (*standard-output
*)
811 (take-it-out-for-a-test-walk
812 (flet ((flet-1 (a b
) () (flet-1 a b
) (list a b
)))
815 "Form: (FLET ((FLET-1 (A B)
820 (FOO 1 2)) Context: EVAL
821 Form: NIL Context: EVAL; bound: NIL
822 Form: (FLET-1 A B) Context: EVAL
823 Form: 'OUTER Context: EVAL
824 Form: (LIST A B) Context: EVAL
825 Form: A Context: EVAL; lexically bound
826 Form: B Context: EVAL; lexically bound
827 Form: (FLET-1 1 2) Context: EVAL
828 Form: 1 Context: EVAL
829 Form: 2 Context: EVAL
830 Form: (FOO 1 2) Context: EVAL
831 Form: 'GLOBAL-FOO Context: EVAL
832 \(FLET ((FLET-1 (A B)
839 (test-util:with-test
(:name
(:walk labels defmacro
))
840 (assert (string=-modulo-tabspace
841 (with-output-to-string (*standard-output
*)
842 (take-it-out-for-a-test-walk
843 (labels ((label-1 (a b
) () (label-1 a b
)(list a b
)))
846 "Form: (LABELS ((LABEL-1 (A B)
851 (FOO 1 2)) Context: EVAL
852 Form: NIL Context: EVAL; bound: NIL
853 Form: (LABEL-1 A B) Context: EVAL
854 Form: A Context: EVAL; lexically bound
855 Form: B Context: EVAL; lexically bound
856 Form: (LIST A B) Context: EVAL
857 Form: A Context: EVAL; lexically bound
858 Form: B Context: EVAL; lexically bound
859 Form: (LABEL-1 1 2) Context: EVAL
860 Form: 1 Context: EVAL
861 Form: 2 Context: EVAL
862 Form: (FOO 1 2) Context: EVAL
863 Form: 'GLOBAL-FOO Context: EVAL
864 \(LABELS ((LABEL-1 (A B)
871 (test-util:with-test
(:name
(:walk macrolet
1))
872 (assert (string=-modulo-tabspace
873 (with-output-to-string (*standard-output
*)
874 (take-it-out-for-a-test-walk (macrolet ((macrolet-1 (a b
) (list a b
)))
877 "Form: (MACROLET ((MACROLET-1 (A B)
880 (FOO 1 2)) Context: EVAL
881 Form: (LIST A B) Context: EVAL
882 Form: A Context: EVAL; lexically bound
883 Form: B Context: EVAL; lexically bound
884 Form: (MACROLET-1 A B) Context: EVAL
885 Form: (A B) Context: EVAL
886 Form: B Context: EVAL
887 Form: (FOO 1 2) Context: EVAL
888 Form: 'GLOBAL-FOO Context: EVAL
889 \(MACROLET ((MACROLET-1 (A B)
894 (test-util:with-test
(:name
(:walk macrolet
2))
895 (assert (string=-modulo-tabspace
896 (with-output-to-string (*standard-output
*)
897 (take-it-out-for-a-test-walk (macrolet ((foo (a) `(inner-foo-expanded ,a
)))
899 "Form: (MACROLET ((FOO (A)
900 `(INNER-FOO-EXPANDED ,A)))
901 (FOO 1)) Context: EVAL
902 Form: `(INNER-FOO-EXPANDED ,A) Context: EVAL
903 Form: (LIST 'INNER-FOO-EXPANDED A) Context: EVAL
904 Form: 'INNER-FOO-EXPANDED Context: EVAL
905 Form: A Context: EVAL; lexically bound
906 Form: (FOO 1) Context: EVAL
907 Form: (INNER-FOO-EXPANDED 1) Context: EVAL
908 Form: 1 Context: EVAL
910 `(INNER-FOO-EXPANDED ,A)))
913 (test-util:with-test
(:name
(:walk macrolet progn
1))
914 (assert (string=-modulo-tabspace
915 (with-output-to-string (*standard-output
*)
916 (take-it-out-for-a-test-walk (progn (bar 1)
918 `(inner-bar-expanded ,a
)))
923 `(INNER-BAR-EXPANDED ,A)))
924 (BAR 2))) Context: EVAL
925 Form: (BAR 1) Context: EVAL
926 Form: 'GLOBAL-BAR Context: EVAL
927 Form: (MACROLET ((BAR (A)
928 `(INNER-BAR-EXPANDED ,A)))
929 (BAR 2)) Context: EVAL
930 Form: `(INNER-BAR-EXPANDED ,A) Context: EVAL
931 Form: (LIST 'INNER-BAR-EXPANDED A) Context: EVAL
932 Form: 'INNER-BAR-EXPANDED Context: EVAL
933 Form: A Context: EVAL; lexically bound
934 Form: (BAR 2) Context: EVAL
935 Form: (INNER-BAR-EXPANDED 2) Context: EVAL
936 Form: 2 Context: EVAL
940 `(INNER-BAR-EXPANDED ,A)))
943 (test-util:with-test
(:name
(:walk macrolet progn
2))
944 (assert (string=-modulo-tabspace
945 (with-output-to-string (*standard-output
*)
946 (take-it-out-for-a-test-walk (progn (bar 1)
949 `(inner-bar-expanded ,s
)))
955 `(INNER-BAR-EXPANDED ,S)))
956 (BAR 2))) Context: EVAL
957 Form: (BAR 1) Context: EVAL
958 Form: 'GLOBAL-BAR Context: EVAL
959 Form: (MACROLET ((BAR (S)
961 `(INNER-BAR-EXPANDED ,S)))
962 (BAR 2)) Context: EVAL
963 Form: (BAR S) Context: EVAL
964 Form: 'GLOBAL-BAR Context: EVAL
965 Form: `(INNER-BAR-EXPANDED ,S) Context: EVAL
966 Form: (LIST 'INNER-BAR-EXPANDED S) Context: EVAL
967 Form: 'INNER-BAR-EXPANDED Context: EVAL
968 Form: S Context: EVAL; lexically bound
969 Form: (BAR 2) Context: EVAL
970 Form: (INNER-BAR-EXPANDED 2) Context: EVAL
971 Form: 2 Context: EVAL
976 `(INNER-BAR-EXPANDED ,S)))
979 (test-util:with-test
(:name
(:walk cond
))
980 (assert (string=-modulo-tabspace
981 (with-output-to-string (*standard-output
*)
982 (take-it-out-for-a-test-walk (cond (a b
)
983 ((foo bar
) a
(foo a
)))))
984 "Form: (COND (A B) ((FOO BAR) A (FOO A))) Context: EVAL
985 Form: (IF A (PROGN B) (COND ((FOO BAR) A (FOO A)))) Context: EVAL
986 Form: A Context: EVAL
987 Form: (PROGN B) Context: EVAL
988 Form: B Context: EVAL
989 Form: (COND ((FOO BAR) A (FOO A))) Context: EVAL
990 Form: (IF (FOO BAR) (PROGN A (FOO A)) NIL) Context: EVAL
991 Form: (FOO BAR) Context: EVAL
992 Form: 'GLOBAL-FOO Context: EVAL
993 Form: (PROGN A (FOO A)) Context: EVAL
994 Form: A Context: EVAL
995 Form: (FOO A) Context: EVAL
996 Form: 'GLOBAL-FOO Context: EVAL
997 Form: NIL Context: EVAL; bound: NIL
998 \(COND (A B) ((FOO BAR) A (FOO A)))")))
1000 (test-util:with-test
(:name
(:walk let lambda
))
1001 (assert (string=-modulo-tabspace
1002 (with-output-to-string (*standard-output
*)
1003 (let ((the-lexical-variables ()))
1004 (walk-form '(let ((a 1) (b 2))
1005 (lambda (x) (list a b x y
)))
1007 (lambda (form context env
)
1008 (declare (ignore context
))
1009 (when (and (symbolp form
)
1010 (var-lexical-p form env
))
1011 (push form the-lexical-variables
))
1013 (or (and (= (length the-lexical-variables
) 3)
1014 (member 'a the-lexical-variables
)
1015 (member 'b the-lexical-variables
)
1016 (member 'x the-lexical-variables
))
1017 (error "Walker didn't do lexical variables of a closure properly."))))
1020 (test-util:with-test
(:name
(:walk setq
:macro
))
1021 (assert (string=-modulo-tabspace
1022 (with-output-to-string (*standard-output
*)
1023 (take-it-out-for-a-test-walk
1024 (macrolet ((x () 'y
))
1026 "Form: (MACROLET ((X ()
1028 (SETQ (X) 3)) Context: EVAL
1029 Form: 'Y Context: EVAL
1030 Form: (SETQ (X) 3) Context: EVAL
1031 Form: (X) Context: SET
1032 Form: 3 Context: EVAL
1038 (test-util:with-test
(:name
(:walk let
* special list
:hairier-specials
))
1040 (string=-modulo-tabspace
1041 (with-output-to-string (*standard-output
*)
1042 (take-it-out-for-a-test-walk (let* ((a a
) (b a
) (c b
) (b c
))
1043 (declare (special a b
))
1045 "Form: (LET* ((A A) (B A) (C B) (B C))
1046 (DECLARE (SPECIAL A B))
1047 (LIST A B C)) Context: EVAL
1048 Form: A Context: EVAL
1049 Form: A Context: EVAL; lexically bound; declared special
1050 Form: B Context: EVAL; lexically bound
1051 Form: C Context: EVAL; lexically bound
1052 Form: (LIST A B C) Context: EVAL
1053 Form: A Context: EVAL; lexically bound; declared special
1054 Form: B Context: EVAL; lexically bound; declared special
1055 Form: C Context: EVAL; lexically bound
1056 \(LET* ((A A) (B A) (C B) (B C))
1057 (DECLARE (SPECIAL A B))
1062 ;;; Old PCL hung up on this.