1
0
forked from alex-eg/sex

declare a record's typedef ahead of its struct

It came after, so a record pointing at itself, (next (* node)), named a
type C had not been told of yet.
This commit is contained in:
2026-10-16 13:55:22 +03:00
parent 0852079827
commit 0cb3956e02
2 changed files with 23 additions and 8 deletions

View File

@@ -1895,13 +1895,19 @@
(unless (symbol? name)
(sex-error form "record needs a name" form))
(add-typedef name `(typedef ,name (struct ,name)))
(cons (copy-form-source! form `(typedef (struct ,name) ,name))
(process-struct
(copy-form-source! form
(if (eq? (car form) 'pub)
`(pub struct ,@(cdr core))
`(struct ,@(cdr core))))
acc))))
;; the typedef first, so a field may point back at the record, and
;; the docstring ahead of both
(let-values (((doc struct)
(extract-aggregate-docstring
(copy-form-source! form
(if (eq? (car form) 'pub)
`(pub struct ,@(cdr core))
`(struct ,@(cdr core)))))))
(process-struct
struct
(with-docstring doc
(copy-form-source! form `(typedef (struct ,name) ,name))
acc)))))
(define (register-aggregate! form)
(let* ((f (if (eq? (car form) 'pub) (cdr form) form))