1 ;;;; tests related to the way objects are dumped into fasl files
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 (cl:in-package :cl-user)
16 (declaim (optimize (debug 3) (speed 2) (space 1)))
18 ;;; Don Geddis reported this test case 25 December 1999 on a CMU CL
19 ;;; mailing list: dumping circular lists caused the compiler to enter
20 ;;; an infinite loop. Douglas Crosher reported a patch 27 Dec 1999.
21 ;;; The patch was tested on SBCL by Martin Atzmueller 2 Nov 2000, and
22 ;;; merged in sbcl-0.6.8.11.
23 (defun q-dg1999-1 () (dolist (x '#1=("A" "B" . #1#)) x))
24 (defun q-dg1999-2 () (dolist (x '#1=("C" "D" . #1#)) x))
25 (defun q-dg1999-3 () (dolist (x '#1=("E" "F" . #1#)) x))
26 (defun q-dg1999-4 () (dolist (x '#1=("C" "D" . #1#)) x))
27 (defun useful-dg1999 (keys)
28 (declare (type list keys))
30 for c in '#1=("Red" "Blue" . #1#)
33 ;;; sbcl-0.6.11.25 or so had DEF!STRUCT/MAKE-LOAD-FORM/HOST screwed up
34 ;;; so that the compiler couldn't dump pathnames.
35 (format t "Now the compiler can dump pathnames again: ~S ~S~%" #p"" #p"/x/y/z")
37 (eval-when (:compile-toplevel :load-toplevel :execute)
39 (defmethod make-load-form ((foo foo) &optional env)
40 (declare (ignore env))
41 ;; an extremely meaningless MAKE-LOAD-FORM method whose only point
42 ;; is to exercise the mechanism a little bit
43 (values `(make-foo :x (list ',(foo-x foo)))
44 `(setf (foo-y ,foo) ',foo))))
47 #.(make-foo :x "X" :y "Y"))
49 (assert (equalp (foo-x *foo*) '("X")))
50 (assert (eql (foo-y *foo*) *foo*))
52 ;;; Logical pathnames should be dumpable, too, but what does it mean?
53 ;;; As of sbcl-0.7.7.16, we've taken dumping the host part to mean
54 ;;; dumping a reference to the name of the host (much as dumping a
55 ;;; symbol involves dumping a reference to the name of its package).
56 (eval-when (:compile-toplevel :load-toplevel :execute)
57 (setf (logical-pathname-translations "MY-LOGICAL-HOST")
58 (list '("**;*.*.*" "/tmp/*.*"))))
60 (defparameter *path* #p"MY-LOGICAL-HOST:FOO;BAR.LISP")
62 ;;; Non-SIMPLE-ARRAY VECTORs should be dumpable, though they can lose
63 ;;; their complex attributes.
65 (defparameter *string* #.(make-array 3 :initial-element #\a
67 :element-type 'character))
69 ;;; SBCL 0.7.8 incorrectly read high bits of (COMPLEX DOUBLE-FLOAT)
70 ;;; components as unsigned bytes.
71 (defparameter *numbers*
73 #c(-1s0 -1s0) #c(-1f0 -1f0) #c(-1d0 -1d0) #c(-1l0 -1l0)))
75 ;;; tests for MAKE-LOAD-FORM-SAVING-SLOTS
76 (eval-when (:compile-toplevel :load-toplevel :execute)
77 (defstruct savable-structure
79 (b nil :type symbol :read-only t)
82 (e 17 :type (unsigned-byte 32) :read-only t))
83 (defmethod make-load-form ((s savable-structure) &optional env)
84 (make-load-form-saving-slots s :environment env)))
85 (defparameter *savable-structure*
86 #.(make-savable-structure :a t :b 'frob :c 1 :d 39 :e 19))
87 (assert (eql (savable-structure-a *savable-structure*) t))
88 (assert (eql (savable-structure-b *savable-structure*) 'frob))
89 (assert (eql (savable-structure-c *savable-structure*) 1))
90 (assert (eql (savable-structure-d *savable-structure*) 39))
91 (assert (eql (savable-structure-e *savable-structure*) 19))
93 ;;; ensure that we can dump and reload specialized arrays whose element
94 ;;; size is smaller than a byte (caused a few problems circa SBCL
97 (defvar *1-bit* #.(make-array 5 :element-type 'bit :initial-element 0))
98 (defvar *2-bit* #.(make-array 5 :element-type '(unsigned-byte 2) :initial-element 0))
99 (defvar *4-bit* #.(make-array 5 :element-type '(unsigned-byte 4) :initial-element 1))
101 ;;; tests for constant coalescing (and absence of such) in the
102 ;;; presence of strings.
104 (defvar *character-string-1* #.(make-string 5 :initial-element #\a))
105 (defvar *character-string-2* #.(make-string 5 :initial-element #\a))
106 (assert (eq *character-string-1* *character-string-2*))
107 (assert (typep *character-string-1* '(simple-array character (5)))))
110 (defvar *base-string-1*
111 #.(make-string 5 :initial-element #\b :element-type 'base-char))
112 (defvar *base-string-2*
113 #.(make-string 5 :initial-element #\b :element-type 'base-char))
114 (assert (eq *base-string-1* *base-string-2*))
115 (assert (typep *base-string-1* '(simple-base-string 5))))
117 #-#.(cl:if (cl:subtypep 'cl:character 'cl:base-char) '(and) '(or))
119 (defvar *base-string*
120 #.(make-string 5 :element-type 'base-char :initial-element #\x))
121 (defvar *character-string*
122 #.(make-string 5 :initial-element #\x))
123 (assert (not (eq *base-string* *character-string*)))
124 (assert (typep *base-string* 'base-string))
125 (assert (typep *character-string* '(vector character))))
127 (sb-ext:quit :unix-status 104) ; success