1 ;;;; miscellaneous compiler tests with side effects (e.g. DEFUN
2 ;;;; changing FDEFINITIONs and globaldb stuff)
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; While most of SBCL is derived from the CMU CL system, the test
8 ;;;; files (like this one) were written from scratch after the fork
11 ;;;; This software is in the public domain and is provided with
12 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
13 ;;;; more information.
15 (cl:in-package :cl-user)
17 (declaim (optimize (debug 3) (speed 2) (space 1)))
19 ;;; Until version 0.6.9 or so, SBCL's version of Python couldn't do
20 ;;; this correctly, due to the bug patched by Rob MacLachlan on the
21 ;;; cmucl-imp list 2000-06-21, and applied to SBCL by Martin Atzmueller.
22 ;;; (The effectiveness of the test also depends on the implicit
23 ;;; function typing of Python (where DEFUN is like DECLAIM FTYPE),
24 ;;; which violates the ANSI spec, and should be fixed. Once that
25 ;;; unrelated bug is fixed, this code will no longer test the type
26 ;;; inference behavior it's intended to test.)
27 (defun emptyvalues (&rest rest) (declare (ignore rest)) (values))
30 (let ((res (emptyvalues)))
31 (unless (typep res 'foo)
33 (assert (eq (bar) 'expected-value))
35 (declaim (ftype (function (real) (values integer single-float)) valuesify))
38 (coerce x 'single-float)))
39 (defun exercise-valuesify (x)
40 (multiple-value-bind (i f) (valuesify x)
41 (declare (type integer i))
42 (declare (type single-float f))
44 (assert (= (exercise-valuesify 1.25) 2.25))
46 ;;; An early version (sbcl-0.6.11.33) of code to check FTYPEs from DEFUN
47 ;;; against DECLAIMed FTYPEs blew up when an FTYPE was DECLAIMed
48 ;;; to be pure FUNCTION, because the internal representation of
49 ;;; FUNCTION itself (as opposed to subtypes of FUNCTION, such as
50 ;;; (FUNCTION () T)) is a BUILT-IN-CLASS object, not a FUN-TYPE
52 (declaim (ftype function i-am-just-a-function))
53 (defun i-am-just-a-function (x y) (+ x y 1))
55 ;;; Stig E SandPHI (where PHI is some phi-like character not
56 ;;; representable in ASCII) reported in cclan-Bugs-431263 that SBCL
57 ;;; couldn't compile this. sbcl-0.6.12.26 died in CIRCULAR-LIST-P with
58 ;;; "The value \"EST\" is not of type LIST." Dan Barlow fixed it.
60 '((5 "EDT" . "EST") (6 "CDT" . "CST") (7 "MDT" .
61 "MST") (8 "PDT" . "PST")
62 (0 "GMT" . "GDT") (-2 "MET" . "MET DST"))
63 "*The string representations of the time zones.")
65 ;;; The old CMU CL Python compiler assumed that it was safe to infer
66 ;;; function types (including return types) from function definitions
67 ;;; and then use them to optimize code later. This is of course bad
68 ;;; when functions are redefined. The problem was fixed in
80 (assert (eql (bar 11) :real))
81 (assert (eql (bar -11) :fixnum))
82 (setf (symbol-function 'foo) #'identity)
83 (assert (eql (bar 11) :fixnum))
84 (assert (eql (bar -11.0) :real))
85 (assert (eql (bar "this is a test") :string))
86 (assert (eql (bar (make-hash-table)) :t))
88 ;;; bug reported by Brian Spilsbury sbcl-devel 2001-09-30, fixed by
89 ;;; Alexey Dejneka patch sbcl-devel 2001-10-02
90 (defun pixarray-element-size (pixarray)
91 (let ((eltype (array-element-type pixarray)))
92 (cond ((eq eltype 'bit) 1)
94 (eq (first eltype) 'unsigned-byte))
97 (error "Invalid pixarray: ~S." pixarray)))))
98 (assert (eql 1 (pixarray-element-size #*110)))
100 (sb-ext:quit :unix-status 104) ; success