File: mop-19.impure-cload.lisp

package info (click to toggle)
sbcl 1%3A0.9.16.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 19,960 kB
  • ctags: 16,537
  • sloc: lisp: 231,164; ansic: 19,558; asm: 2,539; sh: 1,925; makefile: 308
file content (76 lines) | stat: -rw-r--r-- 2,641 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;;;; miscellaneous side-effectful tests of the MOP

;;;; This software is part of the SBCL system. See the README file for
;;;; more information.
;;;;
;;;; While most of SBCL is derived from the CMU CL system, the test
;;;; files (like this one) were written from scratch after the fork
;;;; from CMU CL.
;;;;
;;;; This software is in the public domain and is provided with
;;;; absolutely no warranty. See the COPYING and CREDITS files for
;;;; more information.

;;; this file tests the accessor method class portion of the protocol
;;; for Initialization of Class Metaobjects.

(defpackage "MOP-19"
  (:use "CL" "SB-MOP"))

(in-package "MOP-19")

(defclass my-class (standard-class) ())
(defmethod validate-superclass ((a my-class) (b standard-class)) t)

(defclass my-reader (standard-reader-method) ())
(defclass my-writer (standard-writer-method) ())

(defvar *calls* nil)

(defmethod reader-method-class ((c my-class) s &rest initargs)
  (push (cons (slot-definition-name s) 'reader) *calls*)
  (find-class 'my-reader))
(defmethod writer-method-class ((c my-class) s &rest initargs)
  (push (cons (slot-definition-name s) 'writer) *calls*)
  (find-class 'my-writer))

(defclass foo ()
  ((a :reader a)
   (b :writer b)
   (c :accessor c))
  (:metaclass my-class))

(assert (= (length *calls*) 4))
(assert (= (count 'a *calls* :key #'car) 1))
(assert (= (count 'b *calls* :key #'car) 1))
(assert (= (count 'c *calls* :key #'car) 2))
(assert (= (count 'reader *calls* :key #'cdr) 2))
(assert (= (count 'writer *calls* :key #'cdr) 2))
(let ((method (find-method #'a nil (list (find-class 'foo)))))
  (assert (eq (class-of method) (find-class 'my-reader))))
(let ((method (find-method #'b nil (list (find-class t) (find-class 'foo)))))
  (assert (eq (class-of method) (find-class 'my-writer))))

(defclass my-other-class (my-class) ())
(defmethod validate-superclass ((a my-other-class) (b standard-class)) t)

(defclass my-other-reader (standard-reader-method) ())

(defclass my-direct-slot-definition (standard-direct-slot-definition) ())

(defmethod direct-slot-definition-class ((c my-other-class) &rest args)
  (find-class 'my-direct-slot-definition))

(defmethod reader-method-class :around
    (class (s my-direct-slot-definition) &rest initargs)
  (find-class 'my-other-reader))

(defclass bar ()
  ((d :reader d)
   (e :writer e))
  (:metaclass my-other-class))

(let ((method (find-method #'d nil (list (find-class 'bar)))))
  (assert (eq (class-of method) (find-class 'my-other-reader))))
(let ((method (find-method #'e nil (list (find-class t) (find-class 'bar)))))
  (assert (eq (class-of method) (find-class 'my-writer))))