1.0.15.7: threaded BIND and UNBIND improvements on x86
[sbcl/tcr.git] / tests / ctor.impure.lisp
blobe8fecb14ecc5241a7cb7fc8da5d9860506c4a1ea
1 ;;;; gray-box testing of the constructor optimization machinery
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 (defpackage "CTOR-TEST"
15 (:use "CL"))
17 (in-package "CTOR-TEST")
19 (defclass no-slots () ())
21 (defun make-no-slots ()
22 (make-instance 'no-slots))
23 (compile 'make-no-slots)
25 (defmethod update-instance-for-redefined-class
26 ((object no-slots) added discarded plist &rest initargs)
27 (declare (ignore initargs))
28 (error "Called U-I-F-R-C on ~A" object))
30 (assert (typep (make-no-slots) 'no-slots))
32 (make-instances-obsolete 'no-slots)
34 (assert (typep (make-no-slots) 'no-slots))
35 (assert (typep (funcall #'(sb-pcl::ctor no-slots nil)) 'no-slots))
37 (defclass one-slot ()
38 ((a :initarg :a)))
40 (defun make-one-slot-a (a)
41 (make-instance 'one-slot :a a))
42 (compile 'make-one-slot-a)
43 (defun make-one-slot-noa ()
44 (make-instance 'one-slot))
45 (compile 'make-one-slot-noa)
47 (defmethod update-instance-for-redefined-class
48 ((object one-slot) added discarded plist &rest initargs)
49 (declare (ignore initargs))
50 (error "Called U-I-F-R-C on ~A" object))
52 (assert (= (slot-value (make-one-slot-a 3) 'a) 3))
53 (assert (not (slot-boundp (make-one-slot-noa) 'a)))
55 (make-instances-obsolete 'one-slot)
57 (assert (= (slot-value (make-one-slot-a 3) 'a) 3))
58 (assert (= (slot-value (funcall #'(sb-pcl::ctor one-slot nil :a sb-pcl::\.p0.) 4) 'a) 4))
59 (assert (not (slot-boundp (make-one-slot-noa) 'a)))
60 (assert (not (slot-boundp (funcall #'(sb-pcl::ctor one-slot nil)) 'a)))
62 (defclass one-slot-superclass ()
63 ((b :initarg :b)))
64 (defclass one-slot-subclass (one-slot-superclass)
65 ())
67 (defun make-one-slot-subclass (b)
68 (make-instance 'one-slot-subclass :b b))
69 (compile 'make-one-slot-subclass)
71 (defmethod update-instance-for-redifined-class
72 ((object one-slot-superclass) added discarded plist &rest initargs)
73 (declare (ignore initargs))
74 (error "Called U-I-F-R-C on ~A" object))
76 (assert (= (slot-value (make-one-slot-subclass 2) 'b) 2))
78 (make-instances-obsolete 'one-slot-subclass)
80 (assert (= (slot-value (make-one-slot-subclass 2) 'b) 2))
81 (assert (= (slot-value (funcall #'(sb-pcl::ctor one-slot-subclass nil :b sb-pcl::\.p0.) 3) 'b) 3))
82 (make-instances-obsolete 'one-slot-superclass)
84 (assert (= (slot-value (make-one-slot-subclass 2) 'b) 2))
85 (assert (= (slot-value (funcall #'(sb-pcl::ctor one-slot-subclass nil :b sb-pcl::\.p0.) 4) 'b) 4))
87 ;;;; success