src/class-{finalize,layout}-impl.lisp: Error checking on layout slots.
[sod] / src / class-finalize-impl.lisp
index 39ac234..9c34bd7 100644 (file)
        (with-slots (chain-head chain chains) class
         (setf (values chain-head chain chains) (compute-chains class)))
 
-       ;; FIXME: make these slots autovivifying.
-       (with-slots (ilayout effective-methods vtables) class
-        (setf ilayout (compute-ilayout class))
-        (setf effective-methods (compute-effective-methods class))
-        (setf vtables (compute-vtables class)))
-
        ;; Done.
        (setf (sod-class-state class) :finalized)
        t)
       (: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))))
+    (define-layout-slot %ilayout (class)
+      (compute-ilayout class))
+    (define-layout-slot effective-methods (class)
+      (compute-effective-methods class))
+    (define-layout-slot vtables (class)
+      (compute-vtables class))))
+
 ;;;----- That's all, folks --------------------------------------------------