Debian Codegraph @

src/clos/builtin.lsp

raw
1 ;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil; Package: CLOS -*-
2 ;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab:
3
4 ;;;;
5 ;;;; Copyright (c) 1992, Giuseppe Attardi.
6 ;;;;
7 ;;;; See file 'LICENSE' for the copyright details.
8
9 (in-package "CLOS")
10
11 ;;; ----------------------------------------------------------------------
12 ;;; Methods
13
14 ;;; ======================================================================
15 ;;; Built-in classes
16 ;;; ----------------------------------------------------------------------
17
18 (defmethod make-instance ((class built-in-class) &rest initargs)
19 (declare (ignore initargs))
20 (error "The built-in class (~A) cannot be instantiated" class))
21
22 ;;;
23 ;;; At this point we can activate the vector of builtin classes, which
24 ;;; is used by class-of and other functions.
25 ;;;
26 (si::*make-constant '+builtin-classes+ +builtin-classes-pre-array+)
27
28 (defmethod ensure-class-using-class ((class null) name &rest rest)
29 (declare (ignore class))
30 (multiple-value-bind (metaclass direct-superclasses options)
31 (apply #'help-ensure-class rest)
32 (declare (ignore direct-superclasses))
33 (setf class (apply #'make-instance metaclass :name name options))
34 (when name
35 (si:create-type-name name)
36 (setf (find-class name) class))))
37
38 (defmethod change-class ((instance t) (new-class symbol) &rest initargs)
39 (apply #'change-class instance (find-class new-class) initargs))
40
41 (defmethod make-instances-obsolete ((class symbol))
42 (make-instances-obsolete (find-class class))
43 class)
44
45 (defmethod make-instance ((class-name symbol) &rest initargs)
46 (apply #'make-instance (find-class class-name) initargs))
47
48 (defmethod slot-makunbound-using-class ((class built-in-class) self slotd)
49 (declare (ignore class self slotd))
50 (error "SLOT-MAKUNBOUND-USING-CLASS cannot be applied on built-in objects"))
51
52 (defmethod slot-boundp-using-class ((class built-in-class) self slotd)
53 (declare (ignore class self slotd))
54 (error "SLOT-BOUNDP-USING-CLASS cannot be applied on built-in objects"))
55
56 (defmethod slot-value-using-class ((class built-in-class) self slotd)
57 (declare (ignore class self slotd))
58 (error "SLOT-VALUE-USING-CLASS cannot be applied on built-in objects"))
59
60 (defmethod (setf slot-value-using-class) (val (class built-in-class) self slotd)
61 (declare (ignore class self slotd val))
62 (error "SLOT-VALUE-USING-CLASS cannot be applied on built-in objects"))
63
64 (defmethod slot-exists-p-using-class ((class built-in-class) self slotd)
65 (declare (ignore class self slotd))
66 nil)
67
68 ;;; ======================================================================
69 ;;; STRUCTURES
70 ;;;
71
72 ;;; structure-classes cannot be instantiated
73 (defmethod allocate-instance ((class structure-class) &rest initargs)
74 (declare (ignore initargs))
75 (apply #'si::make-structure class
76 (make-list (class-size class) :initial-element nil)))
77
78 (defmethod finalize-inheritance ((class structure-class))
79 (when (class-finalized-p class)
80 (return-from finalize-inheritance))
81 (call-next-method)
82 (dolist (slot (class-slots class))
83 (unless (eq :INSTANCE (slot-definition-allocation slot))
84 (error "The structure class ~S can't have shared slots" (class-name class)))))
85
86 (defmethod make-load-form ((object structure-object) &optional environment)
87 (make-load-form-saving-slots object :key environment))
88
89 (defmethod print-object ((obj structure-object) stream)
90 (let* ((class (si:instance-class obj))
91 (slotds (class-slots class)))
92 (declare (:read-only class))
93 (when (and ;; *p-readably* effectively disables *p-level*
94 (not *print-readably*)
95 *print-level*
96 (zerop *print-level*))
97 (write-string "#" stream)
98 (return-from print-object obj))
99 (write-string "#S(" stream)
100 (prin1 (class-name class) stream)
101 (let ((*print-level* (if (and *print-level* (>= *print-level* 1))
102 (1- *print-level*)
103 *print-level*)))
104 (do ((scan slotds (cdr scan))
105 (i 0 (1+ i))
106 (limit (or *print-length* most-positive-fixnum))
107 (sv))
108 ((null scan))
109 (declare (fixnum i))
110 (when (>= i limit)
111 (write-string " ..." stream)
112 (return))
113 (setq sv (si:instance-ref obj i))
114 (write-string " " stream)
115 ;; 2.4.8.13 Sharpsign S: slots are keywords
116 (prin1 (intern (symbol-name (slot-definition-name (car scan)))
117 (find-package 'keyword))
118 stream)
119 (write-string " " stream)
120 (prin1 sv stream)))
121 (write-string ")" stream)
122 obj))