- ;; Generate vtmsgs structure for all superclasses.
- (hook-output (car (sod-class-vtables class))
- 'vtmsgs
- sequencer))
-
-(defmethod hook-output progn ((class sod-class) reason sequencer)
- (with-slots (ilayout vtables methods effective-methods) class
- (hook-output ilayout reason sequencer)
- (dolist (method methods) (hook-output method reason sequencer))
- (dolist (method effective-methods)
- (hook-output method reason sequencer))
- (dolist (vtable vtables) (hook-output vtable reason sequencer))))
+ ;; Provide convenience macros for sending the newly defined messages. (The
+ ;; macros work on all subclasses too.)
+ ;;
+ ;; We need each message's method entry type for this, so we need to dig it
+ ;; out of the vtmsgs structure. Indeed, the vtmsgs for this class contains
+ ;; entries for precisely the messages we want to make macros for.
+ (when (some (lambda (message)
+ (or (keyword-message-p message)
+ (varargs-message-p message)))
+ (sod-class-messages class))
+ (one-off-output 'varargs-macros sequencer :early-decls
+ (lambda (stream)
+ (format stream
+ "~%SOD__VARARGS_MACROS_PREAMBLE~%"))))
+ (when (sod-class-messages class)
+ (sequence-output (stream sequencer)
+ ((class :message-macros)
+ (let* ((vtable (find (sod-class-chain-head class)
+ (sod-class-vtables class)
+ :key #'vtable-chain-head))
+ (vtmsgs (find-if (lambda (item)
+ (and (typep item 'vtmsgs)
+ (eql (vtmsgs-class item) class)))
+ (vtable-body vtable))))
+ (format stream "/* Message invocation macros. */~%")
+ (dolist (entry (vtmsgs-entries vtmsgs))
+ (let* ((type (method-entry-function-type entry))
+ (args (c-function-arguments type))
+ (in-names nil) (out-names nil) (varargsp nil) (me "me"))
+ (do ((args args (cdr args)))
+ ((endp args))
+ (let* ((raw-name (princ-to-string (argument-name (car args))))
+ (name (if (find raw-name
+ (list "_vt"
+ (sod-class-nickname class)
+ (method-entry-slot-name entry))
+ :test #'string=)
+ (format nil "sod__a_~A" raw-name)
+ raw-name)))
+ (cond ((and (cdr args) (eq (cadr args) :ellipsis))
+ (setf varargsp t)
+ (unless in-names (setf me "SOD__CAR(__VA_ARGS__)"))
+ (push (format nil "/*~A*/ ..." name) in-names)
+ (push "__VA_ARGS__" out-names)
+ (return))
+ (t
+ (push name in-names)
+ (push name out-names)))))
+ (when varargsp
+ (format stream "#ifdef SOD__HAVE_VARARGS_MACROS~%"))
+ (format stream "#define ~A(~{~A~^, ~}) ~
+ (~A)->_vt->~A.~A(~{~A~^, ~})~%"
+ (message-macro-name class entry)
+ (nreverse in-names)
+ me
+ (sod-class-nickname class)
+ (method-entry-slot-name entry)
+ (nreverse out-names))
+ (when varargsp
+ (format stream "#endif~%"))))
+ (terpri stream))))))
+
+(defmethod hook-output :after ((class sod-class) (reason (eql :h)) sequencer)
+
+ ;; Output a structure member definition for each instance slot.
+ (dolist (slot (sod-class-slots class))
+ (hook-output slot 'islots sequencer))
+
+ ;; Generate a vtmsgs structure for all superclasses.
+ (hook-output (car (sod-class-vtables class)) 'vtmsgs sequencer))