1 ;;;; various tests of the interpreter
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 #-
(or sb-eval sb-fasteval
) (invoke-restart 'run-tests
::skip-file
)
16 (setf sb-ext
:*evaluator-mode
* :interpret
)
18 (assert (not (typep (lambda ()) 'compiled-function
)))
20 (assert (not (compiled-function-p (lambda ()))))
22 (let ((seen-forms (make-hash-table :test
'equal
)))
23 (let ((*macroexpand-hook
* (compile nil
24 `(lambda (fun form env
)
25 (setf (gethash form
,seen-forms
) t
)
26 (funcall fun form env
)))))
29 (assert (not (gethash '(when t nil
) seen-forms
)))
31 (assert (gethash '(when t nil
) seen-forms
)))))
33 ;;; defstruct constructor
34 (let ((sb-ext:*evaluator-mode
* :interpret
))
36 (defstruct evaluated-struct
38 (word 0 :type sb-ext
:word
)
39 (single 0.0 :type single-float
)
40 (double 0.0d0
:type double-float
)
41 (csingle (complex 0.0 0.0) :type
(complex single-float
))
42 (cdouble (complex 0.0d0
0.0d0
) :type
(complex double-float
)))
43 (defvar *evaluated-struct
* (make-evaluated-struct
48 :csingle
(complex 1.0 2.0)
49 :cdouble
(complex 2.0d0
3.0d0
)))
50 (assert (eq :foo
(evaluated-struct-pointer *evaluated-struct
*)))
51 (assert (eql 42 (evaluated-struct-word *evaluated-struct
*)))
52 (assert (eql 1.23 (evaluated-struct-single *evaluated-struct
*)))
53 (assert (eql 2.34d0
(evaluated-struct-double *evaluated-struct
*)))
54 (assert (eql #c
(1.0
2.0) (evaluated-struct-csingle *evaluated-struct
*)))
55 (assert (eql #c
(2.0d0
3.0d0
) (evaluated-struct-cdouble *evaluated-struct
*))))))
57 ;;; Prior to 1.0.25, the interpreter checked for package lock
58 ;;; violation for a local function in the fbinding form's body's
59 ;;; lexical environment.
60 (let ((sb-ext:*evaluator-mode
* :interpret
))
65 (locally (declare (disable-package-locks
66 ;; rather than create a whole new package
67 ;; just to test this corner case, we'll
68 ;; lexically shadow something innocuous in
73 (declare (enable-package-locks cl
:ed
))
77 (defvar *file
* (scratch-file-name "lisp"))
78 (with-test (:name
(:full-eval
:redefinition-warnings
))
79 (with-open-file (stream *file
* :direction
:output
:if-exists
:supersede
)
80 (write '(defun function-for-redefinition () nil
) :stream stream
))
81 (handler-bind ((warning #'error
))
82 (let ((sb-ext:*evaluator-mode
* :interpret
))
85 (let ((sb-ext:*evaluator-mode
* :compile
))
90 (defun save-it (f) (setq *stash
* f
) 'whatever
)
91 (with-test (:name
(let* :nested-environments
))
92 (let ((z 'zee
) (y 'y
) (x 92))
93 (let* ((baz (save-it (lambda (what) (assert (equal (list what x y z
)
94 (list what
92 'y
'zee
))))))
95 (mum (funcall *stash
* :after-binding-baz
))
97 (z (progn (funcall *stash
* :after-binding-y
) 'new-z
))
98 (x (progn (funcall *stash
* :after-binding-z
) 'new-x
)))
99 (funcall *stash
* :in-body
)
102 (with-test (:name
(let* :nested-environment-again
))
104 (foo (lambda () (typep foo
'integer
))))
105 (assert (funcall foo
))))
107 (declaim (inline some-inline-fun
))
109 (declare (muffle-conditions compiler-note
))
110 (defun some-inline-fun (x) (- x
)))
111 (with-test (:name
:inline-fun-captures-decl
:fails-on
(not :sb-fasteval
))
112 (assert (equal (sb-int:fun-name-inline-expansion
'some-inline-fun
)
113 '(sb-c:lambda-with-lexenv
114 ((declare (muffle-conditions compiler-note
))) (x)
115 (block some-inline-fun
(- x
))))))
117 (defun typecase-test (node)
124 (sb-kernel:layout
'winner
)))
126 (with-test (:name
:interpreted-type-constraint
)
127 (assert (eq (typecase-test (sb-kernel:find-layout
'cons
)) 'winner
)))
132 (defun a-class-x-0 (a)
135 (defmethod a-class-x-1 ((a a-class
))
138 (defmethod a-class-x-2 ((a a-class
))
142 (defmethod a-class-x-3 ((a t
))
145 (with-test (:name
(slot-value defun
))
146 (assert (= (a-class-x-0 (make-instance 'a-class
)) 123)))
148 (with-test (:name
(slot-value defmethod
))
149 (assert (= (a-class-x-1 (make-instance 'a-class
)) 123)))
151 (with-test (:name
(slot-value defmethod
let))
152 (assert (= (a-class-x-2 (make-instance 'a-class
)) 123)))
154 (with-test (:name
(slot-value defmethod
t))
155 (assert (= (a-class-x-3 (make-instance 'a-class
)) 123)))