;;;----- Licensing notice ---------------------------------------------------
;;;
-;;; This file is part of the Sensble Object Design, an object system for C.
+;;; This file is part of the Sensible Object Design, an object system for C.
;;;
;;; SOD is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
(gethash super table))
(cdr class-precedence-list)))))))))
+;;;--------------------------------------------------------------------------
+;;; Metaclasses.
+
+(defun maximum (items order what)
+ "Return a maximum item according to the non-strict partial ORDER."
+ (reduce (lambda (best this)
+ (cond ((funcall order best this) best)
+ ((funcall order this best) this)
+ (t (error "Unable to choose best ~A." what))))
+ items))
+
+(defmethod guess-metaclass ((class sod-class))
+ "Default metaclass-guessing function for classes.
+
+ Return the most specific metaclass of any of the CLASS's direct
+ superclasses."
+
+ ;; During bootstrapping, our superclasses might not have their own
+ ;; metaclasses resolved yet. If we find this, then throw `bootstrapping'
+ ;; so that `shared-initialize' on `sod-class' can catch it (or as a shot
+ ;; across the bows of anyone else who calls us).
+ (maximum (mapcar (lambda (super)
+ (if (slot-boundp super 'metaclass)
+ (slot-value super 'metaclass)
+ (throw 'bootstrapping nil)))
+ (sod-class-direct-superclasses class))
+ #'sod-subclass-p
+ (format nil "metaclass for `~A'" class)))
+
;;;--------------------------------------------------------------------------
;;; Sanity checking.
((nil)
;; If this fails, mark the class as a loss.
- (setf (sod-class-state class) :broken)
+ (setf (slot-value class 'state) :broken)
+
+ ;; Set up the metaclass if it's not been set already. This is delayed
+ ;; to give bootstrapping a chance to set up metaclass and superclass
+ ;; circularities.
+ (default-slot (class 'metaclass) (guess-metaclass class))
;; Finalize all of the superclasses. There's some special pleading
;; here to make bootstrapping work: we don't try to finalize the
(finalize-sod-class metaclass)))
;; Stash the class's type.
- (setf (sod-class-type class)
+ (setf (slot-value class '%type)
(make-class-type (sod-class-name class)))
;; Clobber the lists of items if they've not been set.
(setf (values chain-head chain chains) (compute-chains class)))
;; Done.
- (setf (sod-class-state class) :finalized)
+ (setf (slot-value class 'state) :finalized)
t)
(:broken
(:finalized
t))))
-(macrolet ((define-layout-slot (slot (class) &body body)
- `(define-on-demand-slot sod-class ,slot (,class)
- (check-class-is-finalized ,class)
- ,@body)))
- (flet ((check-class-is-finalized (class)
- (unless (eq (sod-class-state class) :finalized)
- (error "Class ~S is not finalized" class))))
+(flet ((check-class-is-finalized (class)
+ (unless (eq (sod-class-state class) :finalized)
+ (error "Class ~S is not finalized" class))))
+ (macrolet ((define-layout-slot (slot (class) &body body)
+ `(define-on-demand-slot sod-class ,slot (,class)
+ (check-class-is-finalized ,class)
+ ,@body)))
(define-layout-slot %ilayout (class)
(compute-ilayout class))
(define-layout-slot effective-methods (class)