1.0.13.44: bug #414 has disappeared
[sbcl/simd.git] / tests / dump.impure-cload.lisp
blob28aeb249d6ea05db92b7857c08bd7c5237e89f8b
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
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 (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))
29 (loop
30 for c in '#1=("Red" "Blue" . #1#)
31 for key in keys))
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)
38 (defstruct foo x y)
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))))
46 (defparameter *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
66 :fill-pointer 2
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*
72 '(-1s0 -1f0 -1d0 -1l0
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
78 (a nil :type symbol)
79 (b nil :type symbol :read-only t)
80 (c nil :read-only t)
81 (d 0 :type fixnum)
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 ;;; null :SLOT-NAMES /= unsupplied
94 (eval-when (:compile-toplevel :load-toplevel :execute)
95 (defclass savable-class ()
96 ((a :initform t :initarg :a)))
97 (defmethod make-load-form ((s savable-class) &optional env)
98 (make-load-form-saving-slots s :environment env :slot-names '())))
99 (defparameter *savable-class*
100 #.(make-instance 'savable-class :a 3))
101 (assert (not (slot-boundp *savable-class* 'a)))
104 ;;; ensure that we can dump and reload specialized arrays whose element
105 ;;; size is smaller than a byte (caused a few problems circa SBCL
106 ;;; 0.8.14.4)
108 (defvar *1-bit* #.(make-array 5 :element-type 'bit :initial-element 0))
109 (defvar *2-bit* #.(make-array 5 :element-type '(unsigned-byte 2) :initial-element 0))
110 (defvar *4-bit* #.(make-array 5 :element-type '(unsigned-byte 4) :initial-element 1))
112 ;;; tests for constant coalescing (and absence of such) in the
113 ;;; presence of strings.
114 (progn
115 (defvar *character-string-1* #.(make-string 5 :initial-element #\a))
116 (defvar *character-string-2* #.(make-string 5 :initial-element #\a))
117 (assert (eq *character-string-1* *character-string-2*))
118 (assert (typep *character-string-1* '(simple-array character (5)))))
120 (progn
121 (defvar *base-string-1*
122 #.(make-string 5 :initial-element #\b :element-type 'base-char))
123 (defvar *base-string-2*
124 #.(make-string 5 :initial-element #\b :element-type 'base-char))
125 (assert (eq *base-string-1* *base-string-2*))
126 (assert (typep *base-string-1* '(simple-base-string 5))))
128 #-#.(cl:if (cl:subtypep 'cl:character 'cl:base-char) '(and) '(or))
129 (progn
130 (defvar *base-string*
131 #.(make-string 5 :element-type 'base-char :initial-element #\x))
132 (defvar *character-string*
133 #.(make-string 5 :initial-element #\x))
134 (assert (not (eq *base-string* *character-string*)))
135 (assert (typep *base-string* 'base-string))
136 (assert (typep *character-string* '(vector character))))