Update to CEDET 1.0's version of EIEIO.
[emacs.git] / lisp / emacs-lisp / eieio.el
blob97022f0acbe31d506f17a2e3f0f9675c22ed3e18
1 ;;; eieio.el --- Enhanced Implementation of Emacs Interpreted Objects
2 ;;; or maybe Eric's Implementation of Emacs Intrepreted Objects
4 ;; Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
7 ;; Author: Eric M. Ludlam <zappo@gnu.org>
8 ;; Version: 1.3
9 ;; Keywords: OO, lisp
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;; Commentary:
28 ;; EIEIO is a series of Lisp routines which implements a subset of
29 ;; CLOS, the Common Lisp Object System. In addition, EIEIO also adds
30 ;; a few new features which help it integrate more strongly with the
31 ;; Emacs running environment.
33 ;; See eieio.texi for complete documentation on using this package.
35 ;; Note: the implementation of the c3 algorithm is based on:
36 ;; Kim Barrett et al.: A Monotonic Superclass Linearization for Dylan
37 ;; Retrieved from:
38 ;; http://192.220.96.201/dylan/linearization-oopsla96.html
40 ;; There is funny stuff going on with typep and deftype. This
41 ;; is the only way I seem to be able to make this stuff load properly.
43 ;; @TODO - fix :initform to be a form, not a quoted value
44 ;; @TODO - Prefix non-clos functions with `eieio-'.
46 ;;; Code:
48 (eval-when-compile
49 (require 'cl)
50 (require 'eieio-comp))
52 (defvar eieio-version "1.3"
53 "Current version of EIEIO.")
55 (defun eieio-version ()
56 "Display the current version of EIEIO."
57 (interactive)
58 (message eieio-version))
60 (eval-and-compile
61 ;; About the above. EIEIO must process its own code when it compiles
62 ;; itself, thus, by eval-and-compiling outselves, we solve the problem.
64 ;; Compatibility
65 (if (fboundp 'compiled-function-arglist)
67 ;; XEmacs can only access a compiled functions arglist like this:
68 (defalias 'eieio-compiled-function-arglist 'compiled-function-arglist)
70 ;; Emacs doesn't have this function, but since FUNC is a vector, we can just
71 ;; grab the appropriate element.
72 (defun eieio-compiled-function-arglist (func)
73 "Return the argument list for the compiled function FUNC."
74 (aref func 0))
79 ;;;
80 ;; Variable declarations.
83 (defvar eieio-hook nil
84 "*This hook is executed, then cleared each time `defclass' is called.")
86 (defvar eieio-error-unsupported-class-tags nil
87 "Non-nil to throw an error if an encountered tag is unsupported.
88 This may prevent classes from CLOS applications from being used with EIEIO
89 since EIEIO does not support all CLOS tags.")
91 (defvar eieio-skip-typecheck nil
92 "*If non-nil, skip all slot typechecking.
93 Set this to t permanently if a program is functioning well to get a
94 small speed increase. This variable is also used internally to handle
95 default setting for optimization purposes.")
97 (defvar eieio-optimize-primary-methods-flag t
98 "Non-nil means to optimize the method dispatch on primary methods.")
100 ;; State Variables
101 (defvar this nil
102 "Inside a method, this variable is the object in question.
103 DO NOT SET THIS YOURSELF unless you are trying to simulate friendly slots.
105 Note: Embedded methods are no longer supported. The variable THIS is
106 still set for CLOS methods for the sake of routines like
107 `call-next-method'.")
109 (defvar scoped-class nil
110 "This is set to a class when a method is running.
111 This is so we know we are allowed to check private parts or how to
112 execute a `call-next-method'. DO NOT SET THIS YOURSELF!")
114 (defvar eieio-initializing-object nil
115 "Set to non-nil while initializing an object.")
117 (defconst eieio-unbound
118 (if (and (boundp 'eieio-unbound) (symbolp eieio-unbound))
119 eieio-unbound
120 (make-symbol "unbound"))
121 "Uninterned symbol representing an unbound slot in an object.")
123 ;; This is a bootstrap for eieio-default-superclass so it has a value
124 ;; while it is being built itself.
125 (defvar eieio-default-superclass nil)
127 (defconst class-symbol 1 "Class's symbol (self-referencing.).")
128 (defconst class-parent 2 "Class parent slot.")
129 (defconst class-children 3 "Class children class slot.")
130 (defconst class-symbol-obarray 4 "Obarray permitting fast access to variable position indexes.")
131 ;; @todo
132 ;; the word "public" here is leftovers from the very first version.
133 ;; Get rid of it!
134 (defconst class-public-a 5 "Class attribute index.")
135 (defconst class-public-d 6 "Class attribute defaults index.")
136 (defconst class-public-doc 7 "Class documentation strings for attributes.")
137 (defconst class-public-type 8 "Class type for a slot.")
138 (defconst class-public-custom 9 "Class custom type for a slot.")
139 (defconst class-public-custom-label 10 "Class custom group for a slot.")
140 (defconst class-public-custom-group 11 "Class custom group for a slot.")
141 (defconst class-public-printer 12 "Printer for a slot.")
142 (defconst class-protection 13 "Class protection for a slot.")
143 (defconst class-initarg-tuples 14 "Class initarg tuples list.")
144 (defconst class-class-allocation-a 15 "Class allocated attributes.")
145 (defconst class-class-allocation-doc 16 "Class allocated documentation.")
146 (defconst class-class-allocation-type 17 "Class allocated value type.")
147 (defconst class-class-allocation-custom 18 "Class allocated custom descriptor.")
148 (defconst class-class-allocation-custom-label 19 "Class allocated custom descriptor.")
149 (defconst class-class-allocation-custom-group 20 "Class allocated custom group.")
150 (defconst class-class-allocation-printer 21 "Class allocated printer for a slot.")
151 (defconst class-class-allocation-protection 22 "Class allocated protection list.")
152 (defconst class-class-allocation-values 23 "Class allocated value vector.")
153 (defconst class-default-object-cache 24
154 "Cache index of what a newly created object would look like.
155 This will speed up instantiation time as only a `copy-sequence' will
156 be needed, instead of looping over all the values and setting them
157 from the default.")
158 (defconst class-options 25
159 "Storage location of tagged class options.
160 Stored outright without modifications or stripping.")
162 (defconst class-num-slots 26
163 "Number of slots in the class definition object.")
165 (defconst object-class 1 "Index in an object vector where the class is stored.")
166 (defconst object-name 2 "Index in an object where the name is stored.")
168 (defconst method-static 0 "Index into :static tag on a method.")
169 (defconst method-before 1 "Index into :before tag on a method.")
170 (defconst method-primary 2 "Index into :primary tag on a method.")
171 (defconst method-after 3 "Index into :after tag on a method.")
172 (defconst method-num-lists 4 "Number of indexes into methods vector in which groups of functions are kept.")
173 (defconst method-generic-before 4 "Index into generic :before tag on a method.")
174 (defconst method-generic-primary 5 "Index into generic :primary tag on a method.")
175 (defconst method-generic-after 6 "Index into generic :after tag on a method.")
176 (defconst method-num-slots 7 "Number of indexes into a method's vector.")
178 (defsubst eieio-specialized-key-to-generic-key (key)
179 "Convert a specialized KEY into a generic method key."
180 (cond ((eq key method-static) 0) ;; don't convert
181 ((< key method-num-lists) (+ key 3)) ;; The conversion
182 (t key) ;; already generic.. maybe.
185 ;; How to specialty compile stuff.
186 (autoload 'byte-compile-file-form-defmethod "eieio-comp"
187 "This function is used to byte compile methods in a nice way.")
188 (put 'defmethod 'byte-hunk-handler 'byte-compile-file-form-defmethod)
190 ;;; Important macros used in eieio.
192 (defmacro class-v (class)
193 "Internal: Return the class vector from the CLASS symbol."
194 ;; No check: If eieio gets this far, it's probably been checked already.
195 `(get ,class 'eieio-class-definition))
197 (defmacro class-p (class)
198 "Return t if CLASS is a valid class vector.
199 CLASS is a symbol."
200 ;; this new method is faster since it doesn't waste time checking lots of
201 ;; things.
202 `(condition-case nil
203 (eq (aref (class-v ,class) 0) 'defclass)
204 (error nil)))
206 (defmacro eieio-object-p (obj)
207 "Return non-nil if OBJ is an EIEIO object."
208 `(condition-case nil
209 (let ((tobj ,obj))
210 (and (eq (aref tobj 0) 'object)
211 (class-p (aref tobj object-class))))
212 (error nil)))
213 (defalias 'object-p 'eieio-object-p)
215 (defmacro class-constructor (class)
216 "Return the symbol representing the constructor of CLASS."
217 `(aref (class-v ,class) class-symbol))
219 (defmacro generic-p (method)
220 "Return t if symbol METHOD is a generic function.
221 Only methods have the symbol `eieio-method-obarray' as a property
222 \(which contains a list of all bindings to that method type.)"
223 `(and (fboundp ,method) (get ,method 'eieio-method-obarray)))
225 (defun generic-primary-only-p (method)
226 "Return t if symbol METHOD is a generic function with only primary methods.
227 Only methods have the symbol `eieio-method-obarray' as a property (which
228 contains a list of all bindings to that method type.)
229 Methods with only primary implementations are executed in an optimized way."
230 (and (generic-p method)
231 (let ((M (get method 'eieio-method-tree)))
232 (and (< 0 (length (aref M method-primary)))
233 (not (aref M method-static))
234 (not (aref M method-before))
235 (not (aref M method-after))
236 (not (aref M method-generic-before))
237 (not (aref M method-generic-primary))
238 (not (aref M method-generic-after))))
241 (defun generic-primary-only-one-p (method)
242 "Return t if symbol METHOD is a generic function with only primary methods.
243 Only methods have the symbol `eieio-method-obarray' as a property (which
244 contains a list of all bindings to that method type.)
245 Methods with only primary implementations are executed in an optimized way."
246 (and (generic-p method)
247 (let ((M (get method 'eieio-method-tree)))
248 (and (= 1 (length (aref M method-primary)))
249 (not (aref M method-static))
250 (not (aref M method-before))
251 (not (aref M method-after))
252 (not (aref M method-generic-before))
253 (not (aref M method-generic-primary))
254 (not (aref M method-generic-after))))
257 (defmacro class-option-assoc (list option)
258 "Return from LIST the found OPTION, or nil if it doesn't exist."
259 `(car-safe (cdr (memq ,option ,list))))
261 (defmacro class-option (class option)
262 "Return the value stored for CLASS' OPTION.
263 Return nil if that option doesn't exist."
264 `(class-option-assoc (aref (class-v ,class) class-options) ',option))
266 (defmacro class-abstract-p (class)
267 "Return non-nil if CLASS is abstract.
268 Abstract classes cannot be instantiated."
269 `(class-option ,class :abstract))
271 (defmacro class-method-invocation-order (class)
272 "Return the invocation order of CLASS.
273 Abstract classes cannot be instantiated."
274 `(or (class-option ,class :method-invocation-order)
275 :breadth-first))
278 ;;; Defining a new class
280 (defmacro defclass (name superclass slots &rest options-and-doc)
281 "Define NAME as a new class derived from SUPERCLASS with SLOTS.
282 OPTIONS-AND-DOC is used as the class' options and base documentation.
283 SUPERCLASS is a list of superclasses to inherit from, with SLOTS
284 being the slots residing in that class definition. NOTE: Currently
285 only one slot may exist in SUPERCLASS as multiple inheritance is not
286 yet supported. Supported tags are:
288 :initform - Initializing form.
289 :initarg - Tag used during initialization.
290 :accessor - Tag used to create a function to access this slot.
291 :allocation - Specify where the value is stored.
292 Defaults to `:instance', but could also be `:class'.
293 :writer - A function symbol which will `write' an object's slot.
294 :reader - A function symbol which will `read' an object.
295 :type - The type of data allowed in this slot (see `typep').
296 :documentation
297 - A string documenting use of this slot.
299 The following are extensions on CLOS:
300 :protection - Specify protection for this slot.
301 Defaults to `:public'. Also use `:protected', or `:private'.
302 :custom - When customizing an object, the custom :type. Public only.
303 :label - A text string label used for a slot when customizing.
304 :group - Name of a customization group this slot belongs in.
305 :printer - A function to call to print the value of a slot.
306 See `eieio-override-prin1' as an example.
308 A class can also have optional options. These options happen in place
309 of documentation (including a :documentation tag), in addition to
310 documentation, or not at all. Supported options are:
312 :documentation - The doc-string used for this class.
314 Options added to EIEIO:
316 :allow-nil-initform - Non-nil to skip typechecking of null initforms.
317 :custom-groups - List of custom group names. Organizes slots into
318 reasonable groups for customizations.
319 :abstract - Non-nil to prevent instances of this class.
320 If a string, use as an error string if someone does
321 try to make an instance.
322 :method-invocation-order
323 - Control the method invocation order if there is
324 multiple inheritance. Valid values are:
325 :breadth-first - The default.
326 :depth-first
328 Options in CLOS not supported in EIEIO:
330 :metaclass - Class to use in place of `standard-class'
331 :default-initargs - Initargs to use when initializing new objects of
332 this class.
334 Due to the way class options are set up, you can add any tags you wish,
335 and reference them using the function `class-option'."
336 ;; We must `eval-and-compile' this so that when we byte compile
337 ;; an eieio program, there is no need to load it ahead of time.
338 ;; It also provides lots of nice debugging errors at compile time.
339 `(eval-and-compile
340 (eieio-defclass ',name ',superclass ',slots ',options-and-doc)))
342 (defvar eieio-defclass-autoload-map (make-vector 7 nil)
343 "Symbol map of superclasses we find in autoloads.")
345 ;; We autoload this because it's used in `make-autoload'.
346 ;;;###autoload
347 (defun eieio-defclass-autoload (cname superclasses filename doc)
348 "Create autoload symbols for the EIEIO class CNAME.
349 SUPERCLASSES are the superclasses that CNAME inherits from.
350 DOC is the docstring for CNAME.
351 This function creates a mock-class for CNAME and adds it into
352 SUPERCLASSES as children.
353 It creates an autoload function for CNAME's constructor."
354 ;; Assume we've already debugged inputs.
356 (let* ((oldc (when (class-p cname) (class-v cname)))
357 (newc (make-vector class-num-slots nil))
359 (if oldc
360 nil ;; Do nothing if we already have this class.
362 ;; Create the class in NEWC, but don't fill anything else in.
363 (aset newc 0 'defclass)
364 (aset newc class-symbol cname)
366 (let ((clear-parent nil))
367 ;; No parents?
368 (when (not superclasses)
369 (setq superclasses '(eieio-default-superclass)
370 clear-parent t)
373 ;; Hook our new class into the existing structures so we can
374 ;; autoload it later.
375 (dolist (SC superclasses)
378 ;; TODO - If we create an autoload that is in the map, that
379 ;; map needs to be cleared!
382 ;; Does our parent exist?
383 (if (not (class-p SC))
385 ;; Create a symbol for this parent, and then store this
386 ;; parent on that symbol.
387 (let ((sym (intern (symbol-name SC) eieio-defclass-autoload-map)))
388 (if (not (boundp sym))
389 (set sym (list cname))
390 (add-to-list sym cname))
393 ;; We have a parent, save the child in there.
394 (when (not (member cname (aref (class-v SC) class-children)))
395 (aset (class-v SC) class-children
396 (cons cname (aref (class-v SC) class-children)))))
398 ;; save parent in child
399 (aset newc class-parent (cons SC (aref newc class-parent)))
402 ;; turn this into a useable self-pointing symbol
403 (set cname cname)
405 ;; Store the new class vector definition into the symbol. We need to
406 ;; do this first so that we can call defmethod for the accessor.
407 ;; The vector will be updated by the following while loop and will not
408 ;; need to be stored a second time.
409 (put cname 'eieio-class-definition newc)
411 ;; Clear the parent
412 (if clear-parent (aset newc class-parent nil))
414 ;; Create an autoload on top of our constructor function.
415 (autoload cname filename doc nil nil)
416 (autoload (intern (concat (symbol-name cname) "-p")) filename "" nil nil)
417 (autoload (intern (concat (symbol-name cname) "-child-p")) filename "" nil nil)
419 ))))
421 (defsubst eieio-class-un-autoload (cname)
422 "If class CNAME is in an autoload state, load its file."
423 (when (eq (car-safe (symbol-function cname)) 'autoload)
424 (load-library (car (cdr (symbol-function cname))))))
426 (defun eieio-defclass (cname superclasses slots options-and-doc)
427 "Define CNAME as a new subclass of SUPERCLASSES.
428 SLOTS are the slots residing in that class definition, and options or
429 documentation OPTIONS-AND-DOC is the toplevel documentation for this class.
430 See `defclass' for more information."
431 ;; Run our eieio-hook each time, and clear it when we are done.
432 ;; This way people can add hooks safely if they want to modify eieio
433 ;; or add definitions when eieio is loaded or something like that.
434 (run-hooks 'eieio-hook)
435 (setq eieio-hook nil)
437 (if (not (symbolp cname)) (signal 'wrong-type-argument '(symbolp cname)))
438 (if (not (listp superclasses)) (signal 'wrong-type-argument '(listp superclasses)))
440 (let* ((pname (if superclasses superclasses nil))
441 (newc (make-vector class-num-slots nil))
442 (oldc (when (class-p cname) (class-v cname)))
443 (groups nil) ;; list of groups id'd from slots
444 (options nil)
445 (clearparent nil))
447 (aset newc 0 'defclass)
448 (aset newc class-symbol cname)
450 ;; If this class already existed, and we are updating its structure,
451 ;; make sure we keep the old child list. This can cause bugs, but
452 ;; if no new slots are created, it also saves time, and prevents
453 ;; method table breakage, particularly when the users is only
454 ;; byte compiling an EIEIO file.
455 (if oldc
456 (aset newc class-children (aref oldc class-children))
457 ;; If the old class did not exist, but did exist in the autoload map, then adopt those children.
458 ;; This is like the above, but deals with autoloads nicely.
459 (let ((sym (intern-soft (symbol-name cname) eieio-defclass-autoload-map)))
460 (when sym
461 (condition-case nil
462 (aset newc class-children (symbol-value sym))
463 (error nil))
464 (unintern (symbol-name cname) eieio-defclass-autoload-map)
468 (cond ((and (stringp (car options-and-doc))
469 (/= 1 (% (length options-and-doc) 2)))
470 (error "Too many arguments to `defclass'"))
471 ((and (symbolp (car options-and-doc))
472 (/= 0 (% (length options-and-doc) 2)))
473 (error "Too many arguments to `defclass'"))
476 (setq options
477 (if (stringp (car options-and-doc))
478 (cons :documentation options-and-doc)
479 options-and-doc))
481 (if pname
482 (progn
483 (while pname
484 (if (and (car pname) (symbolp (car pname)))
485 (if (not (class-p (car pname)))
486 ;; bad class
487 (error "Given parent class %s is not a class" (car pname))
488 ;; good parent class...
489 ;; save new child in parent
490 (when (not (member cname (aref (class-v (car pname)) class-children)))
491 (aset (class-v (car pname)) class-children
492 (cons cname (aref (class-v (car pname)) class-children))))
493 ;; Get custom groups, and store them into our local copy.
494 (mapc (lambda (g) (add-to-list 'groups g))
495 (class-option (car pname) :custom-groups))
496 ;; save parent in child
497 (aset newc class-parent (cons (car pname) (aref newc class-parent))))
498 (error "Invalid parent class %s" pname))
499 (setq pname (cdr pname)))
500 ;; Reverse the list of our parents so that they are prioritized in
501 ;; the same order as specified in the code.
502 (aset newc class-parent (nreverse (aref newc class-parent))) )
503 ;; If there is nothing to loop over, then inherit from the
504 ;; default superclass.
505 (unless (eq cname 'eieio-default-superclass)
506 ;; adopt the default parent here, but clear it later...
507 (setq clearparent t)
508 ;; save new child in parent
509 (if (not (member cname (aref (class-v 'eieio-default-superclass) class-children)))
510 (aset (class-v 'eieio-default-superclass) class-children
511 (cons cname (aref (class-v 'eieio-default-superclass) class-children))))
512 ;; save parent in child
513 (aset newc class-parent (list eieio-default-superclass))))
515 ;; turn this into a useable self-pointing symbol
516 (set cname cname)
518 ;; These two tests must be created right away so we can have self-
519 ;; referencing classes. ei, a class whose slot can contain only
520 ;; pointers to itself.
522 ;; Create the test function
523 (let ((csym (intern (concat (symbol-name cname) "-p"))))
524 (fset csym
525 (list 'lambda (list 'obj)
526 (format "Test OBJ to see if it an object of type %s" cname)
527 (list 'and '(eieio-object-p obj)
528 (list 'same-class-p 'obj cname)))))
530 ;; Make sure the method invocation order is a valid value.
531 (let ((io (class-option-assoc options :method-invocation-order)))
532 (when (and io (not (member io '(:depth-first :breadth-first :c3))))
533 (error "Method invocation order %s is not allowed" io)
536 ;; Create a handy child test too
537 (let ((csym (intern (concat (symbol-name cname) "-child-p"))))
538 (fset csym
539 `(lambda (obj)
540 ,(format
541 "Test OBJ to see if it an object is a child of type %s"
542 cname)
543 (and (eieio-object-p obj)
544 (object-of-class-p obj ,cname))))
546 ;; When using typep, (typep OBJ 'myclass) returns t for objects which
547 ;; are subclasses of myclass. For our predicates, however, it is
548 ;; important for EIEIO to be backwards compatible, where
549 ;; myobject-p, and myobject-child-p are different.
550 ;; "cl" uses this technique to specify symbols with specific typep
551 ;; test, so we can let typep have the CLOS documented behavior
552 ;; while keeping our above predicate clean.
554 ;; It would be cleaner to use `defsetf' here, but that requires cl
555 ;; at runtime.
556 (put cname 'cl-deftype-handler
557 (list 'lambda () `(list 'satisfies (quote ,csym)))))
559 ;; before adding new slots, lets add all the methods and classes
560 ;; in from the parent class
561 (eieio-copy-parents-into-subclass newc superclasses)
563 ;; Store the new class vector definition into the symbol. We need to
564 ;; do this first so that we can call defmethod for the accessor.
565 ;; The vector will be updated by the following while loop and will not
566 ;; need to be stored a second time.
567 (put cname 'eieio-class-definition newc)
569 ;; Query each slot in the declaration list and mangle into the
570 ;; class structure I have defined.
571 (while slots
572 (let* ((slot1 (car slots))
573 (name (car slot1))
574 (slot (cdr slot1))
575 (acces (plist-get slot ':accessor))
576 (init (or (plist-get slot ':initform)
577 (if (member ':initform slot) nil
578 eieio-unbound)))
579 (initarg (plist-get slot ':initarg))
580 (docstr (plist-get slot ':documentation))
581 (prot (plist-get slot ':protection))
582 (reader (plist-get slot ':reader))
583 (writer (plist-get slot ':writer))
584 (alloc (plist-get slot ':allocation))
585 (type (plist-get slot ':type))
586 (custom (plist-get slot ':custom))
587 (label (plist-get slot ':label))
588 (customg (plist-get slot ':group))
589 (printer (plist-get slot ':printer))
591 (skip-nil (class-option-assoc options :allow-nil-initform))
594 (if eieio-error-unsupported-class-tags
595 (let ((tmp slot))
596 (while tmp
597 (if (not (member (car tmp) '(:accessor
598 :initform
599 :initarg
600 :documentation
601 :protection
602 :reader
603 :writer
604 :allocation
605 :type
606 :custom
607 :label
608 :group
609 :printer
610 :allow-nil-initform
611 :custom-groups)))
612 (signal 'invalid-slot-type (list (car tmp))))
613 (setq tmp (cdr (cdr tmp))))))
615 ;; Clean up the meaning of protection.
616 (cond ((or (eq prot 'public) (eq prot :public)) (setq prot nil))
617 ((or (eq prot 'protected) (eq prot :protected)) (setq prot 'protected))
618 ((or (eq prot 'private) (eq prot :private)) (setq prot 'private))
619 ((eq prot nil) nil)
620 (t (signal 'invalid-slot-type (list ':protection prot))))
622 ;; Make sure the :allocation parameter has a valid value.
623 (if (not (or (not alloc) (eq alloc :class) (eq alloc :instance)))
624 (signal 'invalid-slot-type (list ':allocation alloc)))
626 ;; The default type specifier is supposed to be t, meaning anything.
627 (if (not type) (setq type t))
629 ;; Label is nil, or a string
630 (if (not (or (null label) (stringp label)))
631 (signal 'invalid-slot-type (list ':label label)))
633 ;; Is there an initarg, but allocation of class?
634 (if (and initarg (eq alloc :class))
635 (message "Class allocated slots do not need :initarg"))
637 ;; intern the symbol so we can use it blankly
638 (if initarg (set initarg initarg))
640 ;; The customgroup should be a list of symbols
641 (cond ((null customg)
642 (setq customg '(default)))
643 ((not (listp customg))
644 (setq customg (list customg))))
645 ;; The customgroup better be a symbol, or list of symbols.
646 (mapc (lambda (cg)
647 (if (not (symbolp cg))
648 (signal 'invalid-slot-type (list ':group cg))))
649 customg)
651 ;; First up, add this slot into our new class.
652 (eieio-add-new-slot newc name init docstr type custom label customg printer
653 prot initarg alloc 'defaultoverride skip-nil)
655 ;; We need to id the group, and store them in a group list attribute.
656 (mapc (lambda (cg) (add-to-list 'groups cg)) customg)
658 ;; anyone can have an accessor function. This creates a function
659 ;; of the specified name, and also performs a `defsetf' if applicable
660 ;; so that users can `setf' the space returned by this function
661 (if acces
662 (progn
663 (eieio-defmethod acces
664 (list (if (eq alloc :class) :static :primary)
665 (list (list 'this cname))
666 (format
667 "Retrieves the slot `%s' from an object of class `%s'"
668 name cname)
669 (list 'if (list 'slot-boundp 'this (list 'quote name))
670 (list 'eieio-oref 'this (list 'quote name))
671 ;; Else - Some error? nil?
672 nil)))
674 ;; Provide a setf method. It would be cleaner to use
675 ;; defsetf, but that would require CL at runtime.
676 (put acces 'setf-method
677 `(lambda (widget)
678 (let* ((--widget-sym-- (make-symbol "--widget--"))
679 (--store-sym-- (make-symbol "--store--")))
680 (list
681 (list --widget-sym--)
682 (list widget)
683 (list --store-sym--)
684 (list 'eieio-oset --widget-sym-- '',name --store-sym--)
685 (list 'getfoo --widget-sym--)))))))
687 ;; If a writer is defined, then create a generic method of that
688 ;; name whose purpose is to set the value of the slot.
689 (if writer
690 (progn
691 (eieio-defmethod writer
692 (list (list (list 'this cname) 'value)
693 (format "Set the slot `%s' of an object of class `%s'"
694 name cname)
695 `(setf (slot-value this ',name) value)))
697 ;; If a reader is defined, then create a generic method
698 ;; of that name whose purpose is to access this slot value.
699 (if reader
700 (progn
701 (eieio-defmethod reader
702 (list (list (list 'this cname))
703 (format "Access the slot `%s' from object of class `%s'"
704 name cname)
705 `(slot-value this ',name)))))
707 (setq slots (cdr slots)))
709 ;; Now that everything has been loaded up, all our lists are backwards! Fix that up now.
710 (aset newc class-public-a (nreverse (aref newc class-public-a)))
711 (aset newc class-public-d (nreverse (aref newc class-public-d)))
712 (aset newc class-public-doc (nreverse (aref newc class-public-doc)))
713 (aset newc class-public-type
714 (apply 'vector (nreverse (aref newc class-public-type))))
715 (aset newc class-public-custom (nreverse (aref newc class-public-custom)))
716 (aset newc class-public-custom-label (nreverse (aref newc class-public-custom-label)))
717 (aset newc class-public-custom-group (nreverse (aref newc class-public-custom-group)))
718 (aset newc class-public-printer (nreverse (aref newc class-public-printer)))
719 (aset newc class-protection (nreverse (aref newc class-protection)))
720 (aset newc class-initarg-tuples (nreverse (aref newc class-initarg-tuples)))
722 ;; The storage for class-class-allocation-type needs to be turned into
723 ;; a vector now.
724 (aset newc class-class-allocation-type
725 (apply 'vector (aref newc class-class-allocation-type)))
727 ;; Also, take class allocated values, and vectorize them for speed.
728 (aset newc class-class-allocation-values
729 (apply 'vector (aref newc class-class-allocation-values)))
731 ;; Attach slot symbols into an obarray, and store the index of
732 ;; this slot as the variable slot in this new symbol. We need to
733 ;; know about primes, because obarrays are best set in vectors of
734 ;; prime number length, and we also need to make our vector small
735 ;; to save space, and also optimal for the number of items we have.
736 (let* ((cnt 0)
737 (pubsyms (aref newc class-public-a))
738 (prots (aref newc class-protection))
739 (l (length pubsyms))
740 (vl (let ((primes '( 3 5 7 11 13 17 19 23 29 31 37 41 43 47
741 53 59 61 67 71 73 79 83 89 97 101 )))
742 (while (and primes (< (car primes) l))
743 (setq primes (cdr primes)))
744 (car primes)))
745 (oa (make-vector vl 0))
746 (newsym))
747 (while pubsyms
748 (setq newsym (intern (symbol-name (car pubsyms)) oa))
749 (set newsym cnt)
750 (setq cnt (1+ cnt))
751 (if (car prots) (put newsym 'protection (car prots)))
752 (setq pubsyms (cdr pubsyms)
753 prots (cdr prots)))
754 (aset newc class-symbol-obarray oa)
757 ;; Create the constructor function
758 (if (class-option-assoc options :abstract)
759 ;; Abstract classes cannot be instantiated. Say so.
760 (let ((abs (class-option-assoc options :abstract)))
761 (if (not (stringp abs))
762 (setq abs (format "Class %s is abstract" cname)))
763 (fset cname
764 `(lambda (&rest stuff)
765 ,(format "You cannot create a new object of type %s" cname)
766 (error ,abs))))
768 ;; Non-abstract classes need a constructor.
769 (fset cname
770 `(lambda (newname &rest slots)
771 ,(format "Create a new object with name NAME of class type %s" cname)
772 (apply 'constructor ,cname newname slots)))
775 ;; Set up a specialized doc string.
776 ;; Use stored value since it is calculated in a non-trivial way
777 (put cname 'variable-documentation
778 (class-option-assoc options :documentation))
780 ;; We have a list of custom groups. Store them into the options.
781 (let ((g (class-option-assoc options :custom-groups)))
782 (mapc (lambda (cg) (add-to-list 'g cg)) groups)
783 (if (memq :custom-groups options)
784 (setcar (cdr (memq :custom-groups options)) g)
785 (setq options (cons :custom-groups (cons g options)))))
787 ;; Set up the options we have collected.
788 (aset newc class-options options)
790 ;; if this is a superclass, clear out parent (which was set to the
791 ;; default superclass eieio-default-superclass)
792 (if clearparent (aset newc class-parent nil))
794 ;; Create the cached default object.
795 (let ((cache (make-vector (+ (length (aref newc class-public-a))
796 3) nil)))
797 (aset cache 0 'object)
798 (aset cache object-class cname)
799 (aset cache object-name 'default-cache-object)
800 (let ((eieio-skip-typecheck t))
801 ;; All type-checking has been done to our satisfaction
802 ;; before this call. Don't waste our time in this call..
803 (eieio-set-defaults cache t))
804 (aset newc class-default-object-cache cache))
806 ;; Return our new class object
807 ;; newc
808 cname
811 (defun eieio-perform-slot-validation-for-default (slot spec value skipnil)
812 "For SLOT, signal if SPEC does not match VALUE.
813 If SKIPNIL is non-nil, then if VALUE is nil return t instead."
814 (if (and (not (eieio-eval-default-p value))
815 (not eieio-skip-typecheck)
816 (not (and skipnil (null value)))
817 (not (eieio-perform-slot-validation spec value)))
818 (signal 'invalid-slot-type (list slot spec value))))
820 (defun eieio-add-new-slot (newc a d doc type cust label custg print prot init alloc
821 &optional defaultoverride skipnil)
822 "Add into NEWC attribute A.
823 If A already exists in NEWC, then do nothing. If it doesn't exist,
824 then also add in D (default), DOC, TYPE, CUST, LABEL, CUSTG, PRINT, PROT, and INIT arg.
825 Argument ALLOC specifies if the slot is allocated per instance, or per class.
826 If optional DEFAULTOVERRIDE is non-nil, then if A exists in NEWC,
827 we must override its value for a default.
828 Optional argument SKIPNIL indicates if type checking should be skipped
829 if default value is nil."
830 ;; Make sure we duplicate those items that are sequences.
831 (condition-case nil
832 (if (sequencep d) (setq d (copy-sequence d)))
833 ;; This copy can fail on a cons cell with a non-cons in the cdr. Lets skip it if it doesn't work.
834 (error nil))
835 (if (sequencep type) (setq type (copy-sequence type)))
836 (if (sequencep cust) (setq cust (copy-sequence cust)))
837 (if (sequencep custg) (setq custg (copy-sequence custg)))
839 ;; To prevent override information w/out specification of storage,
840 ;; we need to do this little hack.
841 (if (member a (aref newc class-class-allocation-a)) (setq alloc ':class))
843 (if (or (not alloc) (and (symbolp alloc) (eq alloc ':instance)))
844 ;; In this case, we modify the INSTANCE version of a given slot.
846 (progn
848 ;; Only add this element if it is so-far unique
849 (if (not (member a (aref newc class-public-a)))
850 (progn
851 (eieio-perform-slot-validation-for-default a type d skipnil)
852 (aset newc class-public-a (cons a (aref newc class-public-a)))
853 (aset newc class-public-d (cons d (aref newc class-public-d)))
854 (aset newc class-public-doc (cons doc (aref newc class-public-doc)))
855 (aset newc class-public-type (cons type (aref newc class-public-type)))
856 (aset newc class-public-custom (cons cust (aref newc class-public-custom)))
857 (aset newc class-public-custom-label (cons label (aref newc class-public-custom-label)))
858 (aset newc class-public-custom-group (cons custg (aref newc class-public-custom-group)))
859 (aset newc class-public-printer (cons print (aref newc class-public-printer)))
860 (aset newc class-protection (cons prot (aref newc class-protection)))
861 (aset newc class-initarg-tuples (cons (cons init a) (aref newc class-initarg-tuples)))
863 ;; When defaultoverride is true, we are usually adding new local
864 ;; attributes which must override the default value of any slot
865 ;; passed in by one of the parent classes.
866 (when defaultoverride
867 ;; There is a match, and we must override the old value.
868 (let* ((ca (aref newc class-public-a))
869 (np (member a ca))
870 (num (- (length ca) (length np)))
871 (dp (if np (nthcdr num (aref newc class-public-d))
872 nil))
873 (tp (if np (nth num (aref newc class-public-type))))
875 (if (not np)
876 (error "EIEIO internal error overriding default value for %s"
878 ;; If type is passed in, is it the same?
879 (if (not (eq type t))
880 (if (not (equal type tp))
881 (error
882 "Child slot type `%s' does not match inherited type `%s' for `%s'"
883 type tp a)))
884 ;; If we have a repeat, only update the initarg...
885 (unless (eq d eieio-unbound)
886 (eieio-perform-slot-validation-for-default a tp d skipnil)
887 (setcar dp d))
888 ;; If we have a new initarg, check for it.
889 (when init
890 (let* ((inits (aref newc class-initarg-tuples))
891 (inita (rassq a inits)))
892 ;; Replace the CAR of the associate INITA.
893 ;;(message "Initarg: %S replace %s" inita init)
894 (setcar inita init)
897 ;; PLN Tue Jun 26 11:57:06 2007 : The protection is
898 ;; checked and SHOULD match the superclass
899 ;; protection. Otherwise an error is thrown. However
900 ;; I wonder if a more flexible schedule might be
901 ;; implemented.
903 ;; EML - We used to have (if prot... here,
904 ;; but a prot of 'nil means public.
906 (let ((super-prot (nth num (aref newc class-protection)))
908 (if (not (eq prot super-prot))
909 (error "Child slot protection `%s' does not match inherited protection `%s' for `%s'"
910 prot super-prot a)))
911 ;; End original PLN
913 ;; PLN Tue Jun 26 11:57:06 2007 :
914 ;; Do a non redundant combination of ancient custom
915 ;; groups and new ones.
916 (when custg
917 (let* ((groups
918 (nthcdr num (aref newc class-public-custom-group)))
919 (list1 (car groups))
920 (list2 (if (listp custg) custg (list custg))))
921 (if (< (length list1) (length list2))
922 (setq list1 (prog1 list2 (setq list2 list1))))
923 (dolist (elt list2)
924 (unless (memq elt list1)
925 (push elt list1)))
926 (setcar groups list1)))
927 ;; End PLN
929 ;; PLN Mon Jun 25 22:44:34 2007 : If a new cust is
930 ;; set, simply replaces the old one.
931 (when cust
932 ;; (message "Custom type redefined to %s" cust)
933 (setcar (nthcdr num (aref newc class-public-custom)) cust))
935 ;; If a new label is specified, it simply replaces
936 ;; the old one.
937 (when label
938 ;; (message "Custom label redefined to %s" label)
939 (setcar (nthcdr num (aref newc class-public-custom-label)) label))
940 ;; End PLN
942 ;; PLN Sat Jun 30 17:24:42 2007 : when a new
943 ;; doc is specified, simply replaces the old one.
944 (when doc
945 ;;(message "Documentation redefined to %s" doc)
946 (setcar (nthcdr num (aref newc class-public-doc))
947 doc))
948 ;; End PLN
950 ;; If a new printer is specified, it simply replaces
951 ;; the old one.
952 (when print
953 ;; (message "printer redefined to %s" print)
954 (setcar (nthcdr num (aref newc class-public-printer)) print))
959 ;; CLASS ALLOCATED SLOTS
960 (let ((value (eieio-default-eval-maybe d)))
961 (if (not (member a (aref newc class-class-allocation-a)))
962 (progn
963 (eieio-perform-slot-validation-for-default a type value skipnil)
964 ;; Here we have found a :class version of a slot. This
965 ;; requires a very different aproach.
966 (aset newc class-class-allocation-a (cons a (aref newc class-class-allocation-a)))
967 (aset newc class-class-allocation-doc (cons doc (aref newc class-class-allocation-doc)))
968 (aset newc class-class-allocation-type (cons type (aref newc class-class-allocation-type)))
969 (aset newc class-class-allocation-custom (cons cust (aref newc class-class-allocation-custom)))
970 (aset newc class-class-allocation-custom-label (cons label (aref newc class-class-allocation-custom-label)))
971 (aset newc class-class-allocation-custom-group (cons custg (aref newc class-class-allocation-custom-group)))
972 (aset newc class-class-allocation-protection (cons prot (aref newc class-class-allocation-protection)))
973 ;; Default value is stored in the 'values section, since new objects
974 ;; can't initialize from this element.
975 (aset newc class-class-allocation-values (cons value (aref newc class-class-allocation-values))))
976 (when defaultoverride
977 ;; There is a match, and we must override the old value.
978 (let* ((ca (aref newc class-class-allocation-a))
979 (np (member a ca))
980 (num (- (length ca) (length np)))
981 (dp (if np
982 (nthcdr num
983 (aref newc class-class-allocation-values))
984 nil))
985 (tp (if np (nth num (aref newc class-class-allocation-type))
986 nil)))
987 (if (not np)
988 (error "EIEIO internal error overriding default value for %s"
990 ;; If type is passed in, is it the same?
991 (if (not (eq type t))
992 (if (not (equal type tp))
993 (error
994 "Child slot type `%s' does not match inherited type `%s' for `%s'"
995 type tp a)))
996 ;; EML - Note: the only reason to override a class bound slot
997 ;; is to change the default, so allow unbound in.
999 ;; If we have a repeat, only update the vlaue...
1000 (eieio-perform-slot-validation-for-default a tp value skipnil)
1001 (setcar dp value))
1003 ;; PLN Tue Jun 26 11:57:06 2007 : The protection is
1004 ;; checked and SHOULD match the superclass
1005 ;; protection. Otherwise an error is thrown. However
1006 ;; I wonder if a more flexible schedule might be
1007 ;; implemented.
1008 (let ((super-prot
1009 (car (nthcdr num (aref newc class-class-allocation-protection)))))
1010 (if (not (eq prot super-prot))
1011 (error "Child slot protection `%s' does not match inherited protection `%s' for `%s'"
1012 prot super-prot a)))
1013 ;; Do a non redundant combination of ancient custom groups
1014 ;; and new ones.
1015 (when custg
1016 (let* ((groups
1017 (nthcdr num (aref newc class-class-allocation-custom-group)))
1018 (list1 (car groups))
1019 (list2 (if (listp custg) custg (list custg))))
1020 (if (< (length list1) (length list2))
1021 (setq list1 (prog1 list2 (setq list2 list1))))
1022 (dolist (elt list2)
1023 (unless (memq elt list1)
1024 (push elt list1)))
1025 (setcar groups list1)))
1027 ;; PLN Sat Jun 30 17:24:42 2007 : when a new
1028 ;; doc is specified, simply replaces the old one.
1029 (when doc
1030 ;;(message "Documentation redefined to %s" doc)
1031 (setcar (nthcdr num (aref newc class-class-allocation-doc))
1032 doc))
1033 ;; End PLN
1035 ;; If a new printer is specified, it simply replaces
1036 ;; the old one.
1037 (when print
1038 ;; (message "printer redefined to %s" print)
1039 (setcar (nthcdr num (aref newc class-class-allocation-printer)) print))
1045 (defun eieio-copy-parents-into-subclass (newc parents)
1046 "Copy into NEWC the slots of PARENTS.
1047 Follow the rules of not overwriting early parents when applying to
1048 the new child class."
1049 (let ((ps (aref newc class-parent))
1050 (sn (class-option-assoc (aref newc class-options)
1051 ':allow-nil-initform)))
1052 (while ps
1053 ;; First, duplicate all the slots of the parent.
1054 (let ((pcv (class-v (car ps))))
1055 (let ((pa (aref pcv class-public-a))
1056 (pd (aref pcv class-public-d))
1057 (pdoc (aref pcv class-public-doc))
1058 (ptype (aref pcv class-public-type))
1059 (pcust (aref pcv class-public-custom))
1060 (plabel (aref pcv class-public-custom-label))
1061 (pcustg (aref pcv class-public-custom-group))
1062 (printer (aref pcv class-public-printer))
1063 (pprot (aref pcv class-protection))
1064 (pinit (aref pcv class-initarg-tuples))
1065 (i 0))
1066 (while pa
1067 (eieio-add-new-slot newc
1068 (car pa) (car pd) (car pdoc) (aref ptype i)
1069 (car pcust) (car plabel) (car pcustg)
1070 (car printer)
1071 (car pprot) (car-safe (car pinit)) nil nil sn)
1072 ;; Increment each value.
1073 (setq pa (cdr pa)
1074 pd (cdr pd)
1075 pdoc (cdr pdoc)
1076 i (1+ i)
1077 pcust (cdr pcust)
1078 plabel (cdr plabel)
1079 pcustg (cdr pcustg)
1080 printer (cdr printer)
1081 pprot (cdr pprot)
1082 pinit (cdr pinit))
1083 )) ;; while/let
1084 ;; Now duplicate all the class alloc slots.
1085 (let ((pa (aref pcv class-class-allocation-a))
1086 (pdoc (aref pcv class-class-allocation-doc))
1087 (ptype (aref pcv class-class-allocation-type))
1088 (pcust (aref pcv class-class-allocation-custom))
1089 (plabel (aref pcv class-class-allocation-custom-label))
1090 (pcustg (aref pcv class-class-allocation-custom-group))
1091 (printer (aref pcv class-class-allocation-printer))
1092 (pprot (aref pcv class-class-allocation-protection))
1093 (pval (aref pcv class-class-allocation-values))
1094 (i 0))
1095 (while pa
1096 (eieio-add-new-slot newc
1097 (car pa) (aref pval i) (car pdoc) (aref ptype i)
1098 (car pcust) (car plabel) (car pcustg)
1099 (car printer)
1100 (car pprot) nil ':class sn)
1101 ;; Increment each value.
1102 (setq pa (cdr pa)
1103 pdoc (cdr pdoc)
1104 pcust (cdr pcust)
1105 plabel (cdr plabel)
1106 pcustg (cdr pcustg)
1107 printer (cdr printer)
1108 pprot (cdr pprot)
1109 i (1+ i))
1110 ))) ;; while/let
1111 ;; Loop over each parent class
1112 (setq ps (cdr ps)))
1115 ;;; CLOS style implementation of object creators.
1117 (defun make-instance (class &rest initargs)
1118 "Make a new instance of CLASS based on INITARGS.
1119 CLASS is a class symbol. For example:
1121 (make-instance 'foo)
1123 INITARGS is a property list with keywords based on the :initarg
1124 for each slot. For example:
1126 (make-instance 'foo :slot1 value1 :slotN valueN)
1128 Compatibility note:
1130 If the first element of INITARGS is a string, it is used as the
1131 name of the class.
1133 In EIEIO, the class' constructor requires a name for use when printing.
1134 `make-instance' in CLOS doesn't use names the way Emacs does, so the
1135 class is used as the name slot instead when INITARGS doesn't start with
1136 a string."
1137 (if (and (car initargs) (stringp (car initargs)))
1138 (apply (class-constructor class) initargs)
1139 (apply (class-constructor class)
1140 (cond ((symbolp class) (symbol-name class))
1141 (t (format "%S" class)))
1142 initargs)))
1145 ;;; CLOS methods and generics
1147 (defmacro defgeneric (method args &optional doc-string)
1148 "Create a generic function METHOD.
1149 DOC-STRING is the base documentation for this class. A generic
1150 function has no body, as its purpose is to decide which method body
1151 is appropriate to use. Uses `defmethod' to create methods, and calls
1152 `defgeneric' for you. With this implementation the ARGS are
1153 currently ignored. You can use `defgeneric' to apply specialized
1154 top level documentation to a method."
1155 `(eieio-defgeneric (quote ,method) ,doc-string))
1157 (defun eieio-defgeneric-form (method doc-string)
1158 "The lambda form that would be used as the function defined on METHOD.
1159 All methods should call the same EIEIO function for dispatch.
1160 DOC-STRING is the documentation attached to METHOD."
1161 `(lambda (&rest local-args)
1162 ,doc-string
1163 (eieio-generic-call (quote ,method) local-args)))
1165 (defsubst eieio-defgeneric-reset-generic-form (method)
1166 "Setup METHOD to call the generic form."
1167 (let ((doc-string (documentation method)))
1168 (fset method (eieio-defgeneric-form method doc-string))))
1170 (defun eieio-defgeneric-form-primary-only (method doc-string)
1171 "The lambda form that would be used as the function defined on METHOD.
1172 All methods should call the same EIEIO function for dispatch.
1173 DOC-STRING is the documentation attached to METHOD."
1174 `(lambda (&rest local-args)
1175 ,doc-string
1176 (eieio-generic-call-primary-only (quote ,method) local-args)))
1178 (defsubst eieio-defgeneric-reset-generic-form-primary-only (method)
1179 "Setup METHOD to call the generic form."
1180 (let ((doc-string (documentation method)))
1181 (fset method (eieio-defgeneric-form-primary-only method doc-string))))
1183 (defun eieio-defgeneric-form-primary-only-one (method doc-string
1184 class
1185 impl
1187 "The lambda form that would be used as the function defined on METHOD.
1188 All methods should call the same EIEIO function for dispatch.
1189 DOC-STRING is the documentation attached to METHOD.
1190 CLASS is the class symbol needed for private method access.
1191 IMPL is the symbol holding the method implementation."
1192 ;; NOTE: I tried out byte compiling this little fcn. Turns out it
1193 ;; is faster to execute this for not byte-compiled. ie, install this,
1194 ;; then measure calls going through here. I wonder why.
1195 (require 'bytecomp)
1196 (let ((byte-compile-free-references nil)
1197 (byte-compile-warnings nil)
1199 (byte-compile-lambda
1200 `(lambda (&rest local-args)
1201 ,doc-string
1202 ;; This is a cool cheat. Usually we need to look up in the
1203 ;; method table to find out if there is a method or not. We can
1204 ;; instead make that determination at load time when there is
1205 ;; only one method. If the first arg is not a child of the class
1206 ;; of that one implementation, then clearly, there is no method def.
1207 (if (not (eieio-object-p (car local-args)))
1208 ;; Not an object. Just signal.
1209 (signal 'no-method-definition (list ,(list 'quote method) local-args))
1211 ;; We do have an object. Make sure it is the right type.
1212 (if ,(if (eq class eieio-default-superclass)
1213 nil ; default superclass means just an obj. Already asked.
1214 `(not (child-of-class-p (aref (car local-args) object-class)
1215 ,(list 'quote class)))
1218 ;; If not the right kind of object, call no applicable
1219 (apply 'no-applicable-method (car local-args)
1220 ,(list 'quote method) local-args)
1222 ;; It is ok, do the call.
1223 ;; Fill in inter-call variables then evaluate the method.
1224 (let ((scoped-class ,(list 'quote class))
1225 (eieio-generic-call-next-method-list nil)
1226 (eieio-generic-call-key method-primary)
1227 (eieio-generic-call-methodname ,(list 'quote method))
1228 (eieio-generic-call-arglst local-args)
1230 (apply ,(list 'quote impl) local-args)
1231 ;(,impl local-args)
1232 ))))
1236 (defsubst eieio-defgeneric-reset-generic-form-primary-only-one (method)
1237 "Setup METHOD to call the generic form."
1238 (let* ((doc-string (documentation method))
1239 (M (get method 'eieio-method-tree))
1240 (entry (car (aref M method-primary)))
1242 (fset method (eieio-defgeneric-form-primary-only-one
1243 method doc-string
1244 (car entry)
1245 (cdr entry)
1246 ))))
1248 (defun eieio-defgeneric (method doc-string)
1249 "Engine part to `defgeneric' macro defining METHOD with DOC-STRING."
1250 (if (and (fboundp method) (not (generic-p method))
1251 (or (byte-code-function-p (symbol-function method))
1252 (not (eq 'autoload (car (symbol-function method)))))
1254 (error "You cannot create a generic/method over an existing symbol: %s"
1255 method))
1256 ;; Don't do this over and over.
1257 (unless (fboundp 'method)
1258 ;; This defun tells emacs where the first definition of this
1259 ;; method is defined.
1260 `(defun ,method nil)
1261 ;; Make sure the method tables are installed.
1262 (eieiomt-install method)
1263 ;; Apply the actual body of this function.
1264 (fset method (eieio-defgeneric-form method doc-string))
1265 ;; Return the method
1266 'method))
1268 (defun eieio-unbind-method-implementations (method)
1269 "Make the generic method METHOD have no implementations.
1270 It will leave the original generic function in place,
1271 but remove reference to all implementations of METHOD."
1272 (put method 'eieio-method-tree nil)
1273 (put method 'eieio-method-obarray nil))
1275 (defmacro defmethod (method &rest args)
1276 "Create a new METHOD through `defgeneric' with ARGS.
1278 The optional second argument KEY is a specifier that
1279 modifies how the method is called, including:
1280 :before - Method will be called before the :primary
1281 :primary - The default if not specified
1282 :after - Method will be called after the :primary
1283 :static - First arg could be an object or class
1284 The next argument is the ARGLIST. The ARGLIST specifies the arguments
1285 to the method as with `defun'. The first argument can have a type
1286 specifier, such as:
1287 ((VARNAME CLASS) ARG2 ...)
1288 where VARNAME is the name of the local variable for the method being
1289 created. The CLASS is a class symbol for a class made with `defclass'.
1290 A DOCSTRING comes after the ARGLIST, and is optional.
1291 All the rest of the args are the BODY of the method. A method will
1292 return the value of the last form in the BODY.
1294 Summary:
1296 (defmethod mymethod [:before | :primary | :after | :static]
1297 ((typearg class-name) arg2 &optional opt &rest rest)
1298 \"doc-string\"
1299 body)"
1300 `(eieio-defmethod (quote ,method) (quote ,args)))
1302 (defun eieio-defmethod (method args)
1303 "Work part of the `defmethod' macro defining METHOD with ARGS."
1304 (let ((key nil) (body nil) (firstarg nil) (argfix nil) (argclass nil) loopa)
1305 ;; find optional keys
1306 (setq key
1307 (cond ((or (eq ':BEFORE (car args))
1308 (eq ':before (car args)))
1309 (setq args (cdr args))
1310 method-before)
1311 ((or (eq ':AFTER (car args))
1312 (eq ':after (car args)))
1313 (setq args (cdr args))
1314 method-after)
1315 ((or (eq ':PRIMARY (car args))
1316 (eq ':primary (car args)))
1317 (setq args (cdr args))
1318 method-primary)
1319 ((or (eq ':STATIC (car args))
1320 (eq ':static (car args)))
1321 (setq args (cdr args))
1322 method-static)
1323 ;; Primary key
1324 (t method-primary)))
1325 ;; get body, and fix contents of args to be the arguments of the fn.
1326 (setq body (cdr args)
1327 args (car args))
1328 (setq loopa args)
1329 ;; Create a fixed version of the arguments
1330 (while loopa
1331 (setq argfix (cons (if (listp (car loopa)) (car (car loopa)) (car loopa))
1332 argfix))
1333 (setq loopa (cdr loopa)))
1334 ;; make sure there is a generic
1335 (eieio-defgeneric
1336 method
1337 (if (stringp (car body))
1338 (car body) (format "Generically created method `%s'." method)))
1339 ;; create symbol for property to bind to. If the first arg is of
1340 ;; the form (varname vartype) and `vartype' is a class, then
1341 ;; that class will be the type symbol. If not, then it will fall
1342 ;; under the type `primary' which is a non-specific calling of the
1343 ;; function.
1344 (setq firstarg (car args))
1345 (if (listp firstarg)
1346 (progn
1347 (setq argclass (nth 1 firstarg))
1348 (if (not (class-p argclass))
1349 (error "Unknown class type %s in method parameters"
1350 (nth 1 firstarg))))
1351 (if (= key -1)
1352 (signal 'wrong-type-argument (list :static 'non-class-arg)))
1353 ;; generics are higher
1354 (setq key (eieio-specialized-key-to-generic-key key)))
1355 ;; Put this lambda into the symbol so we can find it
1356 (if (byte-code-function-p (car-safe body))
1357 (eieiomt-add method (car-safe body) key argclass)
1358 (eieiomt-add method (append (list 'lambda (reverse argfix)) body)
1359 key argclass))
1362 (when eieio-optimize-primary-methods-flag
1363 ;; Optimizing step:
1365 ;; If this method, after this setup, only has primary methods, then
1366 ;; we can setup the generic that way.
1367 (if (generic-primary-only-p method)
1368 ;; If there is only one primary method, then we can go one more
1369 ;; optimization step.
1370 (if (generic-primary-only-one-p method)
1371 (eieio-defgeneric-reset-generic-form-primary-only-one method)
1372 (eieio-defgeneric-reset-generic-form-primary-only method))
1373 (eieio-defgeneric-reset-generic-form method)))
1375 method)
1377 ;;; Slot type validation
1379 ;; This is a hideous hack for replacing `typep' from cl-macs, to avoid
1380 ;; requiring the CL library at run-time. It can be eliminated if/when
1381 ;; `typep' is merged into Emacs core.
1382 (defun eieio--typep (val type)
1383 (if (symbolp type)
1384 (cond ((get type 'cl-deftype-handler)
1385 (eieio--typep val (funcall (get type 'cl-deftype-handler))))
1386 ((eq type t) t)
1387 ((eq type 'null) (null val))
1388 ((eq type 'atom) (atom val))
1389 ((eq type 'float) (and (numberp val) (not (integerp val))))
1390 ((eq type 'real) (numberp val))
1391 ((eq type 'fixnum) (integerp val))
1392 ((memq type '(character string-char)) (characterp val))
1394 (let* ((name (symbol-name type))
1395 (namep (intern (concat name "p"))))
1396 (if (fboundp namep)
1397 (funcall `(lambda () (,namep val)))
1398 (funcall `(lambda ()
1399 (,(intern (concat name "-p")) val)))))))
1400 (cond ((get (car type) 'cl-deftype-handler)
1401 (eieio--typep val (apply (get (car type) 'cl-deftype-handler)
1402 (cdr type))))
1403 ((memq (car type) '(integer float real number))
1404 (and (eieio--typep val (car type))
1405 (or (memq (cadr type) '(* nil))
1406 (if (consp (cadr type))
1407 (> val (car (cadr type)))
1408 (>= val (cadr type))))
1409 (or (memq (caddr type) '(* nil))
1410 (if (consp (car (cddr type)))
1411 (< val (caar (cddr type)))
1412 (<= val (car (cddr type)))))))
1413 ((memq (car type) '(and or not))
1414 (eval (cons (car type)
1415 (mapcar (lambda (x)
1416 `(eieio--typep (quote ,val) (quote ,x)))
1417 (cdr type)))))
1418 ((memq (car type) '(member member*))
1419 (memql val (cdr type)))
1420 ((eq (car type) 'satisfies)
1421 (funcall `(lambda () (,(cadr type) val))))
1422 (t (error "Bad type spec: %s" type)))))
1424 (defun eieio-perform-slot-validation (spec value)
1425 "Return non-nil if SPEC does not match VALUE."
1426 (or (eq spec t) ; t always passes
1427 (eq value eieio-unbound) ; unbound always passes
1428 (eieio--typep value spec)))
1430 (defun eieio-validate-slot-value (class slot-idx value slot)
1431 "Make sure that for CLASS referencing SLOT-IDX, VALUE is valid.
1432 Checks the :type specifier.
1433 SLOT is the slot that is being checked, and is only used when throwing
1434 an error."
1435 (if eieio-skip-typecheck
1437 ;; Trim off object IDX junk added in for the object index.
1438 (setq slot-idx (- slot-idx 3))
1439 (let ((st (aref (aref (class-v class) class-public-type) slot-idx)))
1440 (if (not (eieio-perform-slot-validation st value))
1441 (signal 'invalid-slot-type (list class slot st value))))))
1443 (defun eieio-validate-class-slot-value (class slot-idx value slot)
1444 "Make sure that for CLASS referencing SLOT-IDX, VALUE is valid.
1445 Checks the :type specifier.
1446 SLOT is the slot that is being checked, and is only used when throwing
1447 an error."
1448 (if eieio-skip-typecheck
1450 (let ((st (aref (aref (class-v class) class-class-allocation-type)
1451 slot-idx)))
1452 (if (not (eieio-perform-slot-validation st value))
1453 (signal 'invalid-slot-type (list class slot st value))))))
1455 (defun eieio-barf-if-slot-unbound (value instance slotname fn)
1456 "Throw a signal if VALUE is a representation of an UNBOUND slot.
1457 INSTANCE is the object being referenced. SLOTNAME is the offending
1458 slot. If the slot is ok, return VALUE.
1459 Argument FN is the function calling this verifier."
1460 (if (and (eq value eieio-unbound) (not eieio-skip-typecheck))
1461 (slot-unbound instance (object-class instance) slotname fn)
1462 value))
1464 ;;; Get/Set slots in an object.
1466 (defmacro oref (obj slot)
1467 "Retrieve the value stored in OBJ in the slot named by SLOT.
1468 Slot is the name of the slot when created by `defclass' or the label
1469 created by the :initarg tag."
1470 `(eieio-oref ,obj (quote ,slot)))
1472 (defun eieio-oref (obj slot)
1473 "Return the value in OBJ at SLOT in the object vector."
1474 (if (not (or (eieio-object-p obj) (class-p obj)))
1475 (signal 'wrong-type-argument (list '(or eieio-object-p class-p) obj)))
1476 (if (not (symbolp slot))
1477 (signal 'wrong-type-argument (list 'symbolp slot)))
1478 (if (class-p obj) (eieio-class-un-autoload obj))
1479 (let* ((class (if (class-p obj) obj (aref obj object-class)))
1480 (c (eieio-slot-name-index class obj slot)))
1481 (if (not c)
1482 ;; It might be missing because it is a :class allocated slot.
1483 ;; Lets check that info out.
1484 (if (setq c (eieio-class-slot-name-index class slot))
1485 ;; Oref that slot.
1486 (aref (aref (class-v class) class-class-allocation-values) c)
1487 ;; The slot-missing method is a cool way of allowing an object author
1488 ;; to intercept missing slot definitions. Since it is also the LAST
1489 ;; thing called in this fn, its return value would be retrieved.
1490 (slot-missing obj slot 'oref)
1491 ;;(signal 'invalid-slot-name (list (object-name obj) slot))
1493 (if (not (eieio-object-p obj))
1494 (signal 'wrong-type-argument (list 'eieio-object-p obj)))
1495 (eieio-barf-if-slot-unbound (aref obj c) obj slot 'oref))))
1497 (defalias 'slot-value 'eieio-oref)
1498 (defalias 'set-slot-value 'eieio-oset)
1500 (defmacro oref-default (obj slot)
1501 "Get the default value of OBJ (maybe a class) for SLOT.
1502 The default value is the value installed in a class with the :initform
1503 tag. SLOT can be the slot name, or the tag specified by the :initarg
1504 tag in the `defclass' call."
1505 `(eieio-oref-default ,obj (quote ,slot)))
1507 (defun eieio-oref-default (obj slot)
1508 "Do the work for the macro `oref-default' with similar parameters.
1509 Fills in OBJ's SLOT with its default value."
1510 (if (not (or (eieio-object-p obj) (class-p obj))) (signal 'wrong-type-argument (list 'eieio-object-p obj)))
1511 (if (not (symbolp slot)) (signal 'wrong-type-argument (list 'symbolp slot)))
1512 (let* ((cl (if (eieio-object-p obj) (aref obj object-class) obj))
1513 (c (eieio-slot-name-index cl obj slot)))
1514 (if (not c)
1515 ;; It might be missing because it is a :class allocated slot.
1516 ;; Lets check that info out.
1517 (if (setq c
1518 (eieio-class-slot-name-index cl slot))
1519 ;; Oref that slot.
1520 (aref (aref (class-v cl) class-class-allocation-values)
1522 (slot-missing obj slot 'oref-default)
1523 ;;(signal 'invalid-slot-name (list (class-name cl) slot))
1525 (eieio-barf-if-slot-unbound
1526 (let ((val (nth (- c 3) (aref (class-v cl) class-public-d))))
1527 (eieio-default-eval-maybe val))
1528 obj cl 'oref-default))))
1530 (defsubst eieio-eval-default-p (val)
1531 "Whether the default value VAL should be evaluated for use."
1532 (and (consp val) (symbolp (car val)) (fboundp (car val))))
1534 (defun eieio-default-eval-maybe (val)
1535 "Check VAL, and return what `oref-default' would provide."
1536 (cond
1537 ;; Is it a function call? If so, evaluate it.
1538 ((eieio-eval-default-p val)
1539 (eval val))
1540 ;;;; check for quoted things, and unquote them
1541 ;;((and (consp val) (eq (car val) 'quote))
1542 ;; (car (cdr val)))
1543 ;; return it verbatim
1544 (t val)))
1546 ;;; Object Set macros
1548 (defmacro oset (obj slot value)
1549 "Set the value in OBJ for slot SLOT to VALUE.
1550 SLOT is the slot name as specified in `defclass' or the tag created
1551 with in the :initarg slot. VALUE can be any Lisp object."
1552 `(eieio-oset ,obj (quote ,slot) ,value))
1554 (defun eieio-oset (obj slot value)
1555 "Do the work for the macro `oset'.
1556 Fills in OBJ's SLOT with VALUE."
1557 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj)))
1558 (if (not (symbolp slot)) (signal 'wrong-type-argument (list 'symbolp slot)))
1559 (let ((c (eieio-slot-name-index (object-class-fast obj) obj slot)))
1560 (if (not c)
1561 ;; It might be missing because it is a :class allocated slot.
1562 ;; Lets check that info out.
1563 (if (setq c
1564 (eieio-class-slot-name-index (aref obj object-class) slot))
1565 ;; Oset that slot.
1566 (progn
1567 (eieio-validate-class-slot-value (object-class-fast obj) c value slot)
1568 (aset (aref (class-v (aref obj object-class))
1569 class-class-allocation-values)
1570 c value))
1571 ;; See oref for comment on `slot-missing'
1572 (slot-missing obj slot 'oset value)
1573 ;;(signal 'invalid-slot-name (list (object-name obj) slot))
1575 (eieio-validate-slot-value (object-class-fast obj) c value slot)
1576 (aset obj c value))))
1578 (defmacro oset-default (class slot value)
1579 "Set the default slot in CLASS for SLOT to VALUE.
1580 The default value is usually set with the :initform tag during class
1581 creation. This allows users to change the default behavior of classes
1582 after they are created."
1583 `(eieio-oset-default ,class (quote ,slot) ,value))
1585 (defun eieio-oset-default (class slot value)
1586 "Do the work for the macro `oset-default'.
1587 Fills in the default value in CLASS' in SLOT with VALUE."
1588 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class)))
1589 (if (not (symbolp slot)) (signal 'wrong-type-argument (list 'symbolp slot)))
1590 (let* ((scoped-class class)
1591 (c (eieio-slot-name-index class nil slot)))
1592 (if (not c)
1593 ;; It might be missing because it is a :class allocated slot.
1594 ;; Lets check that info out.
1595 (if (setq c (eieio-class-slot-name-index class slot))
1596 (progn
1597 ;; Oref that slot.
1598 (eieio-validate-class-slot-value class c value slot)
1599 (aset (aref (class-v class) class-class-allocation-values) c
1600 value))
1601 (signal 'invalid-slot-name (list (class-name class) slot)))
1602 (eieio-validate-slot-value class c value slot)
1603 ;; Set this into the storage for defaults.
1604 (setcar (nthcdr (- c 3) (aref (class-v class) class-public-d))
1605 value)
1606 ;; Take the value, and put it into our cache object.
1607 (eieio-oset (aref (class-v class) class-default-object-cache)
1608 slot value)
1611 ;;; Handy CLOS macros
1613 (defmacro with-slots (spec-list object &rest body)
1614 "Bind SPEC-LIST lexically to slot values in OBJECT, and execute BODY.
1615 This establishes a lexical environment for referring to the slots in
1616 the instance named by the given slot-names as though they were
1617 variables. Within such a context the value of the slot can be
1618 specified by using its slot name, as if it were a lexically bound
1619 variable. Both setf and setq can be used to set the value of the
1620 slot.
1622 SPEC-LIST is of a form similar to `let'. For example:
1624 ((VAR1 SLOT1)
1625 SLOT2
1626 SLOTN
1627 (VARN+1 SLOTN+1))
1629 Where each VAR is the local variable given to the associated
1630 SLOT. A slot specified without a variable name is given a
1631 variable name of the same name as the slot."
1632 ;; Transform the spec-list into a symbol-macrolet spec-list.
1633 (let ((mappings (mapcar (lambda (entry)
1634 (let ((var (if (listp entry) (car entry) entry))
1635 (slot (if (listp entry) (cadr entry) entry)))
1636 (list var `(slot-value ,object ',slot))))
1637 spec-list)))
1638 (append (list 'symbol-macrolet mappings)
1639 body)))
1640 (put 'with-slots 'lisp-indent-function 2)
1643 ;;; Simple generators, and query functions. None of these would do
1644 ;; well embedded into an object.
1646 (defmacro object-class-fast (obj) "Return the class struct defining OBJ with no check."
1647 `(aref ,obj object-class))
1649 (defun class-name (class) "Return a Lisp like symbol name for CLASS."
1650 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class)))
1651 ;; I think this is supposed to return a symbol, but to me CLASS is a symbol,
1652 ;; and I wanted a string. Arg!
1653 (format "#<class %s>" (symbol-name class)))
1655 (defun object-name (obj &optional extra)
1656 "Return a Lisp like symbol string for object OBJ.
1657 If EXTRA, include that in the string returned to represent the symbol."
1658 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj)))
1659 (format "#<%s %s%s>" (symbol-name (object-class-fast obj))
1660 (aref obj object-name) (or extra "")))
1662 (defun object-name-string (obj) "Return a string which is OBJ's name."
1663 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj)))
1664 (aref obj object-name))
1666 (defun object-set-name-string (obj name) "Set the string which is OBJ's NAME."
1667 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj)))
1668 (if (not (stringp name)) (signal 'wrong-type-argument (list 'stringp name)))
1669 (aset obj object-name name))
1671 (defun object-class (obj) "Return the class struct defining OBJ."
1672 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj)))
1673 (object-class-fast obj))
1674 (defalias 'class-of 'object-class)
1676 (defun object-class-name (obj) "Return a Lisp like symbol name for OBJ's class."
1677 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj)))
1678 (class-name (object-class-fast obj)))
1680 (defmacro class-parents-fast (class) "Return parent classes to CLASS with no check."
1681 `(aref (class-v ,class) class-parent))
1683 (defun class-parents (class)
1684 "Return parent classes to CLASS. (overload of variable).
1686 The CLOS function `class-direct-superclasses' is aliased to this function."
1687 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class)))
1688 (class-parents-fast class))
1690 (defmacro class-children-fast (class) "Return child classes to CLASS with no check."
1691 `(aref (class-v ,class) class-children))
1693 (defun class-children (class)
1694 "Return child classes to CLASS.
1696 The CLOS function `class-direct-subclasses' is aliased to this function."
1697 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class)))
1698 (class-children-fast class))
1700 (defun eieio-c3-candidate (class remaining-inputs)
1701 "Returns CLASS if it can go in the result now, otherwise nil"
1702 ;; Ensure CLASS is not in any position but the first in any of the
1703 ;; element lists of REMAINING-INPUTS.
1704 (and (not (let ((found nil))
1705 (while (and remaining-inputs (not found))
1706 (setq found (member class (cdr (car remaining-inputs)))
1707 remaining-inputs (cdr remaining-inputs)))
1708 found))
1709 class))
1711 (defun eieio-c3-merge-lists (reversed-partial-result remaining-inputs)
1712 "Merge REVERSED-PARTIAL-RESULT REMAINING-INPUTS in a consistent order, if possible.
1713 If a consistent order does not exist, signal an error."
1714 (if (let ((tail remaining-inputs)
1715 (found nil))
1716 (while (and tail (not found))
1717 (setq found (car tail) tail (cdr tail)))
1718 (not found))
1719 ;; If all remaining inputs are empty lists, we are done.
1720 (nreverse reversed-partial-result)
1721 ;; Otherwise, we try to find the next element of the result. This
1722 ;; is achieved by considering the first element of each
1723 ;; (non-empty) input list and accepting a candidate if it is
1724 ;; consistent with the rests of the input lists.
1725 (let* ((found nil)
1726 (tail remaining-inputs)
1727 (next (progn
1728 (while (and tail (not found))
1729 (setq found (and (car tail)
1730 (eieio-c3-candidate (caar tail)
1731 remaining-inputs))
1732 tail (cdr tail)))
1733 found)))
1734 (if next
1735 ;; The graph is consistent so far, add NEXT to result and
1736 ;; merge input lists, dropping NEXT from their heads where
1737 ;; applicable.
1738 (eieio-c3-merge-lists
1739 (cons next reversed-partial-result)
1740 (mapcar (lambda (l) (if (eq (first l) next) (rest l) l))
1741 remaining-inputs))
1742 ;; The graph is inconsistent, give up
1743 (signal 'inconsistent-class-hierarchy (list remaining-inputs))))))
1745 (defun eieio-class-precedence-dfs (class)
1746 "Return all parents of CLASS in depth-first order."
1747 (let* ((parents (class-parents-fast class))
1748 (classes (copy-sequence
1749 (apply #'append
1750 (list class)
1752 (mapcar
1753 (lambda (parent)
1754 (cons parent
1755 (eieio-class-precedence-dfs parent)))
1756 parents)
1757 '((eieio-default-superclass))))))
1758 (tail classes))
1759 ;; Remove duplicates.
1760 (while tail
1761 (setcdr tail (delq (car tail) (cdr tail)))
1762 (setq tail (cdr tail)))
1763 classes))
1765 (defun eieio-class-precedence-bfs (class)
1766 "Return all parents of CLASS in breadth-first order."
1767 (let ((result)
1768 (queue (or (class-parents-fast class)
1769 '(eieio-default-superclass))))
1770 (while queue
1771 (let ((head (pop queue)))
1772 (unless (member head result)
1773 (push head result)
1774 (unless (eq head 'eieio-default-superclass)
1775 (setq queue (append queue (or (class-parents-fast head)
1776 '(eieio-default-superclass))))))))
1777 (cons class (nreverse result)))
1780 (defun eieio-class-precedence-c3 (class)
1781 "Return all parents of CLASS in c3 order."
1782 (let ((parents (class-parents-fast class)))
1783 (eieio-c3-merge-lists
1784 (list class)
1785 (append
1787 (mapcar
1788 (lambda (x)
1789 (eieio-class-precedence-c3 x))
1790 parents)
1791 '((eieio-default-superclass)))
1792 (list parents))))
1795 (defun class-precedence-list (class)
1796 "Return (transitively closed) list of parents of CLASS.
1797 The order, in which the parents are returned depends on the
1798 method invocation orders of the involved classes."
1799 (if (or (null class) (eq class 'eieio-default-superclass))
1801 (case (class-method-invocation-order class)
1802 (:depth-first
1803 (eieio-class-precedence-dfs class))
1804 (:breadth-first
1805 (eieio-class-precedence-bfs class))
1806 (:c3
1807 (eieio-class-precedence-c3 class))))
1810 ;; Official CLOS functions.
1811 (defalias 'class-direct-superclasses 'class-parents)
1812 (defalias 'class-direct-subclasses 'class-children)
1814 (defmacro class-parent-fast (class) "Return first parent class to CLASS with no check."
1815 `(car (class-parents-fast ,class)))
1817 (defmacro class-parent (class) "Return first parent class to CLASS. (overload of variable)."
1818 `(car (class-parents ,class)))
1820 (defmacro same-class-fast-p (obj class) "Return t if OBJ is of class-type CLASS with no error checking."
1821 `(eq (aref ,obj object-class) ,class))
1823 (defun same-class-p (obj class) "Return t if OBJ is of class-type CLASS."
1824 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class)))
1825 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj)))
1826 (same-class-fast-p obj class))
1828 (defun object-of-class-p (obj class)
1829 "Return non-nil if OBJ is an instance of CLASS or CLASS' subclasses."
1830 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj)))
1831 ;; class will be checked one layer down
1832 (child-of-class-p (aref obj object-class) class))
1833 ;; Backwards compatibility
1834 (defalias 'obj-of-class-p 'object-of-class-p)
1836 (defun child-of-class-p (child class)
1837 "Return non-nil if CHILD class is a subclass of CLASS."
1838 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class)))
1839 (if (not (class-p child)) (signal 'wrong-type-argument (list 'class-p child)))
1840 (let ((p nil))
1841 (while (and child (not (eq child class)))
1842 (setq p (append p (aref (class-v child) class-parent))
1843 child (car p)
1844 p (cdr p)))
1845 (if child t)))
1847 (defun object-slots (obj)
1848 "Return list of slots available in OBJ."
1849 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj)))
1850 (aref (class-v (object-class-fast obj)) class-public-a))
1852 (defun class-slot-initarg (class slot) "Fetch from CLASS, SLOT's :initarg."
1853 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class)))
1854 (let ((ia (aref (class-v class) class-initarg-tuples))
1855 (f nil))
1856 (while (and ia (not f))
1857 (if (eq (cdr (car ia)) slot)
1858 (setq f (car (car ia))))
1859 (setq ia (cdr ia)))
1862 ;;; CLOS queries into classes and slots
1864 (defun slot-boundp (object slot)
1865 "Return non-nil if OBJECT's SLOT is bound.
1866 Setting a slot's value makes it bound. Calling `slot-makeunbound' will
1867 make a slot unbound.
1868 OBJECT can be an instance or a class."
1869 ;; Skip typechecking while retrieving this value.
1870 (let ((eieio-skip-typecheck t))
1871 ;; Return nil if the magic symbol is in there.
1872 (if (eieio-object-p object)
1873 (if (eq (eieio-oref object slot) eieio-unbound) nil t)
1874 (if (class-p object)
1875 (if (eq (eieio-oref-default object slot) eieio-unbound) nil t)
1876 (signal 'wrong-type-argument (list 'eieio-object-p object))))))
1878 (defun slot-makeunbound (object slot)
1879 "In OBJECT, make SLOT unbound."
1880 (eieio-oset object slot eieio-unbound))
1882 (defun slot-exists-p (object-or-class slot)
1883 "Return non-nil if OBJECT-OR-CLASS has SLOT."
1884 (let ((cv (class-v (cond ((eieio-object-p object-or-class)
1885 (object-class object-or-class))
1886 ((class-p object-or-class)
1887 object-or-class))
1889 (or (memq slot (aref cv class-public-a))
1890 (memq slot (aref cv class-class-allocation-a)))
1893 (defun find-class (symbol &optional errorp)
1894 "Return the class that SYMBOL represents.
1895 If there is no class, nil is returned if ERRORP is nil.
1896 If ERRORP is non-nil, `wrong-argument-type' is signaled."
1897 (if (not (class-p symbol))
1898 (if errorp (signal 'wrong-type-argument (list 'class-p symbol))
1899 nil)
1900 (class-v symbol)))
1902 ;;; Slightly more complex utility functions for objects
1904 (defun object-assoc (key slot list)
1905 "Return an object if KEY is `equal' to SLOT's value of an object in LIST.
1906 LIST is a list of objects whose slots are searched.
1907 Objects in LIST do not need to have a slot named SLOT, nor does
1908 SLOT need to be bound. If these errors occur, those objects will
1909 be ignored."
1910 (if (not (listp list)) (signal 'wrong-type-argument (list 'listp list)))
1911 (while (and list (not (condition-case nil
1912 ;; This prevents errors for missing slots.
1913 (equal key (eieio-oref (car list) slot))
1914 (error nil))))
1915 (setq list (cdr list)))
1916 (car list))
1918 (defun object-assoc-list (slot list)
1919 "Return an association list with the contents of SLOT as the key element.
1920 LIST must be a list of objects with SLOT in it.
1921 This is useful when you need to do completing read on an object group."
1922 (if (not (listp list)) (signal 'wrong-type-argument (list 'listp list)))
1923 (let ((assoclist nil))
1924 (while list
1925 (setq assoclist (cons (cons (eieio-oref (car list) slot)
1926 (car list))
1927 assoclist))
1928 (setq list (cdr list)))
1929 (nreverse assoclist)))
1931 (defun object-assoc-list-safe (slot list)
1932 "Return an association list with the contents of SLOT as the key element.
1933 LIST must be a list of objects, but those objects do not need to have
1934 SLOT in it. If it does not, then that element is left out of the association
1935 list."
1936 (if (not (listp list)) (signal 'wrong-type-argument (list 'listp list)))
1937 (let ((assoclist nil))
1938 (while list
1939 (if (slot-exists-p (car list) slot)
1940 (setq assoclist (cons (cons (eieio-oref (car list) slot)
1941 (car list))
1942 assoclist)))
1943 (setq list (cdr list)))
1944 (nreverse assoclist)))
1946 (defun object-add-to-list (object slot item &optional append)
1947 "In OBJECT's SLOT, add ITEM to the list of elements.
1948 Optional argument APPEND indicates we need to append to the list.
1949 If ITEM already exists in the list in SLOT, then it is not added.
1950 Comparison is done with `equal' through the `member' function call.
1951 If SLOT is unbound, bind it to the list containing ITEM."
1952 (let (ov)
1953 ;; Find the originating list.
1954 (if (not (slot-boundp object slot))
1955 (setq ov (list item))
1956 (setq ov (eieio-oref object slot))
1957 ;; turn it into a list.
1958 (unless (listp ov)
1959 (setq ov (list ov)))
1960 ;; Do the combination
1961 (if (not (member item ov))
1962 (setq ov
1963 (if append
1964 (append ov (list item))
1965 (cons item ov)))))
1966 ;; Set back into the slot.
1967 (eieio-oset object slot ov)))
1969 (defun object-remove-from-list (object slot item)
1970 "In OBJECT's SLOT, remove occurrences of ITEM.
1971 Deletion is done with `delete', which deletes by side effect,
1972 and comparisons are done with `equal'.
1973 If SLOT is unbound, do nothing."
1974 (if (not (slot-boundp object slot))
1976 (eieio-oset object slot (delete item (eieio-oref object slot)))))
1978 ;;; EIEIO internal search functions
1980 (defun eieio-slot-originating-class-p (start-class slot)
1981 "Return non-nil if START-CLASS is the first class to define SLOT.
1982 This is for testing if `scoped-class' is the class that defines SLOT
1983 so that we can protect private slots."
1984 (let ((par (class-parents start-class))
1985 (ret t))
1986 (if (not par)
1988 (while (and par ret)
1989 (if (intern-soft (symbol-name slot)
1990 (aref (class-v (car par))
1991 class-symbol-obarray))
1992 (setq ret nil))
1993 (setq par (cdr par)))
1994 ret)))
1996 (defun eieio-slot-name-index (class obj slot)
1997 "In CLASS for OBJ find the index of the named SLOT.
1998 The slot is a symbol which is installed in CLASS by the `defclass'
1999 call. OBJ can be nil, but if it is an object, and the slot in question
2000 is protected, access will be allowed if OBJ is a child of the currently
2001 `scoped-class'.
2002 If SLOT is the value created with :initarg instead,
2003 reverse-lookup that name, and recurse with the associated slot value."
2004 ;; Removed checks to outside this call
2005 (let* ((fsym (intern-soft (symbol-name slot)
2006 (aref (class-v class)
2007 class-symbol-obarray)))
2008 (fsi (if (symbolp fsym) (symbol-value fsym) nil)))
2009 (if (integerp fsi)
2010 (cond
2011 ((not (get fsym 'protection))
2012 (+ 3 fsi))
2013 ((and (eq (get fsym 'protection) 'protected)
2014 scoped-class
2015 (or (child-of-class-p class scoped-class)
2016 (and (eieio-object-p obj)
2017 (child-of-class-p class (object-class obj)))))
2018 (+ 3 fsi))
2019 ((and (eq (get fsym 'protection) 'private)
2020 (or (and scoped-class
2021 (eieio-slot-originating-class-p scoped-class slot))
2022 eieio-initializing-object))
2023 (+ 3 fsi))
2024 (t nil))
2025 (let ((fn (eieio-initarg-to-attribute class slot)))
2026 (if fn (eieio-slot-name-index class obj fn) nil)))))
2028 (defun eieio-class-slot-name-index (class slot)
2029 "In CLASS find the index of the named SLOT.
2030 The slot is a symbol which is installed in CLASS by the `defclass'
2031 call. If SLOT is the value created with :initarg instead,
2032 reverse-lookup that name, and recurse with the associated slot value."
2033 ;; This will happen less often, and with fewer slots. Do this the
2034 ;; storage cheap way.
2035 (let* ((a (aref (class-v class) class-class-allocation-a))
2036 (l1 (length a))
2037 (af (memq slot a))
2038 (l2 (length af)))
2039 ;; Slot # is length of the total list, minus the remaining list of
2040 ;; the found slot.
2041 (if af (- l1 l2))))
2043 ;;; CLOS generics internal function handling
2045 (defvar eieio-generic-call-methodname nil
2046 "When using `call-next-method', provides a context on how to do it.")
2047 (defvar eieio-generic-call-arglst nil
2048 "When using `call-next-method', provides a context for parameters.")
2049 (defvar eieio-generic-call-key nil
2050 "When using `call-next-method', provides a context for the current key.
2051 Keys are a number representing :before, :primary, and :after methods.")
2052 (defvar eieio-generic-call-next-method-list nil
2053 "When executing a PRIMARY or STATIC method, track the 'next-method'.
2054 During executions, the list is first generated, then as each next method
2055 is called, the next method is popped off the stack.")
2057 (defvar eieio-pre-method-execution-hooks nil
2058 "*Hooks run just before a method is executed.
2059 The hook function must accept one argument, the list of forms
2060 about to be executed.")
2062 (defun eieio-generic-call (method args)
2063 "Call METHOD with ARGS.
2064 ARGS provides the context on which implementation to use.
2065 This should only be called from a generic function."
2066 ;; We must expand our arguments first as they are always
2067 ;; passed in as quoted symbols
2068 (let ((newargs nil) (mclass nil) (lambdas nil) (tlambdas nil) (keys nil)
2069 (eieio-generic-call-methodname method)
2070 (eieio-generic-call-arglst args)
2071 (firstarg nil)
2072 (primarymethodlist nil))
2073 ;; get a copy
2074 (setq newargs args
2075 firstarg (car newargs))
2076 ;; Is the class passed in autoloaded?
2077 ;; Since class names are also constructors, they can be autoloaded
2078 ;; via the autoload command. Check for this, and load them in.
2079 ;; It's ok if it doesn't turn out to be a class. Probably want that
2080 ;; function loaded anyway.
2081 (if (and (symbolp firstarg)
2082 (fboundp firstarg)
2083 (listp (symbol-function firstarg))
2084 (eq 'autoload (car (symbol-function firstarg))))
2085 (load (nth 1 (symbol-function firstarg))))
2086 ;; Determine the class to use.
2087 (cond ((eieio-object-p firstarg)
2088 (setq mclass (object-class-fast firstarg)))
2089 ((class-p firstarg)
2090 (setq mclass firstarg))
2092 ;; Make sure the class is a valid class
2093 ;; mclass can be nil (meaning a generic for should be used.
2094 ;; mclass cannot have a value that is not a class, however.
2095 (when (and (not (null mclass)) (not (class-p mclass)))
2096 (error "Cannot dispatch method %S on class %S"
2097 method mclass)
2099 ;; Now create a list in reverse order of all the calls we have
2100 ;; make in order to successfully do this right. Rules:
2101 ;; 1) Only call generics if scoped-class is not defined
2102 ;; This prevents multiple calls in the case of recursion
2103 ;; 2) Only call static if this is a static method.
2104 ;; 3) Only call specifics if the definition allows for them.
2105 ;; 4) Call in order based on :before, :primary, and :after
2106 (when (eieio-object-p firstarg)
2107 ;; Non-static calls do all this stuff.
2109 ;; :after methods
2110 (setq tlambdas
2111 (if mclass
2112 (eieiomt-method-list method method-after mclass)
2113 (list (eieio-generic-form method method-after nil)))
2114 ;;(or (and mclass (eieio-generic-form method method-after mclass))
2115 ;; (eieio-generic-form method method-after nil))
2117 (setq lambdas (append tlambdas lambdas)
2118 keys (append (make-list (length tlambdas) method-after) keys))
2120 ;; :primary methods
2121 (setq tlambdas
2122 (or (and mclass (eieio-generic-form method method-primary mclass))
2123 (eieio-generic-form method method-primary nil)))
2124 (when tlambdas
2125 (setq lambdas (cons tlambdas lambdas)
2126 keys (cons method-primary keys)
2127 primarymethodlist
2128 (eieiomt-method-list method method-primary mclass)))
2130 ;; :before methods
2131 (setq tlambdas
2132 (if mclass
2133 (eieiomt-method-list method method-before mclass)
2134 (list (eieio-generic-form method method-before nil)))
2135 ;;(or (and mclass (eieio-generic-form method method-before mclass))
2136 ;; (eieio-generic-form method method-before nil))
2138 (setq lambdas (append tlambdas lambdas)
2139 keys (append (make-list (length tlambdas) method-before) keys))
2142 (if mclass
2143 ;; For the case of a class,
2144 ;; if there were no methods found, then there could be :static methods.
2145 (when (not lambdas)
2146 (setq tlambdas
2147 (eieio-generic-form method method-static mclass))
2148 (setq lambdas (cons tlambdas lambdas)
2149 keys (cons method-static keys)
2150 primarymethodlist ;; Re-use even with bad name here
2151 (eieiomt-method-list method method-static mclass)))
2152 ;; For the case of no class (ie - mclass == nil) then there may
2153 ;; be a primary method.
2154 (setq tlambdas
2155 (eieio-generic-form method method-primary nil))
2156 (when tlambdas
2157 (setq lambdas (cons tlambdas lambdas)
2158 keys (cons method-primary keys)
2159 primarymethodlist
2160 (eieiomt-method-list method method-primary nil)))
2163 (run-hook-with-args 'eieio-pre-method-execution-hooks
2164 primarymethodlist)
2166 ;; Now loop through all occurrences forms which we must execute
2167 ;; (which are happily sorted now) and execute them all!
2168 (let ((rval nil) (lastval nil) (rvalever nil) (found nil))
2169 (while lambdas
2170 (if (car lambdas)
2171 (let* ((scoped-class (cdr (car lambdas)))
2172 (eieio-generic-call-key (car keys))
2173 (has-return-val
2174 (or (= eieio-generic-call-key method-primary)
2175 (= eieio-generic-call-key method-static)))
2176 (eieio-generic-call-next-method-list
2177 ;; Use the cdr, as the first element is the fcn
2178 ;; we are calling right now.
2179 (when has-return-val (cdr primarymethodlist)))
2181 (setq found t)
2182 ;;(setq rval (apply (car (car lambdas)) newargs))
2183 (setq lastval (apply (car (car lambdas)) newargs))
2184 (when has-return-val
2185 (setq rval lastval
2186 rvalever t))
2188 (setq lambdas (cdr lambdas)
2189 keys (cdr keys)))
2190 (if (not found)
2191 (if (eieio-object-p (car args))
2192 (setq rval (apply 'no-applicable-method (car args) method args)
2193 rvalever t)
2194 (signal
2195 'no-method-definition
2196 (list method args))))
2197 ;; Right Here... it could be that lastval is returned when
2198 ;; rvalever is nil. Is that right?
2199 rval)))
2201 (defun eieio-generic-call-primary-only (method args)
2202 "Call METHOD with ARGS for methods with only :PRIMARY implementations.
2203 ARGS provides the context on which implementation to use.
2204 This should only be called from a generic function.
2206 This method is like `eieio-generic-call', but only
2207 implementations in the :PRIMARY slot are queried. After many
2208 years of use, it appears that over 90% of methods in use
2209 have :PRIMARY implementations only. We can therefore optimize
2210 for this common case to improve performance."
2211 ;; We must expand our arguments first as they are always
2212 ;; passed in as quoted symbols
2213 (let ((newargs nil) (mclass nil) (lambdas nil)
2214 (eieio-generic-call-methodname method)
2215 (eieio-generic-call-arglst args)
2216 (firstarg nil)
2217 (primarymethodlist nil)
2219 ;; get a copy
2220 (setq newargs args
2221 firstarg (car newargs))
2223 ;; Determine the class to use.
2224 (cond ((eieio-object-p firstarg)
2225 (setq mclass (object-class-fast firstarg)))
2226 ((not firstarg)
2227 (error "Method %s called on nil" method))
2228 ((not (eieio-object-p firstarg))
2229 (error "Primary-only method %s called on something not an object" method))
2231 (error "EIEIO Error: Improperly classified method %s as primary only"
2232 method)
2234 ;; Make sure the class is a valid class
2235 ;; mclass can be nil (meaning a generic for should be used.
2236 ;; mclass cannot have a value that is not a class, however.
2237 (when (null mclass)
2238 (error "Cannot dispatch method %S on class %S" method mclass)
2241 ;; :primary methods
2242 (setq lambdas (eieio-generic-form method method-primary mclass))
2243 (setq primarymethodlist ;; Re-use even with bad name here
2244 (eieiomt-method-list method method-primary mclass))
2246 ;; Now loop through all occurrences forms which we must execute
2247 ;; (which are happily sorted now) and execute them all!
2248 (let* ((rval nil) (lastval nil) (rvalever nil)
2249 (scoped-class (cdr lambdas))
2250 (eieio-generic-call-key method-primary)
2251 ;; Use the cdr, as the first element is the fcn
2252 ;; we are calling right now.
2253 (eieio-generic-call-next-method-list (cdr primarymethodlist))
2256 (if (or (not lambdas) (not (car lambdas)))
2258 ;; No methods found for this impl...
2259 (if (eieio-object-p (car args))
2260 (setq rval (apply 'no-applicable-method (car args) method args)
2261 rvalever t)
2262 (signal
2263 'no-method-definition
2264 (list method args)))
2266 ;; Do the regular implementation here.
2268 (run-hook-with-args 'eieio-pre-method-execution-hooks
2269 lambdas)
2271 (setq lastval (apply (car lambdas) newargs))
2272 (setq rval lastval
2273 rvalever t)
2276 ;; Right Here... it could be that lastval is returned when
2277 ;; rvalever is nil. Is that right?
2278 rval)))
2280 (defun eieiomt-method-list (method key class)
2281 "Return an alist list of methods lambdas.
2282 METHOD is the method name.
2283 KEY represents either :before, or :after methods.
2284 CLASS is the starting class to search from in the method tree.
2285 If CLASS is nil, then an empty list of methods should be returned."
2286 ;; Note: eieiomt - the MT means MethodTree. See more comments below
2287 ;; for the rest of the eieiomt methods.
2289 ;; Collect lambda expressions stored for the class and its parent
2290 ;; classes.
2291 (let (lambdas)
2292 (dolist (ancestor (class-precedence-list class))
2293 ;; Lookup the form to use for the PRIMARY object for the next level
2294 (let ((tmpl (eieio-generic-form method key ancestor)))
2295 (when (and tmpl
2296 (or (not lambdas)
2297 ;; This prevents duplicates coming out of the
2298 ;; class method optimizer. Perhaps we should
2299 ;; just not optimize before/afters?
2300 (not (member tmpl lambdas))))
2301 (push tmpl lambdas))))
2303 ;; Return collected lambda. For :after methods, return in current
2304 ;; order (most general class last); Otherwise, reverse order.
2305 (if (eq key method-after)
2306 lambdas
2307 (nreverse lambdas))))
2309 (defun next-method-p ()
2310 "Return non-nil if there is a next method.
2311 Returns a list of lambda expressions which is the `next-method'
2312 order."
2313 eieio-generic-call-next-method-list)
2315 (defun call-next-method (&rest replacement-args)
2316 "Call the superclass method from a subclass method.
2317 The superclass method is specified in the current method list,
2318 and is called the next method.
2320 If REPLACEMENT-ARGS is non-nil, then use them instead of
2321 `eieio-generic-call-arglst'. The generic arg list are the
2322 arguments passed in at the top level.
2324 Use `next-method-p' to find out if there is a next method to call."
2325 (if (not scoped-class)
2326 (error "`call-next-method' not called within a class specific method"))
2327 (if (and (/= eieio-generic-call-key method-primary)
2328 (/= eieio-generic-call-key method-static))
2329 (error "Cannot `call-next-method' except in :primary or :static methods")
2331 (let ((newargs (or replacement-args eieio-generic-call-arglst))
2332 (next (car eieio-generic-call-next-method-list))
2334 (if (or (not next) (not (car next)))
2335 (apply 'no-next-method (car newargs) (cdr newargs))
2336 (let* ((eieio-generic-call-next-method-list
2337 (cdr eieio-generic-call-next-method-list))
2338 (eieio-generic-call-arglst newargs)
2339 (scoped-class (cdr next))
2340 (fcn (car next))
2342 (apply fcn newargs)
2343 ))))
2346 ;; eieio-method-tree : eieiomt-
2348 ;; Stored as eieio-method-tree in property list of a generic method
2350 ;; (eieio-method-tree . [BEFORE PRIMARY AFTER
2351 ;; genericBEFORE genericPRIMARY genericAFTER])
2352 ;; and
2353 ;; (eieio-method-obarray . [BEFORE PRIMARY AFTER
2354 ;; genericBEFORE genericPRIMARY genericAFTER])
2355 ;; where the association is a vector.
2356 ;; (aref 0 -- all static methods.
2357 ;; (aref 1 -- all methods classified as :before
2358 ;; (aref 2 -- all methods classified as :primary
2359 ;; (aref 3 -- all methods classified as :after
2360 ;; (aref 4 -- a generic classified as :before
2361 ;; (aref 5 -- a generic classified as :primary
2362 ;; (aref 6 -- a generic classified as :after
2364 (defvar eieiomt-optimizing-obarray nil
2365 "While mapping atoms, this contain the obarray being optimized.")
2367 (defun eieiomt-install (method-name)
2368 "Install the method tree, and obarray onto METHOD-NAME.
2369 Do not do the work if they already exist."
2370 (let ((emtv (get method-name 'eieio-method-tree))
2371 (emto (get method-name 'eieio-method-obarray)))
2372 (if (or (not emtv) (not emto))
2373 (progn
2374 (setq emtv (put method-name 'eieio-method-tree
2375 (make-vector method-num-slots nil))
2376 emto (put method-name 'eieio-method-obarray
2377 (make-vector method-num-slots nil)))
2378 (aset emto 0 (make-vector 11 0))
2379 (aset emto 1 (make-vector 11 0))
2380 (aset emto 2 (make-vector 41 0))
2381 (aset emto 3 (make-vector 11 0))
2382 ))))
2384 (defun eieiomt-add (method-name method key class)
2385 "Add to METHOD-NAME the forms METHOD in a call position KEY for CLASS.
2386 METHOD-NAME is the name created by a call to `defgeneric'.
2387 METHOD are the forms for a given implementation.
2388 KEY is an integer (see comment in eieio.el near this function) which
2389 is associated with the :static :before :primary and :after tags.
2390 It also indicates if CLASS is defined or not.
2391 CLASS is the class this method is associated with."
2392 (if (or (> key method-num-slots) (< key 0))
2393 (error "eieiomt-add: method key error!"))
2394 (let ((emtv (get method-name 'eieio-method-tree))
2395 (emto (get method-name 'eieio-method-obarray)))
2396 ;; Make sure the method tables are available.
2397 (if (or (not emtv) (not emto))
2398 (error "Programmer error: eieiomt-add"))
2399 ;; only add new cells on if it doesn't already exist!
2400 (if (assq class (aref emtv key))
2401 (setcdr (assq class (aref emtv key)) method)
2402 (aset emtv key (cons (cons class method) (aref emtv key))))
2403 ;; Add function definition into newly created symbol, and store
2404 ;; said symbol in the correct obarray, otherwise use the
2405 ;; other array to keep this stuff
2406 (if (< key method-num-lists)
2407 (let ((nsym (intern (symbol-name class) (aref emto key))))
2408 (fset nsym method)))
2409 ;; Now optimize the entire obarray
2410 (if (< key method-num-lists)
2411 (let ((eieiomt-optimizing-obarray (aref emto key)))
2412 ;; @todo - Is this overkill? Should we just clear the symbol?
2413 (mapatoms 'eieiomt-sym-optimize eieiomt-optimizing-obarray)))
2416 (defun eieiomt-next (class)
2417 "Return the next parent class for CLASS.
2418 If CLASS is a superclass, return variable `eieio-default-superclass'.
2419 If CLASS is variable `eieio-default-superclass' then return nil.
2420 This is different from function `class-parent' as class parent returns
2421 nil for superclasses. This function performs no type checking!"
2422 ;; No type-checking because all calls are made from functions which
2423 ;; are safe and do checking for us.
2424 (or (class-parents-fast class)
2425 (if (eq class 'eieio-default-superclass)
2427 '(eieio-default-superclass))))
2429 (defun eieiomt-sym-optimize (s)
2430 "Find the next class above S which has a function body for the optimizer."
2431 ;; Set the value to nil in case there is no nearest cell.
2432 (set s nil)
2433 ;; Find the nearest cell that has a function body. If we find one,
2434 ;; we replace the nil from above.
2435 (let ((external-symbol (intern-soft (symbol-name s))))
2436 (catch 'done
2437 (dolist (ancestor (rest (class-precedence-list external-symbol)))
2438 (let ((ov (intern-soft (symbol-name ancestor)
2439 eieiomt-optimizing-obarray)))
2440 (when (fboundp ov)
2441 (set s ov) ;; store ov as our next symbol
2442 (throw 'done ancestor)))))))
2444 (defun eieio-generic-form (method key class)
2445 "Return the lambda form belonging to METHOD using KEY based upon CLASS.
2446 If CLASS is not a class then use `generic' instead. If class has
2447 no form, but has a parent class, then trace to that parent class.
2448 The first time a form is requested from a symbol, an optimized path
2449 is memorized for faster future use."
2450 (let ((emto (aref (get method 'eieio-method-obarray)
2451 (if class key (eieio-specialized-key-to-generic-key key)))))
2452 (if (class-p class)
2453 ;; 1) find our symbol
2454 (let ((cs (intern-soft (symbol-name class) emto)))
2455 (if (not cs)
2456 ;; 2) If there isn't one, then make one.
2457 ;; This can be slow since it only occurs once
2458 (progn
2459 (setq cs (intern (symbol-name class) emto))
2460 ;; 2.1) Cache its nearest neighbor with a quick optimize
2461 ;; which should only occur once for this call ever
2462 (let ((eieiomt-optimizing-obarray emto))
2463 (eieiomt-sym-optimize cs))))
2464 ;; 3) If it's bound return this one.
2465 (if (fboundp cs)
2466 (cons cs (aref (class-v class) class-symbol))
2467 ;; 4) If it's not bound then this variable knows something
2468 (if (symbol-value cs)
2469 (progn
2470 ;; 4.1) This symbol holds the next class in its value
2471 (setq class (symbol-value cs)
2472 cs (intern-soft (symbol-name class) emto))
2473 ;; 4.2) The optimizer should always have chosen a
2474 ;; function-symbol
2475 ;;(if (fboundp cs)
2476 (cons cs (aref (class-v (intern (symbol-name class)))
2477 class-symbol))
2478 ;;(error "EIEIO optimizer: erratic data loss!"))
2480 ;; There never will be a funcall...
2481 nil)))
2482 ;; for a generic call, what is a list, is the function body we want.
2483 (let ((emtl (aref (get method 'eieio-method-tree)
2484 (if class key (eieio-specialized-key-to-generic-key key)))))
2485 (if emtl
2486 ;; The car of EMTL is supposed to be a class, which in this
2487 ;; case is nil, so skip it.
2488 (cons (cdr (car emtl)) nil)
2489 nil)))))
2492 ;; Way to assign slots based on a list. Used for constructors, or
2493 ;; even resetting an object at run-time
2495 (defun eieio-set-defaults (obj &optional set-all)
2496 "Take object OBJ, and reset all slots to their defaults.
2497 If SET-ALL is non-nil, then when a default is nil, that value is
2498 reset. If SET-ALL is nil, the slots are only reset if the default is
2499 not nil."
2500 (let ((scoped-class (aref obj object-class))
2501 (eieio-initializing-object t)
2502 (pub (aref (class-v (aref obj object-class)) class-public-a)))
2503 (while pub
2504 (let ((df (eieio-oref-default obj (car pub))))
2505 (if (or df set-all)
2506 (eieio-oset obj (car pub) df)))
2507 (setq pub (cdr pub)))))
2509 (defun eieio-initarg-to-attribute (class initarg)
2510 "For CLASS, convert INITARG to the actual attribute name.
2511 If there is no translation, pass it in directly (so we can cheat if
2512 need be... May remove that later...)"
2513 (let ((tuple (assoc initarg (aref (class-v class) class-initarg-tuples))))
2514 (if tuple
2515 (cdr tuple)
2516 nil)))
2518 (defun eieio-attribute-to-initarg (class attribute)
2519 "In CLASS, convert the ATTRIBUTE into the corresponding init argument tag.
2520 This is usually a symbol that starts with `:'."
2521 (let ((tuple (rassoc attribute (aref (class-v class) class-initarg-tuples))))
2522 (if tuple
2523 (car tuple)
2524 nil)))
2527 ;;; Here are some special types of errors
2529 (intern "no-method-definition")
2530 (put 'no-method-definition 'error-conditions '(no-method-definition error))
2531 (put 'no-method-definition 'error-message "No method definition")
2533 (intern "no-next-method")
2534 (put 'no-next-method 'error-conditions '(no-next-method error))
2535 (put 'no-next-method 'error-message "No next method")
2537 (intern "invalid-slot-name")
2538 (put 'invalid-slot-name 'error-conditions '(invalid-slot-name error))
2539 (put 'invalid-slot-name 'error-message "Invalid slot name")
2541 (intern "invalid-slot-type")
2542 (put 'invalid-slot-type 'error-conditions '(invalid-slot-type error nil))
2543 (put 'invalid-slot-type 'error-message "Invalid slot type")
2545 (intern "unbound-slot")
2546 (put 'unbound-slot 'error-conditions '(unbound-slot error nil))
2547 (put 'unbound-slot 'error-message "Unbound slot")
2549 (intern "inconsistent-class-hierarchy")
2550 (put 'inconsistent-class-hierarchy 'error-conditions
2551 '(inconsistent-class-hierarchy error nil))
2552 (put 'inconsistent-class-hierarchy 'error-message "Inconsistent class hierarchy")
2554 ;;; Here are some CLOS items that need the CL package
2557 (defsetf slot-value (obj slot) (store) (list 'eieio-oset obj slot store))
2558 (defsetf eieio-oref (obj slot) (store) (list 'eieio-oset obj slot store))
2560 ;; The below setf method was written by Arnd Kohrs <kohrs@acm.org>
2561 (define-setf-method oref (obj slot)
2562 (with-no-warnings
2563 (require 'cl)
2564 (let ((obj-temp (gensym))
2565 (slot-temp (gensym))
2566 (store-temp (gensym)))
2567 (list (list obj-temp slot-temp)
2568 (list obj `(quote ,slot))
2569 (list store-temp)
2570 (list 'set-slot-value obj-temp slot-temp
2571 store-temp)
2572 (list 'slot-value obj-temp slot-temp)))))
2576 ;; We want all objects created by EIEIO to have some default set of
2577 ;; behaviours so we can create object utilities, and allow various
2578 ;; types of error checking. To do this, create the default EIEIO
2579 ;; class, and when no parent class is specified, use this as the
2580 ;; default. (But don't store it in the other classes as the default,
2581 ;; allowing for transparent support.)
2584 (defclass eieio-default-superclass nil
2586 "Default parent class for classes with no specified parent class.
2587 Its slots are automatically adopted by classes with no specified parents.
2588 This class is not stored in the `parent' slot of a class vector."
2589 :abstract t)
2591 (defalias 'standard-class 'eieio-default-superclass)
2593 (defgeneric constructor (class newname &rest slots)
2594 "Default constructor for CLASS `eieio-default-superclass'.")
2596 (defmethod constructor :static
2597 ((class eieio-default-superclass) newname &rest slots)
2598 "Default constructor for CLASS `eieio-default-superclass'.
2599 NEWNAME is the name to be given to the constructed object.
2600 SLOTS are the initialization slots used by `shared-initialize'.
2601 This static method is called when an object is constructed.
2602 It allocates the vector used to represent an EIEIO object, and then
2603 calls `shared-initialize' on that object."
2604 (let* ((new-object (copy-sequence (aref (class-v class)
2605 class-default-object-cache))))
2606 ;; Update the name for the newly created object.
2607 (aset new-object object-name newname)
2608 ;; Call the initialize method on the new object with the slots
2609 ;; that were passed down to us.
2610 (initialize-instance new-object slots)
2611 ;; Return the created object.
2612 new-object))
2614 (defgeneric shared-initialize (obj slots)
2615 "Set slots of OBJ with SLOTS which is a list of name/value pairs.
2616 Called from the constructor routine.")
2618 (defmethod shared-initialize ((obj eieio-default-superclass) slots)
2619 "Set slots of OBJ with SLOTS which is a list of name/value pairs.
2620 Called from the constructor routine."
2621 (let ((scoped-class (aref obj object-class)))
2622 (while slots
2623 (let ((rn (eieio-initarg-to-attribute (object-class-fast obj)
2624 (car slots))))
2625 (if (not rn)
2626 (slot-missing obj (car slots) 'oset (car (cdr slots)))
2627 (eieio-oset obj rn (car (cdr slots)))))
2628 (setq slots (cdr (cdr slots))))))
2630 (defgeneric initialize-instance (this &optional slots)
2631 "Construct the new object THIS based on SLOTS.")
2633 (defmethod initialize-instance ((this eieio-default-superclass)
2634 &optional slots)
2635 "Construct the new object THIS based on SLOTS.
2636 SLOTS is a tagged list where odd numbered elements are tags, and
2637 even numbered elements are the values to store in the tagged slot.
2638 If you overload the `initialize-instance', there you will need to
2639 call `shared-initialize' yourself, or you can call `call-next-method'
2640 to have this constructor called automatically. If these steps are
2641 not taken, then new objects of your class will not have their values
2642 dynamically set from SLOTS."
2643 ;; First, see if any of our defaults are `lambda', and
2644 ;; re-evaluate them and apply the value to our slots.
2645 (let* ((scoped-class (class-v (aref this object-class)))
2646 (slot (aref scoped-class class-public-a))
2647 (defaults (aref scoped-class class-public-d)))
2648 (while slot
2649 ;; For each slot, see if we need to evaluate it.
2651 ;; Paul Landes said in an email:
2652 ;; > CL evaluates it if it can, and otherwise, leaves it as
2653 ;; > the quoted thing as you already have. This is by the
2654 ;; > Sonya E. Keene book and other things I've look at on the
2655 ;; > web.
2656 (let ((dflt (eieio-default-eval-maybe (car defaults))))
2657 (when (not (eq dflt (car defaults)))
2658 (eieio-oset this (car slot) dflt) ))
2659 ;; Next.
2660 (setq slot (cdr slot)
2661 defaults (cdr defaults))))
2662 ;; Shared initialize will parse our slots for us.
2663 (shared-initialize this slots))
2665 (defgeneric slot-missing (object slot-name operation &optional new-value)
2666 "Method invoked when an attempt to access a slot in OBJECT fails.")
2668 (defmethod slot-missing ((object eieio-default-superclass) slot-name
2669 operation &optional new-value)
2670 "Method invoked when an attempt to access a slot in OBJECT fails.
2671 SLOT-NAME is the name of the failed slot, OPERATION is the type of access
2672 that was requested, and optional NEW-VALUE is the value that was desired
2673 to be set.
2675 This method is called from `oref', `oset', and other functions which
2676 directly reference slots in EIEIO objects."
2677 (signal 'invalid-slot-name (list (object-name object)
2678 slot-name)))
2680 (defgeneric slot-unbound (object class slot-name fn)
2681 "Slot unbound is invoked during an attempt to reference an unbound slot.")
2683 (defmethod slot-unbound ((object eieio-default-superclass)
2684 class slot-name fn)
2685 "Slot unbound is invoked during an attempt to reference an unbound slot.
2686 OBJECT is the instance of the object being reference. CLASS is the
2687 class of OBJECT, and SLOT-NAME is the offending slot. This function
2688 throws the signal `unbound-slot'. You can overload this function and
2689 return the value to use in place of the unbound value.
2690 Argument FN is the function signaling this error.
2691 Use `slot-boundp' to determine if a slot is bound or not.
2693 In CLOS, the argument list is (CLASS OBJECT SLOT-NAME), but
2694 EIEIO can only dispatch on the first argument, so the first two are swapped."
2695 (signal 'unbound-slot (list (class-name class) (object-name object)
2696 slot-name fn)))
2698 (defgeneric no-applicable-method (object method &rest args)
2699 "Called if there are no implementations for OBJECT in METHOD.")
2701 (defmethod no-applicable-method ((object eieio-default-superclass)
2702 method &rest args)
2703 "Called if there are no implementations for OBJECT in METHOD.
2704 OBJECT is the object which has no method implementation.
2705 ARGS are the arguments that were passed to METHOD.
2707 Implement this for a class to block this signal. The return
2708 value becomes the return value of the original method call."
2709 (signal 'no-method-definition (list method (object-name object)))
2712 (defgeneric no-next-method (object &rest args)
2713 "Called from `call-next-method' when no additional methods are available.")
2715 (defmethod no-next-method ((object eieio-default-superclass)
2716 &rest args)
2717 "Called from `call-next-method' when no additional methods are available.
2718 OBJECT is othe object being called on `call-next-method'.
2719 ARGS are the arguments it is called by.
2720 This method signals `no-next-method' by default. Override this
2721 method to not throw an error, and its return value becomes the
2722 return value of `call-next-method'."
2723 (signal 'no-next-method (list (object-name object) args))
2726 (defgeneric clone (obj &rest params)
2727 "Make a copy of OBJ, and then supply PARAMS.
2728 PARAMS is a parameter list of the same form used by `initialize-instance'.
2730 When overloading `clone', be sure to call `call-next-method'
2731 first and modify the returned object.")
2733 (defmethod clone ((obj eieio-default-superclass) &rest params)
2734 "Make a copy of OBJ, and then apply PARAMS."
2735 (let ((nobj (copy-sequence obj))
2736 (nm (aref obj object-name))
2737 (passname (and params (stringp (car params))))
2738 (num 1))
2739 (if params (shared-initialize nobj (if passname (cdr params) params)))
2740 (if (not passname)
2741 (save-match-data
2742 (if (string-match "-\\([0-9]+\\)" nm)
2743 (setq num (1+ (string-to-number (match-string 1 nm)))
2744 nm (substring nm 0 (match-beginning 0))))
2745 (aset nobj object-name (concat nm "-" (int-to-string num))))
2746 (aset nobj object-name (car params)))
2747 nobj))
2749 (defgeneric destructor (this &rest params)
2750 "Destructor for cleaning up any dynamic links to our object.")
2752 (defmethod destructor ((this eieio-default-superclass) &rest params)
2753 "Destructor for cleaning up any dynamic links to our object.
2754 Argument THIS is the object being destroyed. PARAMS are additional
2755 ignored parameters."
2756 ;; No cleanup... yet.
2759 (defgeneric object-print (this &rest strings)
2760 "Pretty printer for object THIS. Call function `object-name' with STRINGS.
2762 It is sometimes useful to put a summary of the object into the
2763 default #<notation> string when using EIEIO browsing tools.
2764 Implement this method to customize the summary.")
2766 (defmethod object-print ((this eieio-default-superclass) &rest strings)
2767 "Pretty printer for object THIS. Call function `object-name' with STRINGS.
2768 The default method for printing object THIS is to use the
2769 function `object-name'.
2771 It is sometimes useful to put a summary of the object into the
2772 default #<notation> string when using EIEIO browsing tools.
2774 Implement this function and specify STRINGS in a call to
2775 `call-next-method' to provide additional summary information.
2776 When passing in extra strings from child classes, always remember
2777 to prepend a space."
2778 (object-name this (apply 'concat strings)))
2780 (defvar eieio-print-depth 0
2781 "When printing, keep track of the current indentation depth.")
2783 (defgeneric object-write (this &optional comment)
2784 "Write out object THIS to the current stream.
2785 Optional COMMENT will add comments to the beginning of the output.")
2787 (defmethod object-write ((this eieio-default-superclass) &optional comment)
2788 "Write object THIS out to the current stream.
2789 This writes out the vector version of this object. Complex and recursive
2790 object are discouraged from being written.
2791 If optional COMMENT is non-nil, include comments when outputting
2792 this object."
2793 (when comment
2794 (princ ";; Object ")
2795 (princ (object-name-string this))
2796 (princ "\n")
2797 (princ comment)
2798 (princ "\n"))
2799 (let* ((cl (object-class this))
2800 (cv (class-v cl)))
2801 ;; Now output readable lisp to recreate this object
2802 ;; It should look like this:
2803 ;; (<constructor> <name> <slot> <slot> ... )
2804 ;; Each slot's slot is writen using its :writer.
2805 (princ (make-string (* eieio-print-depth 2) ? ))
2806 (princ "(")
2807 (princ (symbol-name (class-constructor (object-class this))))
2808 (princ " \"")
2809 (princ (object-name-string this))
2810 (princ "\"\n")
2811 ;; Loop over all the public slots
2812 (let ((publa (aref cv class-public-a))
2813 (publd (aref cv class-public-d))
2814 (publp (aref cv class-public-printer))
2815 (eieio-print-depth (1+ eieio-print-depth)))
2816 (while publa
2817 (when (slot-boundp this (car publa))
2818 (let ((i (class-slot-initarg cl (car publa)))
2819 (v (eieio-oref this (car publa)))
2821 (unless (or (not i) (equal v (car publd)))
2822 (princ (make-string (* eieio-print-depth 2) ? ))
2823 (princ (symbol-name i))
2824 (princ " ")
2825 (if (car publp)
2826 ;; Use our public printer
2827 (funcall (car publp) v)
2828 ;; Use our generic override prin1 function.
2829 (eieio-override-prin1 v))
2830 (princ "\n"))))
2831 (setq publa (cdr publa) publd (cdr publd)
2832 publp (cdr publp)))
2833 (princ (make-string (* eieio-print-depth 2) ? )))
2834 (princ ")\n")))
2836 (defun eieio-override-prin1 (thing)
2837 "Perform a `prin1' on THING taking advantage of object knowledge."
2838 (cond ((eieio-object-p thing)
2839 (object-write thing))
2840 ((listp thing)
2841 (eieio-list-prin1 thing))
2842 ((class-p thing)
2843 (princ (class-name thing)))
2844 ((symbolp thing)
2845 (princ (concat "'" (symbol-name thing))))
2846 (t (prin1 thing))))
2848 (defun eieio-list-prin1 (list)
2849 "Display LIST where list may contain objects."
2850 (if (not (eieio-object-p (car list)))
2851 (progn
2852 (princ "'")
2853 (prin1 list))
2854 (princ "(list ")
2855 (if (eieio-object-p (car list)) (princ "\n "))
2856 (while list
2857 (if (eieio-object-p (car list))
2858 (object-write (car list))
2859 (princ "'")
2860 (prin1 (car list)))
2861 (princ " ")
2862 (setq list (cdr list)))
2863 (princ (make-string (* eieio-print-depth 2) ? ))
2864 (princ ")")))
2867 ;;; Unimplemented functions from CLOS
2869 (defun change-class (obj class)
2870 "Change the class of OBJ to type CLASS.
2871 This may create or delete slots, but does not affect the return value
2872 of `eq'."
2873 (error "EIEIO: `change-class' is unimplemented"))
2878 ;;; Interfacing with edebug
2880 (defun eieio-edebug-prin1-to-string (object &optional noescape)
2881 "Display EIEIO OBJECT in fancy format.
2882 Overrides the edebug default.
2883 Optional argument NOESCAPE is passed to `prin1-to-string' when appropriate."
2884 (cond ((class-p object) (class-name object))
2885 ((eieio-object-p object) (object-print object))
2886 ((and (listp object) (or (class-p (car object))
2887 (eieio-object-p (car object))))
2888 (concat "(" (mapconcat 'eieio-edebug-prin1-to-string object " ") ")"))
2889 (t (prin1-to-string object noescape))))
2891 (add-hook 'edebug-setup-hook
2892 (lambda ()
2893 (def-edebug-spec defmethod
2894 (&define ; this means we are defining something
2895 [&or name ("setf" :name setf name)]
2896 ;; ^^ This is the methods symbol
2897 [ &optional symbolp ] ; this is key :before etc
2898 list ; arguments
2899 [ &optional stringp ] ; documentation string
2900 def-body ; part to be debugged
2902 ;; The rest of the macros
2903 (def-edebug-spec oref (form quote))
2904 (def-edebug-spec oref-default (form quote))
2905 (def-edebug-spec oset (form quote form))
2906 (def-edebug-spec oset-default (form quote form))
2907 (def-edebug-spec class-v form)
2908 (def-edebug-spec class-p form)
2909 (def-edebug-spec eieio-object-p form)
2910 (def-edebug-spec class-constructor form)
2911 (def-edebug-spec generic-p form)
2912 (def-edebug-spec with-slots (list list def-body))
2913 ;; I suspect this isn't the best way to do this, but when
2914 ;; cust-print was used on my system all my objects
2915 ;; appeared as "#1 =" which was not useful. This allows
2916 ;; edebug to print my objects in the nice way they were
2917 ;; meant to with `object-print' and `class-name'
2918 ;; (defalias 'edebug-prin1-to-string 'eieio-edebug-prin1-to-string)
2922 ;;; Interfacing with imenu in emacs lisp mode
2923 ;; (Only if the expression is defined)
2925 (if (eval-when-compile (boundp 'list-imenu-generic-expression))
2926 (progn
2928 (defun eieio-update-lisp-imenu-expression ()
2929 "Examine `lisp-imenu-generic-expression' and modify it to find `defmethod'."
2930 (let ((exp lisp-imenu-generic-expression))
2931 (while exp
2932 ;; it's of the form '( ( title expr indx ) ... )
2933 (let* ((subcar (cdr (car exp)))
2934 (substr (car subcar)))
2935 (if (and (not (string-match "|method\\\\" substr))
2936 (string-match "|advice\\\\" substr))
2937 (setcar subcar
2938 (replace-match "|advice\\|method\\" t t substr 0))))
2939 (setq exp (cdr exp)))))
2941 (eieio-update-lisp-imenu-expression)
2945 ;;; Autoloading some external symbols, and hooking into the help system
2948 (autoload 'eieio-help-mode-augmentation-maybee "eieio-opt" "For buffers thrown into help mode, augment for EIEIO.")
2949 (autoload 'eieio-browse "eieio-opt" "Create an object browser window." t)
2950 (autoload 'eieio-describe-class "eieio-opt" "Describe CLASS defined by a string or symbol" t)
2951 (autoload 'eieio-describe-constructor "eieio-opt" "Describe the constructor function FCN." t)
2952 (autoload 'describe-class "eieio-opt" "Describe CLASS defined by a string or symbol." t)
2953 (autoload 'eieio-describe-generic "eieio-opt" "Describe GENERIC defined by a string or symbol." t)
2954 (autoload 'describe-generic "eieio-opt" "Describe GENERIC defined by a string or symbol." t)
2956 (autoload 'customize-object "eieio-custom" "Create a custom buffer editing OBJ.")
2958 (provide 'eieio)
2960 ;; arch-tag: c1aeab9c-2938-41a3-842b-1a38bd26e9f2
2961 ;;; eieio ends here