tests: Refactor CHECKED-COMPILE
[sbcl.git] / tests / compiler-2.impure-cload.lisp
blob83052a8ced921bb19319a60e2b810c206f705a74
1 ;;;; -*- lisp -*-
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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
8 ;;;; from CMU CL.
9 ;;;;
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 (cl:in-package :cl-user)
16 ;;;; recognize self-calls
17 (declaim (optimize speed))
19 ;;; This is a fopcompilable form that caused FOP stack underflow
20 ;;; because the PROGN and SETQ each failed to push a NIL onto the stack.
21 ;;; >>> DO NOT ADD A (WITH-TEST) TO THIS. <<< It must stay fopcompilable.
22 (let ((a (progn)) ; lp# 1427050
23 (b (setq))
24 (c (+ 1 2)))
25 (print c)
26 (defvar *aaa* a)
27 (defvar *bbb* b))
30 ;;;; These three forms should be equivalent.
32 ;;; This used to be a bug in the handling of null-lexenv vs toplevel
33 ;;; policy: LOCALLY and MACROLET hid the toplevel policy from view.
35 (locally
36 (defun foo (n)
37 (frob 'foo)
38 (if (<= n 0)
40 (foo (1- n)))))
42 (progn
43 (defun bar (n)
44 (frob 'bar)
45 (if (<= n 0)
47 (bar (1- n)))))
49 (macrolet ()
50 (defun quux (n)
51 (frob 'quux)
52 (if (<= n 0)
54 (quux (1- n)))))
56 (defun frob (x)
57 (setf (fdefinition x) (constantly 13)))
59 (defun test ()
60 (list (foo 1) (bar 1) (quux 1)))
62 (assert (equal (test) '(0 0 0)))
63 (assert (equal (test) '(13 13 13))) ; sanity check
65 ;;; Bug in 1.0.2 and 1.0.3, where the XEP was compiled with the wrong
66 ;;; policy. (Test-case derived from code posted by alexander.ekart in
67 ;;; comp.lang.lisp).
69 (locally
70 (declare (optimize (safety 0)))
71 (defun bubblesort (x y)
72 (declare (type (simple-array fixnum (*)) x)
73 (type fixnum y)
74 (optimize (speed 3) (safety 3) (space 0) (debug 0)))
75 (aref x y)))
77 (assert-error (bubblesort (make-array 10) 9))
79 (define-symbol-macro %trash% what)
80 (locally
81 ;; just in case we get so smart that INFO becomes foldable
82 (declare (notinline sb-int:info))
83 (assert (eq (sb-int:info :variable :kind '%trash%) :macro))
84 (assert (eq (sb-int:info :variable :macro-expansion '%trash%) 'what))
85 (assert (sb-int:info :source-location :symbol-macro '%trash%)))
86 (let ()
87 (declare (notinline sb-int:info))
88 (defconstant %trash% 9) ; this is non-toplevel
89 (multiple-value-bind (val foundp)
90 (sb-int:info :variable :macro-expansion '%trash%)
91 (assert (and (not val) (not foundp)))))
93 ;; This must be one toplevel form.
94 ;; In practice you'd never do anything like this I suspect.
95 (progn
96 (defvar *foofoo1* 1)
97 (eval-when (:compile-toplevel)
98 (setq sb-c::*source-plist* '(strange "Yes")))
99 (defvar *foofoo2* 2))
101 (with-test (:name :source-location-plist-invalid-memoization)
102 (assert (null (sb-c:definition-source-location-plist
103 (sb-int:info :source-location :variable '*foofoo1*))))
104 (assert (equal (sb-c:definition-source-location-plist
105 (sb-int:info :source-location :variable '*foofoo2*))
106 '(strange "Yes"))))