X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/6e6b09589b6f6d0b260fd022e6a3b189f7f7d352..675b48242d0f5c6f2f2563003a1d2fd87e06522c:/src/class-layout-impl.lisp diff --git a/src/class-layout-impl.lisp b/src/class-layout-impl.lisp index 8edfcf6..452e683 100644 --- a/src/class-layout-impl.lisp +++ b/src/class-layout-impl.lisp @@ -7,7 +7,7 @@ ;;;----- 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 @@ -41,16 +41,26 @@ :key #'sod-initializer-slot)) (sod-class-precedence-list class))) +(defmethod find-slot-initargs ((class sod-class) (slot sod-slot)) + (mappend (lambda (super) + (remove-if-not (lambda (initarg) + (and (typep initarg 'sod-slot-initarg) + (eq (sod-initarg-slot initarg) slot))) + (sod-class-initargs super))) + (sod-class-precedence-list class))) + (defmethod compute-effective-slot ((class sod-class) (slot sod-slot)) (make-instance 'effective-slot :slot slot :class class - :initializer (find-slot-initializer class slot))) + :initializer (find-slot-initializer class slot) + :initargs (find-slot-initargs class slot))) ;;;-------------------------------------------------------------------------- ;;; Special-purpose slot objects. -(export 'sod-class-slot) +(export '(sod-class-slot + sod-slot-initializer-function sod-slot-prepare-function)) (defclass sod-class-slot (sod-slot) ((initializer-function :initarg :initializer-function :type (or symbol function) @@ -116,8 +126,8 @@ (sod-class-methods super) :key #'sod-method-message :test-not #'eql)) - (sod-class-precedence-list class)))) - (make-instance (message-effective-method-class message) + (sod-class-precedence-list class)))) + (make-instance (sod-message-effective-method-class message) :message message :class class :direct-methods direct-methods))) @@ -129,9 +139,6 @@ (sod-class-messages super))) (sod-class-precedence-list class))) -(define-on-demand-slot sod-class effective-methods (class) - (compute-effective-methods class)) - ;;;-------------------------------------------------------------------------- ;;; Instance layout. @@ -204,9 +211,6 @@ (reverse chain))) (sod-class-chains class)))) -(define-on-demand-slot sod-class %ilayout (class) - (compute-ilayout class)) - ;;;-------------------------------------------------------------------------- ;;; Vtable layout. @@ -384,7 +388,22 @@ (compute-vtable class (reverse chain))) (sod-class-chains class))) -(define-on-demand-slot sod-class vtables (class) - (compute-vtables class)) +;;;-------------------------------------------------------------------------- +;;; Layout interface. + +;; Just arrange to populate the necessary slots on demand. +(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) + (compute-effective-methods class)) + (define-layout-slot vtables (class) + (compute-vtables class)))) ;;;----- That's all, folks --------------------------------------------------