(cl-defstruct (eieio--class
(:constructor nil)
- (:constructor eieio--class-make (name &aux (tag 'defclass)))
- (:type vector)
+ (:constructor eieio--class-make (name))
+ (:include cl--class)
(:copier nil))
- ;; We use an untagged cl-struct, with our own hand-made tag as first field
- ;; (containing the symbol `defclass'). It would be better to use a normal
- ;; cl-struct with its normal tag (e.g. so that cl-defstruct can define the
- ;; predicate for us), but that breaks compatibility with .elc files compiled
- ;; against older versions of EIEIO.
- tag
- ;; Fields we could inherit from cl--class (if we used a tagged cl-struct):
- (name nil :type symbol) ;The type name.
- (docstring nil :type string)
- (parents nil :type (or eieio--class (list-of eieio--class)))
- (slots nil :type (vector cl-slot-descriptor))
- (index-table nil :type hash-table)
- ;; Fields specific to EIEIO classes:
children
initarg-tuples ;; initarg tuples list
(class-slots nil :type eieio--slot)
(or (eieio--class-v class) class)
class))
-(defsubst eieio--class-p (class)
- "Return non-nil if CLASS is a valid class object."
- (condition-case nil
- (eq (aref class 0) 'defclass)
- (error nil)))
-
(defun class-p (class)
"Return non-nil if CLASS is a valid class vector.
CLASS is a symbol." ;FIXME: Is it a vector or a symbol?
(setq eieio-hook nil)
(let* ((oldc (let ((c (eieio--class-v cname))) (if (eieio--class-p c) c)))
- (newc (if (and oldc (not (eieio--class-default-object-cache oldc)))
- ;; The oldc class is a stub setup by eieio-defclass-autoload.
- ;; Reuse it instead of creating a new one, so that existing
- ;; references stay valid.
- oldc
- (eieio--class-make cname)))
+ (newc (or oldc
+ ;; Reuse `oldc' instead of creating a new one, so that
+ ;; existing references stay valid. E.g. when
+ ;; reloading the file that does the `defclass', we don't
+ ;; want to create a new class object.
+ (eieio--class-make cname)))
(groups nil) ;; list of groups id'd from slots
(clearparent nil))
;; method table breakage, particularly when the users is only
;; byte compiling an EIEIO file.
(if oldc
- (setf (eieio--class-children newc) (eieio--class-children oldc))
+ (progn
+ (cl-assert (eq newc oldc))
+ ;; Reset the fields.
+ (setf (eieio--class-parents newc) nil)
+ (setf (eieio--class-slots newc) nil)
+ (setf (eieio--class-initarg-tuples newc) nil)
+ (setf (eieio--class-class-slots newc) nil))
;; If the old class did not exist, but did exist in the autoload map,
;; then adopt those children. This is like the above, but deals with
;; autoloads nicely.
(cl-check-type slot symbol)
(cl-check-type obj (or eieio-object class))
(let* ((class (cond ((symbolp obj)
- (error "eieio-oref called on a class!")
+ (error "eieio-oref called on a class: %s" obj)
(let ((c (eieio--class-v obj)))
(if (eieio--class-p c) (eieio-class-un-autoload obj))
c))