4867c86f |
1 | (in-package :lisp-on-lines) |
2 | |
4358148e |
3 | ;;;; * DESCRIPTIONS |
4 | ;;;; A description is an object which is used |
5 | ;;;; to describe another object. |
6 | |
7 | ;;; HACK: |
8 | ;;; Since i'm not using deflayer, ensure-layer etc, |
9 | ;;; There are a few places where contextl gets confused |
10 | ;;; trying to locate my description layers. |
11 | |
12 | ;;; TODO: investigate switching to deflayer! |
13 | |
14 | (defun contextl::prepare-layer (layer) |
15 | (if (symbolp layer) |
16 | (if (eq (symbol-package layer) |
17 | (find-package :description-definers)) |
18 | layer |
19 | (contextl::defining-layer layer)) |
20 | |
21 | layer)) |
22 | |
23 | (defmethod find-layer-class :around ((layer symbol) &optional errorp environment) |
24 | (if (eq (symbol-package layer) |
25 | (find-package :description-definers)) |
26 | (find-class layer) |
27 | (call-next-method))) |
28 | |
29 | ;;; #+HACK |
30 | ;;; I'm having some 'issues' with |
31 | ;;; compiled code and my initialization. |
32 | ;;; So this hack initializes the world. |
33 | (eval-when (:compile-toplevel :load-toplevel :execute) |
34 | (defparameter *defined-descriptions* nil)) |
35 | |
4271ab0b |
36 | (define-layered-class description-access-class (standard-layer-class contextl::special-layered-access-class ) |
4358148e |
37 | ((defined-in-descriptions :initarg :in-description) |
38 | (mixin-class-p :initarg :mixinp))) |
39 | |
40 | (defmethod direct-slot-definition-class |
41 | ((class description-access-class) &key &allow-other-keys) |
42 | (find-class 'direct-attribute-definition-class)) |
43 | |
44 | (defmethod effective-slot-definition-class |
45 | ((class description-access-class) &key &allow-other-keys) |
46 | (find-class 'effective-attribute-definition-class)) |
47 | |
48 | (defmethod compute-effective-slot-definition |
49 | ((class description-access-class) name direct-slot-definitions) |
4867c86f |
50 | (declare (ignore name)) |
4358148e |
51 | (let ((attribute (call-next-method))) |
52 | (setf (attribute-direct-attributes attribute) direct-slot-definitions) |
f2ff8a16 |
53 | (setf (attribute-object-initargs attribute) |
54 | ;; This plist will be used to init the attribute object |
55 | ;; Once the description itself is properly initiated. |
56 | (list :name name |
57 | 'effective-attribute attribute |
58 | 'description-class class)) |
4358148e |
59 | attribute)) |
4867c86f |
60 | |
4358148e |
61 | |
62 | (defclass standard-description-class (description-access-class layered-class) |
4867c86f |
63 | () |
4358148e |
64 | (:default-initargs :defining-metaclass 'description-access-class)) |
65 | |
66 | (defmethod validate-superclass |
67 | ((class standard-description-class) |
68 | (superclass standard-class)) |
69 | t) |
70 | |
6de8d300 |
71 | (defclass standard-description-object (standard-layer-object) |
72 | ()) |
4358148e |
73 | |
74 | (defun description-class-name (description-class) |
75 | (read-from-string (symbol-name (class-name description-class)))) |
81d70610 |
76 | |
4867c86f |
77 | (defun initialize-description-class (class) |
4358148e |
78 | |
81d70610 |
79 | ;;; HACK: initialization does not happ en properly |
f2ff8a16 |
80 | ;;; when compiling and loading or something like that. |
81 | ;;; Obviously i'm not sure why. |
82 | ;;; So we're going to explicitly initialize things. |
83 | ;;; For now. --drewc |
4358148e |
84 | |
85 | (pushnew class *defined-descriptions*) |
6de8d300 |
86 | |
f2ff8a16 |
87 | ;;; ENDHACK. |
4358148e |
88 | |
89 | (let* ((description (find-layer class)) |
f2ff8a16 |
90 | (attribute-objects |
91 | (mapcar |
92 | (lambda (slot) |
93 | (setf (attribute-object slot) |
94 | (apply #'make-instance |
95 | 'standard-attribute |
96 | (attribute-object-initargs slot)))) |
97 | (class-slots (class-of description)))) |
4358148e |
98 | (defining-classes (partial-class-defining-classes (class-of description)))) |
4358148e |
99 | |
4358148e |
100 | (loop |
101 | :for (layer class) |
102 | :on defining-classes :by #'cddr |
103 | :do (funcall-with-layer-context |
104 | (adjoin-layer (find-layer layer) (current-layer-context)) |
f2ff8a16 |
105 | (lambda () |
106 | (loop :for direct-slot :in (class-direct-slots class) |
107 | :do (let ((attribute |
108 | (find (slot-definition-name direct-slot) |
109 | attribute-objects |
110 | :key #'attribute-name))) |
4271ab0b |
111 | (let ((initargs |
112 | (prepare-initargs attribute (direct-attribute-properties direct-slot)))) |
113 | |
114 | (apply #'reinitialize-instance attribute |
115 | initargs ) |
116 | (when (not (eq (find-class (attribute-class attribute)) |
117 | (class-of attribute))) |
81d70610 |
118 | |
119 | (apply #'change-class attribute (attribute-class attribute) |
4271ab0b |
120 | initargs))) |
81d70610 |
121 | |
f2ff8a16 |
122 | |
123 | (setf (slot-value description (attribute-name attribute)) |
124 | attribute)))))))) |
4358148e |
125 | |
126 | ;;;; HACK: run this at startup till we figure things out. |
127 | (defun initialize-descriptions () |
128 | (map nil #'initialize-description-class |
129 | (setf *defined-descriptions* |
130 | (remove-duplicates *defined-descriptions*)))) |
131 | |
132 | (defmethod initialize-instance :around ((class standard-description-class) &rest initargs &key (direct-superclasses '())) |
133 | (declare (dynamic-extent initargs)) |
134 | (prog1 |
135 | (if (loop for direct-superclass in direct-superclasses |
136 | thereis (ignore-errors (subtypep direct-superclass 'standard-description-object))) |
137 | (call-next-method) |
138 | (apply #'call-next-method |
139 | class |
140 | :direct-superclasses |
141 | (append direct-superclasses |
142 | (list (find-class 'standard-description-object))) |
143 | initargs)) |
144 | (initialize-description-class class))) |
145 | |
146 | |
147 | (defmethod reinitialize-instance :around ((class standard-description-class) &rest initargs &key (direct-superclasses '() direct-superclasses-p)) |
148 | (declare (dynamic-extent initargs)) |
149 | ; (warn "CLASS ~A ARGS ~A:" class initargs) |
150 | (prog1 |
151 | (if (or (not direct-superclasses-p) |
152 | (loop for direct-superclass in direct-superclasses |
153 | thereis (ignore-errors (subtypep direct-superclass 'standard-description-object)))) |
154 | (call-next-method) |
155 | (apply #'call-next-method |
156 | class |
157 | :direct-superclasses |
158 | (append direct-superclasses |
159 | (list (find-class 'standard-description-object))) |
160 | initargs)) |
161 | (initialize-description-class class))) |
162 | |
163 | |
164 | (defmethod print-object ((object standard-description-object) stream) |
165 | (print-unreadable-object (object stream :type nil :identity t) |
166 | (format stream "DESCRIPTION ~A" (ignore-errors (description-print-name object))))) |
167 | |
168 | (defmethod print-object ((object standard-description-class) stream) |
169 | (print-unreadable-object (object stream :type t :identity t) |
170 | (princ (ignore-errors (description-print-name (find-layer object))) stream))) |
171 | |
172 | (defun find-description (name) |
173 | (find-layer (find-class (defining-description name)))) |
174 | |
175 | |
176 | |
4867c86f |
177 | |
178 | |
179 | |