0.7.1.21:
[sbcl.git] / tests / compiler.impure.lisp
1 ;;;; This file is for compiler tests which have side effects (e.g.
2 ;;;; executing DEFUN) but which don't need any special side-effecting
3 ;;;; environmental stuff (e.g. DECLAIM of particular optimization
4 ;;;; settings). Similar tests which *do* expect special settings may
5 ;;;; be in files compiler-1.impure.lisp, compiler-2.impure.lisp, etc.
6
7 ;;;; This software is part of the SBCL system. See the README file for
8 ;;;; more information.
9 ;;;;
10 ;;;; While most of SBCL is derived from the CMU CL system, the test
11 ;;;; files (like this one) were written from scratch after the fork
12 ;;;; from CMU CL.
13 ;;;; 
14 ;;;; This software is in the public domain and is provided with
15 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
16 ;;;; more information.
17
18 (cl:in-package :cl-user)
19
20 (load "assertoid.lisp")
21
22 ;;; Old CMU CL code assumed that the names of "keyword" arguments are
23 ;;; necessarily self-evaluating symbols, but ANSI Common Lisp allows
24 ;;; them to be any symbols, not necessarily keywords, and thus not
25 ;;; necessarily self-evaluating. Make sure that this works.
26 (defun newfangled-cons (&key ((left-thing x)) ((right-thing y)))
27   (cons x y))
28 (assert (equal (cons 1 2) (newfangled-cons 'right-thing 2 'left-thing 1)))
29
30 ;;; ANSI specifically says that duplicate keys are OK in lambda lists,
31 ;;; with no special exception for macro lambda lists. (As reported by
32 ;;; Pierre Mai on cmucl-imp 2001-03-30, Python didn't think so. The
33 ;;; rest of the thread had some entertainment value, at least for me
34 ;;; (WHN). The unbelievers were besmote and now even CMU CL will
35 ;;; conform to the spec in this regard. Who needs diplomacy when you
36 ;;; have brimstone?:-)
37 (defmacro ayup-duplicate-keys-are-ok-i-see-the-lite (&key k)
38   k)
39 (assert (equal (ayup-duplicate-keys-are-ok-i-see-the-lite :k 112) 112))
40 (assert (equal (ayup-duplicate-keys-are-ok-i-see-the-lite :k 'x :k 'y) 'x))
41
42 ;;; As reported by Alexey Dejneka (sbcl-devel 2002-01-30), in
43 ;;; sbcl-0.7.1 plus his patch (i.e. essentially sbcl-0.7.1.2), the
44 ;;; compiler barfed on this, blowing up in FIND-IN-PHYSENV looking for
45 ;;; the LAMBDA-VAR named NUM. That was fixed in sbcl-0.7.1.3.
46 (defun parse-num (index)
47   (let (num x)
48     (flet ((digs ()
49              (setq num index))
50            (z ()
51              (let ()
52                (setq x nil))))
53       (when (and (digs) (digs)) x))))
54
55 ;;; Bug 132: The compiler used to fail to compile INTEGER-valued CATCH
56 ;;; tags. This was fixed by Alexey Dejneka in sbcl-0.7.1.14. (They're
57 ;;; still a bad idea because tags are compared with EQ, but now it's a
58 ;;; compiler warning instead of a failure to compile.)
59 (defun foo ()
60   (catch 0 (print 1331)))
61 \f
62 ;;;; tests not in the problem domain, but of the consistency of the
63 ;;;; compiler machinery itself
64
65 (in-package "SB-C")
66
67 ;;; Hunt for wrong-looking things in fundamental compiler definitions,
68 ;;; and gripe about them.
69 ;;;
70 ;;; FIXME: It should be possible to (1) repair the things that this
71 ;;; code gripes about, and then (2) make the code signal errors
72 ;;; instead of just printing complaints to standard output, in order
73 ;;; to prevent the code from later falling back into disrepair.
74 (defun grovel-results (function)
75   (dolist (template (fun-info-templates (info :function :info function)))
76     (when (template-more-results-type template)
77       (format t "~&Template ~A has :MORE results, and translates ~A.~%"
78               (template-name template)
79               function)
80       (return nil))
81     (when (eq (template-result-types template) :conditional)
82       ;; dunno.
83       (return t))
84     (let ((types (template-result-types template))
85           (result-type (fun-type-returns (info :function :type function))))
86       (cond
87         ((values-type-p result-type)
88          (do ((ltypes (append (args-type-required result-type)
89                               (args-type-optional result-type))
90                       (rest ltypes))
91               (types types (rest types)))
92              ((null ltypes)
93               (unless (null types)
94                 (format t "~&More types than ltypes in ~A, translating ~A.~%"
95                         (template-name template)
96                         function)
97                 (return nil)))
98            (when (null types)
99              (unless (null ltypes)
100                (format t "~&More ltypes than types in ~A, translating ~A.~%"
101                        (template-name template)
102                        function)
103                (return nil)))))
104         ((eq result-type (specifier-type nil))
105          (unless (null types)
106            (format t "~&Template ~A returns values for function ~A with RESULT-TYPE NIL.~%"
107                    (template-name template)
108                    function)
109            (return nil)))
110         ((/= (length types) 1)
111          (format t "~&Template ~A isn't returning 1 value for ~A.~%"
112                  (template-name template)
113                  function)
114          (return nil))
115         (t t)))))
116 (defun identify-suspect-vops (&optional (env (first
117                                               (last *info-environment*))))
118   (do-info (env :class class :type type :name name :value value)
119     (when (and (eq class :function) (eq type :type))
120       ;; OK, so we have an entry in the INFO database. Now, if ...
121       (let* ((info (info :function :info name))
122              (templates (and info (fun-info-templates info))))
123         (when templates
124           ;; ... it has translators
125           (grovel-results name))))))
126 (identify-suspect-vops)
127 \f
128 ;;; success
129 (quit :unix-status 104)